Skip to content

Commit d0146bd

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 1629d56 commit d0146bd

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
rebase 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
@@ -183,7 +183,7 @@ static struct option pull_options[] = {
183183
N_("verify that the named commit has a valid GPG signature"),
184184
PARSE_OPT_NOARG),
185185
OPT_BOOL(0, "autostash", &opt_autostash,
186-
N_("automatically stash/stash pop before and after rebase")),
186+
N_("automatically stash/stash pop before and after")),
187187
OPT_PASSTHRU_ARGV('s', "strategy", &opt_strategies, N_("strategy"),
188188
N_("merge strategy to use"),
189189
0),
@@ -671,6 +671,10 @@ static int run_merge(void)
671671
argv_array_pushv(&args, opt_strategy_opts.argv);
672672
if (opt_gpg_sign)
673673
argv_array_push(&args, opt_gpg_sign);
674+
if (opt_autostash == 0)
675+
argv_array_push(&args, "--no-autostash");
676+
else if (opt_autostash == 1)
677+
argv_array_push(&args, "--autostash");
674678
if (opt_allow_unrelated_histories > 0)
675679
argv_array_push(&args, "--allow-unrelated-histories");
676680

@@ -918,9 +922,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
918922
if (get_oid("HEAD", &orig_head))
919923
oidclr(&orig_head);
920924

921-
if (!opt_rebase && opt_autostash != -1)
922-
die(_("--[no-]autostash option is only valid with --rebase."));
923-
924925
autostash = config_autostash;
925926
if (opt_rebase) {
926927
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 '
@@ -391,13 +391,40 @@ test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
391391
test_pull_autostash_fail --rebase --no-autostash
392392
'
393393

394-
for i in --autostash --no-autostash
395-
do
396-
test_expect_success "pull $i (without --rebase) is illegal" '
397-
test_must_fail git pull $i . copy 2>err &&
398-
test_i18ngrep "only valid with --rebase" err
399-
'
400-
done
394+
test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' '
395+
test_config merge.autostash true &&
396+
test_pull_autostash 2
397+
'
398+
399+
test_expect_success 'pull --autostash & merge.autostash=true' '
400+
test_config merge.autostash true &&
401+
test_pull_autostash 2 --autostash
402+
'
403+
404+
test_expect_success 'pull --autostash & merge.autostash=false' '
405+
test_config merge.autostash false &&
406+
test_pull_autostash 2 --autostash
407+
'
408+
409+
test_expect_success 'pull --autostash & merge.autostash unset' '
410+
test_unconfig merge.autostash &&
411+
test_pull_autostash 2 --autostash
412+
'
413+
414+
test_expect_success 'pull --no-autostash & merge.autostash=true' '
415+
test_config merge.autostash true &&
416+
test_pull_autostash_fail --no-autostash
417+
'
418+
419+
test_expect_success 'pull --no-autostash & merge.autostash=false' '
420+
test_config merge.autostash false &&
421+
test_pull_autostash_fail --no-autostash
422+
'
423+
424+
test_expect_success 'pull --no-autostash & merge.autostash unset' '
425+
test_unconfig merge.autostash &&
426+
test_pull_autostash_fail --no-autostash
427+
'
401428

402429
test_expect_success 'pull.rebase' '
403430
git reset --hard before-rebase &&

0 commit comments

Comments
 (0)