From 226da94bdeb7c80ca7ecc889dc62a3fef9fd4e95 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 18 Sep 2007 01:38:42 +0200 Subject: [PATCH] Support cherry-picking commits in main view to current branch Bound to 'C' by default. Idea by krh on #git. --- tig.1.txt | 4 ++++ tig.c | 33 +++++++++++++++++++++++++++++---- tigrc.5.txt | 1 + 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tig.1.txt b/tig.1.txt index 13d4059..efc937b 100644 --- a/tig.1.txt +++ b/tig.1.txt @@ -82,6 +82,10 @@ TIG_LS_REMOTE:: Set command for retrieving all repository references. The command should output data in the same format as git-ls-remote(1). +TIG_CHERRY_PICK:: + Set command for cherry-picking a commit. The command should expect + a commit SHA as its final argument. + TIG_DIFF_CMD:: The command used for the diff view. By default, git show is used as a backend. diff --git a/tig.c b/tig.c index 05ec10c..246812f 100644 --- a/tig.c +++ b/tig.c @@ -351,7 +351,8 @@ sq_quote(char buf[SIZEOF_STR], size_t bufsize, const char *src) REQ_(TOGGLE_LINENO, "Toggle line numbers"), \ REQ_(TOGGLE_REV_GRAPH, "Toggle revision graph visualization"), \ REQ_(STATUS_UPDATE, "Update file status"), \ - REQ_(EDIT, "Open in editor") + REQ_(EDIT, "Open in editor"), \ + REQ_(CHERRY_PICK, "Cherry-pick commit to current branch") /* User action requests. */ @@ -784,6 +785,7 @@ static struct keybinding default_keybindings[] = { { ':', REQ_PROMPT }, { 'u', REQ_STATUS_UPDATE }, { 'e', REQ_EDIT }, + { 'C', REQ_CHERRY_PICK }, /* Using the ncurses SIGWINCH handler. */ { KEY_RESIZE, REQ_SCREEN_RESIZE }, @@ -2326,13 +2328,14 @@ view_driver(struct view *view, enum request request) report("Nothing to edit"); break; + case REQ_CHERRY_PICK: + report("Nothing to cherry-pick"); + break; + case REQ_ENTER: report("Nothing to enter"); break; - case REQ_NONE: - doupdate(); - return TRUE; case REQ_VIEW_CLOSE: /* XXX: Mark closed views by letting view->parent point to the @@ -3986,6 +3989,26 @@ main_read(struct view *view, char *line) return TRUE; } +static void +cherry_pick_commit(struct commit *commit) +{ + char cmd[SIZEOF_STR]; + char *cherry_pick = getenv("TIG_CHERRY_PICK"); + + if (!cherry_pick) + cherry_pick = "git cherry-pick"; + + if (string_format(cmd, "%s %s", cherry_pick, commit->id)) { + def_prog_mode(); /* save current tty modes */ + endwin(); /* restore original tty modes */ + system(cmd); + fprintf(stderr, "Press Enter to continue"); + getc(stdin); + reset_prog_mode(); + redraw_display(); + } +} + static enum request main_request(struct view *view, enum request request, struct line *line) { @@ -3993,6 +4016,8 @@ main_request(struct view *view, enum request request, struct line *line) if (request == REQ_ENTER) open_view(view, REQ_VIEW_DIFF, flags); + else if (request == REQ_CHERRY_PICK) + cherry_pick_commit(line->data); else return request; diff --git a/tigrc.5.txt b/tigrc.5.txt index 9d3ad69..540de87 100644 --- a/tigrc.5.txt +++ b/tigrc.5.txt @@ -233,6 +233,7 @@ toggle-lineno Toggle line numbers toggle-rev-graph Toggle revision graph visualization status-update Update file status edit Open in editor +cherry-pick Cherry-pick commit to current branch ------------------------------------------------------------------------------ -- 2.30.2