Skip to content

Commit f5eb87b

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7548842 commit f5eb87b

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ When preserve, also pass `--preserve-merges` along to 'git rebase'
870870
so that locally committed merge commits will not be flattened
871871
by running 'git pull'.
872872
+
873+
When the value is `interactive`, the rebase is run in interactive mode.
874+
+
873875
*NOTE*: this is a possibly dangerous operation; do *not* use
874876
it unless you understand the implications (see linkgit:git-rebase[1]
875877
for details).
@@ -2149,6 +2151,8 @@ When preserve, also pass `--preserve-merges` along to 'git rebase'
21492151
so that locally committed merge commits will not be flattened
21502152
by running 'git pull'.
21512153
+
2154+
When the value is `interactive`, the rebase is run in interactive mode.
2155+
+
21522156
*NOTE*: this is a possibly dangerous operation; do *not* use
21532157
it unless you understand the implications (see linkgit:git-rebase[1]
21542158
for details).

Documentation/git-pull.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Options related to merging
101101
include::merge-options.txt[]
102102

103103
-r::
104-
--rebase[=false|true|preserve]::
104+
--rebase[=false|true|preserve|interactive]::
105105
When true, rebase the current branch on top of the upstream
106106
branch after fetching. If there is a remote-tracking branch
107107
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.
113113
+
114114
When false, merge the current branch into the upstream branch.
115115
+
116+
When `interactive`, enable the interactive mode of rebase.
117+
+
116118
See `pull.rebase`, `branch.<name>.rebase` and `branch.autoSetupRebase` in
117119
linkgit:git-config[1] if you want to make `git pull` always use
118120
`--rebase` instead of merging.

builtin/pull.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ enum rebase_type {
2222
REBASE_INVALID = -1,
2323
REBASE_FALSE = 0,
2424
REBASE_TRUE,
25-
REBASE_PRESERVE
25+
REBASE_PRESERVE,
26+
REBASE_INTERACTIVE
2627
};
2728

2829
/**
@@ -42,6 +43,8 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,
4243
return REBASE_TRUE;
4344
else if (!strcmp(value, "preserve"))
4445
return REBASE_PRESERVE;
46+
else if (!strcmp(value, "interactive"))
47+
return REBASE_INTERACTIVE;
4548

4649
if (fatal)
4750
die(_("Invalid value for %s: %s"), key, value);
@@ -112,7 +115,7 @@ static struct option pull_options[] = {
112115
/* Options passed to git-merge or git-rebase */
113116
OPT_GROUP(N_("Options related to merging")),
114117
{ OPTION_CALLBACK, 'r', "rebase", &opt_rebase,
115-
"false|true|preserve",
118+
"false|true|preserve|interactive",
116119
N_("incorporate changes by rebasing rather than merging"),
117120
PARSE_OPT_OPTARG, parse_opt_rebase },
118121
OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL,
@@ -772,6 +775,8 @@ static int run_rebase(const unsigned char *curr_head,
772775
/* Options passed to git-rebase */
773776
if (opt_rebase == REBASE_PRESERVE)
774777
argv_array_push(&args, "--preserve-merges");
778+
else if (opt_rebase == REBASE_INTERACTIVE)
779+
argv_array_push(&args, "--interactive");
775780
if (opt_diffstat)
776781
argv_array_push(&args, opt_diffstat);
777782
argv_array_pushv(&args, opt_strategies.argv);

t/t5520-pull.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,16 @@ test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
326326
test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
327327
'
328328

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+
329339
test_expect_success 'pull.rebase=invalid fails' '
330340
git reset --hard before-preserve-rebase &&
331341
test_config pull.rebase invalid &&

0 commit comments

Comments
 (0)