git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: John Cai <johncai86@gmail.com>
To: git@vger.kernel.org
Cc: John Cai <johncai86@gmail.com>,
	"Tilman Vogel" <tilman.vogel@web.de>,
	"Philippe Blain" <levraiphilippeblain@gmail.com>
Subject: [PATCH 1/1] builtin/pull.c: use config value of autostash
Date: Tue,  4 Jan 2022 16:45:22 -0500	[thread overview]
Message-ID: <20220104214522.10692-2-johncai86@gmail.com> (raw)
In-Reply-To: <20220104214522.10692-1-johncai86@gmail.com>

A bug in pull.c causes merge and rebase functions to ignore
rebase.autostash if it is only set in the config.

There are a couple of different scenarios that we need to be mindful of:
1. --autostash passed in through command line
$ git pull --autostash
merge/rebase should get --autostashed passed through

2. --rebase passed in, rebase.autostash set in config
$ git config rebase.autostash true
$ git pull --rebase

merge/rebase should get --autostash from config

3. --no-autostash passed in
$ git pull --no-autostash
--no-autostash should be passed into merge/rebase

4. rebase.autostash set but --rebase not used

$ git config rebase.autostash true
$ git pull
--autostash should not be passed into merge but not rebase

This change adjusts variable names to make it more clear which autostash
setting it is modifying, and ensures --autostash is passed into the
merge/rebase where appropriate.

Reported-by: "Tilman Vogel" <tilman.vogel@web.de>
Co-authored-by: "Philippe Blain" <levraiphilippeblain@gmail.com>
Signed-Off-by: "John Cai" <johncai86@gmail.com>
---
 builtin/pull.c          | 15 ++++++------
 t/t5521-pull-options.sh | 51 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/builtin/pull.c b/builtin/pull.c
index 100cbf9fb8..fb700c2d39 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -86,7 +86,8 @@ static char *opt_ff;
 static char *opt_verify_signatures;
 static char *opt_verify;
 static int opt_autostash = -1;
-static int config_autostash;
+static int rebase_autostash = 0;
+static int cfg_rebase_autostash;
 static int check_trust_level = 1;
 static struct strvec opt_strategies = STRVEC_INIT;
 static struct strvec opt_strategy_opts = STRVEC_INIT;
@@ -361,7 +362,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
 	int status;
 
 	if (!strcmp(var, "rebase.autostash")) {
-		config_autostash = git_config_bool(var, value);
+		cfg_rebase_autostash = git_config_bool(var, value);
 		return 0;
 	} else if (!strcmp(var, "submodule.recurse")) {
 		recurse_submodules = git_config_bool(var, value) ?
@@ -689,7 +690,7 @@ static int run_merge(void)
 		strvec_push(&args, opt_gpg_sign);
 	if (opt_autostash == 0)
 		strvec_push(&args, "--no-autostash");
-	else if (opt_autostash == 1)
+	else if (rebase_autostash == 1 || opt_autostash == 1)
 		strvec_push(&args, "--autostash");
 	if (opt_allow_unrelated_histories > 0)
 		strvec_push(&args, "--allow-unrelated-histories");
@@ -901,7 +902,7 @@ static int run_rebase(const struct object_id *newbase,
 		strvec_push(&args, opt_signoff);
 	if (opt_autostash == 0)
 		strvec_push(&args, "--no-autostash");
-	else if (opt_autostash == 1)
+	else if (rebase_autostash == 1)
 		strvec_push(&args, "--autostash");
 	if (opt_verify_signatures &&
 	    !strcmp(opt_verify_signatures, "--verify-signatures"))
@@ -1038,14 +1039,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 		oidclr(&orig_head);
 
 	if (opt_rebase) {
-		int autostash = config_autostash;
+		rebase_autostash = cfg_rebase_autostash;
 		if (opt_autostash != -1)
-			autostash = opt_autostash;
+			rebase_autostash = opt_autostash;
 
 		if (is_null_oid(&orig_head) && !is_cache_unborn())
 			die(_("Updating an unborn branch with changes added to the index."));
 
-		if (!autostash)
+		if (!rebase_autostash)
 			require_clean_work_tree(the_repository,
 				N_("pull with rebase"),
 				_("please commit or stash them."), 1, 0);
diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh
index 66cfcb09c5..28f551db8e 100755
--- a/t/t5521-pull-options.sh
+++ b/t/t5521-pull-options.sh
@@ -251,5 +251,56 @@ test_expect_success 'git pull --no-verify --verify passed to merge' '
 	test_commit -C src two &&
 	test_must_fail git -C dst pull --no-ff --no-verify --verify
 '
+test_expect_success 'git pull --rebase --autostash succeeds on ff' '
+	test_when_finished "rm -fr src dst actual" &&
+	git init src &&
+	test_commit -C src "initial" file "content" &&
+	git clone src dst &&
+	test_commit -C src --printf "more_content" file "more content\ncontent\n" &&
+	echo "dirty" >>dst/file &&
+	git -C dst pull --rebase --autostash >actual 2>&1 &&
+	grep -q "Fast-forward" actual &&
+	grep -q "Applied autostash." actual
+'
+
+test_expect_success 'git pull --rebase with rebase.autostash succeeds on ff' '
+	test_when_finished "rm -fr src dst actual" &&
+	git init src &&
+	test_commit -C src "initial" file "content" &&
+	git clone src dst &&
+	test_commit -C src --printf "more_content" file "more content\ncontent\n" &&
+	echo "dirty" >>dst/file &&
+	test_config -C dst rebase.autostash true &&
+	git -C dst pull --rebase  >actual 2>&1 &&
+	grep -q "Fast-forward" actual &&
+	grep -q "Applied autostash." actual
+'
+
+test_expect_success 'git pull --rebase --autostash succeeds on non-ff' '
+	test_when_finished "rm -fr src dst actual" &&
+	git init src &&
+	test_commit -C src "initial" file "content" &&
+	git clone src dst &&
+	test_commit -C src --printf "src_content" file "src content\ncontent\n" &&
+	test_commit -C dst --append "dst_content" file "dst content" &&
+	echo "dirty" >>dst/file &&
+	git -C dst pull --rebase --autostash >actual 2>&1 &&
+	grep -q "Successfully rebased and updated refs/heads/main." actual &&
+	grep -q "Applied autostash." actual
+'
+
+test_expect_success 'git pull --rebase with rebase.autostash succeeds on non-ff' '
+	test_when_finished "rm -fr src dst actual" &&
+	git init src &&
+	test_commit -C src "initial" file "content" &&
+	git clone src dst &&
+	test_commit -C src --printf "src_content" file "src content\ncontent\n" &&
+	test_commit -C dst --append "dst_content" file "dst content" &&
+	echo "dirty" >>dst/file &&
+	test_config -C dst rebase.autostash true &&
+	git -C dst pull --rebase >actual 2>&1 &&
+	grep -q "Successfully rebased and updated refs/heads/main." actual &&
+	grep -q "Applied autostash." actual
+'
 
 test_done
-- 
2.34.1


  reply	other threads:[~2022-01-04 21:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 21:45 [PATCH 0/1] Fix bug in pull --rebase not recognizing rebase.autostash John Cai
2022-01-04 21:45 ` John Cai [this message]
2022-01-04 22:46   ` [PATCH 1/1] builtin/pull.c: use config value of autostash Junio C Hamano
2022-01-05  3:58     ` Philippe Blain
2022-01-06 19:11       ` Junio C Hamano
2022-01-14  0:00         ` Junio C Hamano
2022-01-14  3:14           ` Philippe Blain
2022-01-14 14:09             ` John Cai
2022-01-14 19:40             ` Junio C Hamano
2022-01-14 23:33               ` Philippe Blain
2022-01-05 11:21     ` Phillip Wood
2022-01-05  3:40   ` Philippe Blain
2022-01-05  4:02     ` Philippe Blain
2022-01-05 15:50   ` Johannes Schindelin
2022-01-04 23:32 ` [PATCH 0/1] Fix bug in pull --rebase not recognizing rebase.autostash Philippe Blain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220104214522.10692-2-johncai86@gmail.com \
    --to=johncai86@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=levraiphilippeblain@gmail.com \
    --cc=tilman.vogel@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).