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 <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Denton Liu committed
Apr 7, 2020 at 10:28 UTC
d9f15d37f1a545305988f6b2bb40de1fbf0049cf
4 files changed
+42
-23
Documentation/git-pull.txt
-9
@@ -133,15 +133,6 @@ unless you have read linkgit:git-rebase[1] carefully.
133
--no-rebase::
134
Override earlier --rebase.
135
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
-
136
Options related to fetching
137
~~~~~~~~~~~~~~~~~~~~~~~~~~~
138
Documentation/merge-options.txt
+2
-2
@@ -155,6 +155,8 @@ ifndef::git-pull[]
155
Note that not all merge strategies may support progress
156
reporting.
157
158
+endif::git-pull[]
159
+
160
--autostash::
161
--no-autostash::
162
Automatically create a temporary stash entry before the operation
@@ -163,8 +165,6 @@ ifndef::git-pull[]
165
with care: the final stash application after a successful
166
merge might result in non-trivial conflicts.
167
166
-endif::git-pull[]
167
-
168
--allow-unrelated-histories::
169
By default, `git merge` command refuses to merge histories
170
that do not share a common ancestor. This option can be
builtin/pull.c
+5
-4
@@ -163,7 +163,7 @@ static struct option pull_options[] = {
163
N_("verify that the named commit has a valid GPG signature"),
164
PARSE_OPT_NOARG),
165
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")),
167
OPT_PASSTHRU_ARGV('s', "strategy", &opt_strategies, N_("strategy"),
168
N_("merge strategy to use"),
169
0),
@@ -661,6 +661,10 @@ static int run_merge(void)
661
argv_array_pushv(&args, opt_strategy_opts.argv);
662
if (opt_gpg_sign)
663
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");
668
if (opt_allow_unrelated_histories > 0)
669
argv_array_push(&args, "--allow-unrelated-histories");
670
@@ -908,9 +912,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
912
if (get_oid("HEAD", &orig_head))
913
oidclr(&orig_head);
914
911
- if (!opt_rebase && opt_autostash != -1)
912
- die(_("--[no-]autostash option is only valid with --rebase."));
913
-
915
autostash = config_autostash;
916
if (opt_rebase) {
917
if (opt_autostash != -1)
t/t5520-pull.sh
+35
-8
@@ -28,7 +28,7 @@ test_pull_autostash_fail () {
28
echo dirty >new_file &&
29
git add new_file &&
30
test_must_fail git pull "$@" . copy 2>err &&
31
- test_i18ngrep "uncommitted changes." err
31
+ test_i18ngrep "\(uncommitted changes.\)\|\(overwritten by merge:\)" err
32
}
33
34
test_expect_success setup '
@@ -404,13 +404,40 @@ test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
404
test_pull_autostash_fail --rebase --no-autostash
405
'
406
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
+'
441
442
test_expect_success 'pull.rebase' '
443
git reset --hard before-rebase &&