git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/1] builtin/pull.c: use config value of autostash

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 4, 2022, 22:46 UTC
Message-ID
<xmqqbl0r9l0l.fsf@gitster.g>
In-Reply-To
<20220104214522.10692-2-johncai86@gmail.com>
John Cai <johncai86@gmail.com> writes:
Show 11 quoted lines
> 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;
Do not explicitly initialize statics to '0' (or NULL for that matter).

But more importantly, I have a feeling that you are making a piece of code that is already hard to read impossible to follow by adding yet another variable.

Show 9 quoted lines
> 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' '
Missing blank line between tests.

I thought that the root cause of the problem is that run_merge() is called even when rebase was asked for (either via pull.rebase=true configuration or "pull --rebase" option), when the other side is a descendant of HEAD. The basic idea behind that behaviour may be sound (i.e. if we do not have any of our own development on top of their history, rebase vs merge shouldn't make any difference while fast-forwarding HEAD to their history), except that rebase vs merge look at different configuration variables.

I wonder if the following two-liner patch is a simpler fix that is easier to understand. run_merge() decides if we should pass the "--[no-]autostash" option based on the value of opt_autostash, and we know the value of rebase.autostash in config_autostash variable.

It appears to pass all four tests your patch adds.
 builtin/pull.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git c/builtin/pull.c w/builtin/pull.c
index 100cbf9fb8..d459a91a64 100644
--- c/builtin/pull.c
+++ w/builtin/pull.c
@@ -1133,7 +1133,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 			die(_("cannot rebase with locally recorded submodule modifications"));
 
 		if (can_ff) {
-			/* we can fast-forward this without invoking rebase */
+			/*
+			 * We can fast-forward without invoking
+			 * rebase, by calling run_merge().  But we
+			 * have to allow rebase.autostash=true to kick
+			 * in.
+			 */
+			if (opt_autostash < 0)
+				opt_autostash = config_autostash;
 			opt_ff = "--ff-only";
 			ret = run_merge();
 		} else {
Previous: John CaiNext: Philippe Blain
Message 3 of 15 in “Fix bug in pull --rebase not recognizing rebase.autostash”
  1. 0/1 Fix bug in pull --rebase not recognizing rebase.autostashJohn Cai, Jan 4, 2022
  2. 1/1 builtin/pull.c: use config value of autostashJohn Cai, Jan 4, 2022
  3. Junio C HamanoJan 4, 2022
  4. Philippe BlainJan 5, 2022
  5. Junio C HamanoJan 6, 2022
  6. Junio C HamanoJan 14, 2022
  7. Philippe BlainJan 14, 2022
  8. John CaiJan 14, 2022
  9. Junio C HamanoJan 14, 2022
  10. Philippe BlainJan 14, 2022
  11. Phillip WoodJan 5, 2022
  12. Philippe BlainJan 5, 2022
  13. Philippe BlainJan 5, 2022
  14. Johannes SchindelinJan 5, 2022
  15. Philippe BlainJan 4, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.