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.<name>.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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 13, 2016 at 13:17 UTC f5eb87b98dd6aa587683057b9f5bd063e682e145
4 files changed +24 -3
Documentation/config.txt
+4
@@ -870,6 +870,8 @@ When preserve, also pass `--preserve-merges` along to 'git rebase'
870 so that locally committed merge commits will not be flattened
871 by running 'git pull'.
872 +
873 +When the value is `interactive`, the rebase is run in interactive mode.
874 ++
875 *NOTE*: this is a possibly dangerous operation; do *not* use
876 it unless you understand the implications (see linkgit:git-rebase[1]
877 for details).
@@ -2149,6 +2151,8 @@ When preserve, also pass `--preserve-merges` along to 'git rebase'
2151 so that locally committed merge commits will not be flattened
2152 by running 'git pull'.
2153 +
2154 +When the value is `interactive`, the rebase is run in interactive mode.
2155 ++
2156 *NOTE*: this is a possibly dangerous operation; do *not* use
2157 it unless you understand the implications (see linkgit:git-rebase[1]
2158 for details).
Documentation/git-pull.txt
+3 -1
@@ -101,7 +101,7 @@ Options related to merging
101 include::merge-options.txt[]
102
103 -r::
104 ---rebase[=false|true|preserve]::
104 +--rebase[=false|true|preserve|interactive]::
105 When true, rebase the current branch on top of the upstream
106 branch after fetching. If there is a remote-tracking branch
107 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.
113 +
114 When false, merge the current branch into the upstream branch.
115 +
116 +When `interactive`, enable the interactive mode of rebase.
117 ++
118 See `pull.rebase`, `branch.<name>.rebase` and `branch.autoSetupRebase` in
119 linkgit:git-config[1] if you want to make `git pull` always use
120 `--rebase` instead of merging.
builtin/pull.c
+7 -2
@@ -22,7 +22,8 @@ enum rebase_type {
22 REBASE_INVALID = -1,
23 REBASE_FALSE = 0,
24 REBASE_TRUE,
25 - REBASE_PRESERVE
25 + REBASE_PRESERVE,
26 + REBASE_INTERACTIVE
27 };
28
29 /**
@@ -42,6 +43,8 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,
43 return REBASE_TRUE;
44 else if (!strcmp(value, "preserve"))
45 return REBASE_PRESERVE;
46 + else if (!strcmp(value, "interactive"))
47 + return REBASE_INTERACTIVE;
48
49 if (fatal)
50 die(_("Invalid value for %s: %s"), key, value);
@@ -112,7 +115,7 @@ static struct option pull_options[] = {
115 /* Options passed to git-merge or git-rebase */
116 OPT_GROUP(N_("Options related to merging")),
117 { OPTION_CALLBACK, 'r', "rebase", &opt_rebase,
115 - "false|true|preserve",
118 + "false|true|preserve|interactive",
119 N_("incorporate changes by rebasing rather than merging"),
120 PARSE_OPT_OPTARG, parse_opt_rebase },
121 OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL,
@@ -772,6 +775,8 @@ static int run_rebase(const unsigned char *curr_head,
775 /* Options passed to git-rebase */
776 if (opt_rebase == REBASE_PRESERVE)
777 argv_array_push(&args, "--preserve-merges");
778 + else if (opt_rebase == REBASE_INTERACTIVE)
779 + argv_array_push(&args, "--interactive");
780 if (opt_diffstat)
781 argv_array_push(&args, opt_diffstat);
782 argv_array_pushv(&args, opt_strategies.argv);
t/t5520-pull.sh
+10
@@ -326,6 +326,16 @@ test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
326 test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
327 '
328
329 +test_expect_success 'pull.rebase=interactive' '
330 + write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
331 + echo I was here >fake.out &&
332 + false
333 + EOF
334 + test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
335 + test_must_fail git pull --rebase=interactive . copy &&
336 + test "I was here" = "$(cat fake.out)"
337 +'
338 +
339 test_expect_success 'pull.rebase=invalid fails' '
340 git reset --hard before-preserve-rebase &&
341 test_config pull.rebase invalid &&