]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pull: pass --autostash to merge
authorDenton Liu <liu.denton@gmail.com>
Tue, 7 Apr 2020 14:28:09 +0000 (10:28 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Apr 2020 16:28:02 +0000 (09:28 -0700)
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>
Documentation/git-pull.txt
Documentation/merge-options.txt
builtin/pull.c
t/t5520-pull.sh

index dfb901f8b8358ea309e6403079e3c87fb82fee6f..ba3772de9f6e6d1ec8a5c8be201e77f1c2dfb3fd 100644 (file)
@@ -133,15 +133,6 @@ unless you have read linkgit:git-rebase[1] carefully.
 --no-rebase::
        Override earlier --rebase.
 
---autostash::
---no-autostash::
-       Before starting rebase, stash local modifications away (see
-       linkgit:git-stash[1]) if needed, and apply the stash entry when
-       done. `--no-autostash` is useful to override the `rebase.autoStash`
-       configuration variable (see linkgit:git-config[1]).
-+
-This option is only valid when "--rebase" is used.
-
 Options related to fetching
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
index 3985e6d4a9e112e1f798889fef8fdff1ad5847a8..48bfcda084dc9c2fea601b1f59ac4d2d5060dc4a 100644 (file)
@@ -155,6 +155,8 @@ ifndef::git-pull[]
        Note that not all merge strategies may support progress
        reporting.
 
+endif::git-pull[]
+
 --autostash::
 --no-autostash::
        Automatically create a temporary stash entry before the operation
@@ -163,8 +165,6 @@ ifndef::git-pull[]
        with care: the final stash application after a successful
        merge might result in non-trivial conflicts.
 
-endif::git-pull[]
-
 --allow-unrelated-histories::
        By default, `git merge` command refuses to merge histories
        that do not share a common ancestor.  This option can be
index 3e624d1e008588ed063a7a960026287d34b84965..9beb4841d10502e0d47ce61d989a136d8fb6be9c 100644 (file)
@@ -163,7 +163,7 @@ static struct option pull_options[] = {
                N_("verify that the named commit has a valid GPG signature"),
                PARSE_OPT_NOARG),
        OPT_BOOL(0, "autostash", &opt_autostash,
-               N_("automatically stash/stash pop before and after rebase")),
+               N_("automatically stash/stash pop before and after")),
        OPT_PASSTHRU_ARGV('s', "strategy", &opt_strategies, N_("strategy"),
                N_("merge strategy to use"),
                0),
@@ -661,6 +661,10 @@ static int run_merge(void)
        argv_array_pushv(&args, opt_strategy_opts.argv);
        if (opt_gpg_sign)
                argv_array_push(&args, opt_gpg_sign);
+       if (opt_autostash == 0)
+               argv_array_push(&args, "--no-autostash");
+       else if (opt_autostash == 1)
+               argv_array_push(&args, "--autostash");
        if (opt_allow_unrelated_histories > 0)
                argv_array_push(&args, "--allow-unrelated-histories");
 
@@ -908,9 +912,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        if (get_oid("HEAD", &orig_head))
                oidclr(&orig_head);
 
-       if (!opt_rebase && opt_autostash != -1)
-               die(_("--[no-]autostash option is only valid with --rebase."));
-
        autostash = config_autostash;
        if (opt_rebase) {
                if (opt_autostash != -1)
index f610dc14ded8e0085600b10cf90ef2fd53a5d949..37535d63a9cc0c8d611747bd3235995d0b98a115 100755 (executable)
@@ -28,7 +28,7 @@ test_pull_autostash_fail () {
        echo dirty >new_file &&
        git add new_file &&
        test_must_fail git pull "$@" . copy 2>err &&
-       test_i18ngrep "uncommitted changes." err
+       test_i18ngrep "\(uncommitted changes.\)\|\(overwritten by merge:\)" err
 }
 
 test_expect_success setup '
@@ -404,13 +404,40 @@ test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
        test_pull_autostash_fail --rebase --no-autostash
 '
 
-for i in --autostash --no-autostash
-do
-       test_expect_success "pull $i (without --rebase) is illegal" '
-               test_must_fail git pull $i . copy 2>err &&
-               test_i18ngrep "only valid with --rebase" err
-       '
-done
+test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' '
+       test_config merge.autostash true &&
+       test_pull_autostash 2
+'
+
+test_expect_success 'pull --autostash & merge.autostash=true' '
+       test_config merge.autostash true &&
+       test_pull_autostash 2 --autostash
+'
+
+test_expect_success 'pull --autostash & merge.autostash=false' '
+       test_config merge.autostash false &&
+       test_pull_autostash 2 --autostash
+'
+
+test_expect_success 'pull --autostash & merge.autostash unset' '
+       test_unconfig merge.autostash &&
+       test_pull_autostash 2 --autostash
+'
+
+test_expect_success 'pull --no-autostash & merge.autostash=true' '
+       test_config merge.autostash true &&
+       test_pull_autostash_fail --no-autostash
+'
+
+test_expect_success 'pull --no-autostash & merge.autostash=false' '
+       test_config merge.autostash false &&
+       test_pull_autostash_fail --no-autostash
+'
+
+test_expect_success 'pull --no-autostash & merge.autostash unset' '
+       test_unconfig merge.autostash &&
+       test_pull_autostash_fail --no-autostash
+'
 
 test_expect_success 'pull.rebase' '
        git reset --hard before-rebase &&