Skip to content

Commit d9f15d3

Browse files
Denton-Lgitster
authored andcommitted
pull: pass --autostash to merge
Before, `--autostash` only worked with `git pull --rebase`. However, in the last patch, merge learned `--autostash` as well so there's no reason why we should have this restriction anymore. Teach pull to pass `--autostash` to merge, just like it did for rebase. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8a1785 commit d9f15d3

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

Documentation/git-pull.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ unless you have read linkgit:git-rebase[1] carefully.
133133
--no-rebase::
134134
Override earlier --rebase.
135135

136-
--autostash::
137-
--no-autostash::
138-
Before starting rebase, stash local modifications away (see
139-
linkgit:git-stash[1]) if needed, and apply the stash entry when
140-
done. `--no-autostash` is useful to override the `rebase.autoStash`
141-
configuration variable (see linkgit:git-config[1]).
142-
+
143-
This option is only valid when "--rebase" is used.
144-
145136
Options related to fetching
146137
~~~~~~~~~~~~~~~~~~~~~~~~~~~
147138

Documentation/merge-options.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ ifndef::git-pull[]
155155
Note that not all merge strategies may support progress
156156
reporting.
157157

158+
endif::git-pull[]
159+
158160
--autostash::
159161
--no-autostash::
160162
Automatically create a temporary stash entry before the operation
@@ -163,8 +165,6 @@ ifndef::git-pull[]
163165
with care: the final stash application after a successful
164166
merge might result in non-trivial conflicts.
165167

166-
endif::git-pull[]
167-
168168
--allow-unrelated-histories::
169169
By default, `git merge` command refuses to merge histories
170170
that do not share a common ancestor. This option can be

builtin/pull.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static struct option pull_options[] = {
163163
N_("verify that the named commit has a valid GPG signature"),
164164
PARSE_OPT_NOARG),
165165
OPT_BOOL(0, "autostash", &opt_autostash,
166-
N_("automatically stash/stash pop before and after rebase")),
166+
N_("automatically stash/stash pop before and after")),
167167
OPT_PASSTHRU_ARGV('s', "strategy", &opt_strategies, N_("strategy"),
168168
N_("merge strategy to use"),
169169
0),
@@ -661,6 +661,10 @@ static int run_merge(void)
661661
argv_array_pushv(&args, opt_strategy_opts.argv);
662662
if (opt_gpg_sign)
663663
argv_array_push(&args, opt_gpg_sign);
664+
if (opt_autostash == 0)
665+
argv_array_push(&args, "--no-autostash");
666+
else if (opt_autostash == 1)
667+
argv_array_push(&args, "--autostash");
664668
if (opt_allow_unrelated_histories > 0)
665669
argv_array_push(&args, "--allow-unrelated-histories");
666670

@@ -908,9 +912,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
908912
if (get_oid("HEAD", &orig_head))
909913
oidclr(&orig_head);
910914

911-
if (!opt_rebase && opt_autostash != -1)
912-
die(_("--[no-]autostash option is only valid with --rebase."));
913-
914915
autostash = config_autostash;
915916
if (opt_rebase) {
916917
if (opt_autostash != -1)

t/t5520-pull.sh

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test_pull_autostash_fail () {
2828
echo dirty >new_file &&
2929
git add new_file &&
3030
test_must_fail git pull "$@" . copy 2>err &&
31-
test_i18ngrep "uncommitted changes." err
31+
test_i18ngrep "\(uncommitted changes.\)\|\(overwritten by merge:\)" err
3232
}
3333

3434
test_expect_success setup '
@@ -404,13 +404,40 @@ test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
404404
test_pull_autostash_fail --rebase --no-autostash
405405
'
406406

407-
for i in --autostash --no-autostash
408-
do
409-
test_expect_success "pull $i (without --rebase) is illegal" '
410-
test_must_fail git pull $i . copy 2>err &&
411-
test_i18ngrep "only valid with --rebase" err
412-
'
413-
done
407+
test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' '
408+
test_config merge.autostash true &&
409+
test_pull_autostash 2
410+
'
411+
412+
test_expect_success 'pull --autostash & merge.autostash=true' '
413+
test_config merge.autostash true &&
414+
test_pull_autostash 2 --autostash
415+
'
416+
417+
test_expect_success 'pull --autostash & merge.autostash=false' '
418+
test_config merge.autostash false &&
419+
test_pull_autostash 2 --autostash
420+
'
421+
422+
test_expect_success 'pull --autostash & merge.autostash unset' '
423+
test_unconfig merge.autostash &&
424+
test_pull_autostash 2 --autostash
425+
'
426+
427+
test_expect_success 'pull --no-autostash & merge.autostash=true' '
428+
test_config merge.autostash true &&
429+
test_pull_autostash_fail --no-autostash
430+
'
431+
432+
test_expect_success 'pull --no-autostash & merge.autostash=false' '
433+
test_config merge.autostash false &&
434+
test_pull_autostash_fail --no-autostash
435+
'
436+
437+
test_expect_success 'pull --no-autostash & merge.autostash unset' '
438+
test_unconfig merge.autostash &&
439+
test_pull_autostash_fail --no-autostash
440+
'
414441

415442
test_expect_success 'pull.rebase' '
416443
git reset --hard before-rebase &&

0 commit comments

Comments
 (0)