From 288511723f91238c0eb36fc68131408012de4137 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 13 Jan 2016 13:17:15 +0100 Subject: [PATCH 1/3] pull: allow interactive rebase with --rebase=interactive A couple of years ago, I found the need to collaborate on topic branches that were rebased all the time, and I really needed to see what I was rebasing when pulling, so I introduced an interactively-rebasing pull. The way builtin pull works, this change also supports the value 'interactive' for the 'branch..rebase' config variable, which is a neat thing because users can now configure given branches for interactively-rebasing pulls without having to type out the complete `--rebase=interactive` option every time they pull. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/config.txt | 4 ++++ Documentation/git-pull.txt | 4 +++- builtin/pull.c | 9 +++++++-- t/t5520-pull.sh | 10 ++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index f61788668e89b6..d04a669f002e90 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -870,6 +870,8 @@ When preserve, also pass `--preserve-merges` along to 'git rebase' so that locally committed merge commits will not be flattened by running 'git pull'. + +When the value is `interactive`, the rebase is run in interactive mode. ++ *NOTE*: this is a possibly dangerous operation; do *not* use it unless you understand the implications (see linkgit:git-rebase[1] for details). @@ -2149,6 +2151,8 @@ When preserve, also pass `--preserve-merges` along to 'git rebase' so that locally committed merge commits will not be flattened by running 'git pull'. + +When the value is `interactive`, the rebase is run in interactive mode. ++ *NOTE*: this is a possibly dangerous operation; do *not* use it unless you understand the implications (see linkgit:git-rebase[1] for details). diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index 93c72a29cecb7c..a62a2a615d0e01 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -101,7 +101,7 @@ Options related to merging include::merge-options.txt[] -r:: ---rebase[=false|true|preserve]:: +--rebase[=false|true|preserve|interactive]:: When true, rebase the current branch on top of the upstream branch after fetching. If there is a remote-tracking branch corresponding to the upstream branch and the upstream branch @@ -113,6 +113,8 @@ to `git rebase` so that locally created merge commits will not be flattened. + When false, merge the current branch into the upstream branch. + +When `interactive`, enable the interactive mode of rebase. ++ See `pull.rebase`, `branch..rebase` and `branch.autoSetupRebase` in linkgit:git-config[1] if you want to make `git pull` always use `--rebase` instead of merging. diff --git a/builtin/pull.c b/builtin/pull.c index 5145fc60a0377a..c7b39b428f7746 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -22,7 +22,8 @@ enum rebase_type { REBASE_INVALID = -1, REBASE_FALSE = 0, REBASE_TRUE, - REBASE_PRESERVE + REBASE_PRESERVE, + REBASE_INTERACTIVE }; /** @@ -42,6 +43,8 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value, return REBASE_TRUE; else if (!strcmp(value, "preserve")) return REBASE_PRESERVE; + else if (!strcmp(value, "interactive")) + return REBASE_INTERACTIVE; if (fatal) die(_("Invalid value for %s: %s"), key, value); @@ -112,7 +115,7 @@ static struct option pull_options[] = { /* Options passed to git-merge or git-rebase */ OPT_GROUP(N_("Options related to merging")), { OPTION_CALLBACK, 'r', "rebase", &opt_rebase, - "false|true|preserve", + "false|true|preserve|interactive", N_("incorporate changes by rebasing rather than merging"), PARSE_OPT_OPTARG, parse_opt_rebase }, OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL, @@ -772,6 +775,8 @@ static int run_rebase(const unsigned char *curr_head, /* Options passed to git-rebase */ if (opt_rebase == REBASE_PRESERVE) argv_array_push(&args, "--preserve-merges"); + else if (opt_rebase == REBASE_INTERACTIVE) + argv_array_push(&args, "--interactive"); if (opt_diffstat) argv_array_push(&args, opt_diffstat); argv_array_pushv(&args, opt_strategies.argv); diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index a0013ee32f1940..c952d5ef5c4e4d 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -326,6 +326,16 @@ test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' ' test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)" ' +test_expect_success 'pull.rebase=interactive' ' + write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF && + echo I was here >fake.out && + false + EOF + test_set_editor "$TRASH_DIRECTORY/fake-editor" && + test_must_fail git pull --rebase=interactive . copy && + test "I was here" = "$(cat fake.out)" +' + test_expect_success 'pull.rebase=invalid fails' ' git reset --hard before-preserve-rebase && test_config pull.rebase invalid && From 6426046514bb3dad01241863f62158299a69c949 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 13 Jan 2016 13:17:19 +0100 Subject: [PATCH 2/3] remote: handle the config setting branch.*.rebase=interactive The config variable branch..rebase is not only used by `git pull`, but also by `git remote` when showing details about a remote. Therefore, it needs to be taught to accept the newly-introduced `interactive` value of said variable. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin/remote.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 6694cf20efdc01..2b2ff9b7d2152c 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -251,7 +251,7 @@ static int add(int argc, const char **argv) struct branch_info { char *remote_name; struct string_list merge; - int rebase; + enum { NO_REBASE, NORMAL_REBASE, INTERACTIVE_REBASE } rebase; }; static struct string_list branch_list; @@ -311,7 +311,9 @@ static int config_read_branches(const char *key, const char *value, void *cb) if (v >= 0) info->rebase = v; else if (!strcmp(value, "preserve")) - info->rebase = 1; + info->rebase = NORMAL_REBASE; + else if (!strcmp(value, "interactive")) + info->rebase = INTERACTIVE_REBASE; } } return 0; @@ -980,7 +982,9 @@ static int show_local_info_item(struct string_list_item *item, void *cb_data) printf(" %-*s ", show_info->width, item->string); if (branch_info->rebase) { - printf_ln(_("rebases onto remote %s"), merge->items[0].string); + printf_ln(_(branch_info->rebase == INTERACTIVE_REBASE ? + "rebases interactively onto remote %s" : + "rebases onto remote %s"), merge->items[0].string); return 0; } else if (show_info->any_rebase) { printf_ln(_(" merges with remote %s"), merge->items[0].string); From 6236729b2aa6df9cc3497059c83b66604e82fdf6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 13 Jan 2016 13:17:22 +0100 Subject: [PATCH 3/3] completion: add missing branch.*.rebase values Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 00d729996fab5b..06474fee13f6cf 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1812,7 +1812,7 @@ _git_config () return ;; branch.*.rebase) - __gitcomp "false true" + __gitcomp "false true preserve interactive" return ;; remote.pushdefault)