threads / patch / 56923

patchpull: should be noop when already-up-to-date

Subject: [PATCH] pull: should be noop when already-up-to-date

## tl;dr

2 messages between Nov 17, 2021 and Nov 18, 2021. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Erwin Villejo via GitGitGadget· Nov 17, 2021, 07:55 UTC · lore
From: Erwin Villejo <erwin.villejo@gmail.com>

The already-up-to-date pull bug was fixed for --ff-only but it did not include the case where --ff or --ff-only are not specified. This updates the --ff-only fix to include the case where --ff or --ff-only are not specified in command line flags or config.

Signed-off-by: Erwin Villejo <erwin.villejo@gmail.com>
---
    pull: should be noop when already-up-to-date
    
    The already-up-to-date pull bug was fixed for --ff-only but it did not
    include the case where --ff or --ff-only are not specified. This updates
    the --ff-only fix to include the case where --ff or --ff-only are not
    specified in command line flags or config.
    
    Signed-off-by: Erwin Villejo erwin.villejo@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1078%2Ferwinv%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1078/erwinv/master-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1078
 builtin/pull.c               | 6 ++++--
 t/t7601-merge-pull-config.sh | 6 ++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
Show changes to 2 files +10 −2

builtin/pull.c, t/t7601-merge-pull-config.sh

diff --git a/builtin/pull.c b/builtin/pull.c
index 127798ba84e..1cfaf9f3436 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -988,6 +988,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 	struct object_id rebase_fork_point;
 	int rebase_unspecified = 0;
 	int can_ff;
+	int divergent;
 
 	if (!getenv("GIT_REFLOG_ACTION"))
 		set_reflog_message(argc, argv);
@@ -1102,15 +1103,16 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 	}
 
 	can_ff = get_can_ff(&orig_head, &merge_heads);
+	divergent = !can_ff && !already_up_to_date(&orig_head, &merge_heads);
 
 	/* ff-only takes precedence over rebase */
 	if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
-		if (!can_ff && !already_up_to_date(&orig_head, &merge_heads))
+		if (divergent)
 			die_ff_impossible();
 		opt_rebase = REBASE_FALSE;
 	}
 	/* If no action specified and we can't fast forward, then warn. */
-	if (!opt_ff && rebase_unspecified && !can_ff) {
+	if (!opt_ff && rebase_unspecified && divergent) {
 		show_advice_pull_non_ff();
 		die(_("Need to specify how to reconcile divergent branches."));
 	}
diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh
index 6275641b9c2..bd238d89b0c 100755
--- a/t/t7601-merge-pull-config.sh
+++ b/t/t7601-merge-pull-config.sh
@@ -387,6 +387,12 @@ test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
 	test_must_fail git pull . c3
 '
 
+test_expect_success 'already-up-to-date pull succeeds with unspecified pull.ff' '
+	git reset --hard c1 &&
+	git pull . c0 &&
+	test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
+'
+
 test_expect_success 'already-up-to-date pull succeeds with "only" in pull.ff' '
 	git reset --hard c1 &&
 	test_config pull.ff only &&

base-commit: cd3e606211bb1cf8bc57f7d76bab98cc17a150bc
-- 
gitgitgadget
Junio C Hamano· Nov 18, 2021, 23:50 UTC · re: Erwin Villejo via GitGitGadget · lore

Re: [PATCH] pull: should be noop when already-up-to-date

"Erwin Villejo via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 9 quoted lines
> From: Erwin Villejo <erwin.villejo@gmail.com>
>
> The already-up-to-date pull bug was fixed for --ff-only but it did not
> include the case where --ff or --ff-only are not specified. This updates
> the --ff-only fix to include the case where --ff or --ff-only are not
> specified in command line flags or config.
>
> Signed-off-by: Erwin Villejo <erwin.villejo@gmail.com>
> ---
Show 19 quoted lines
> @@ -1102,15 +1103,16 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
>  	}
>  
>  	can_ff = get_can_ff(&orig_head, &merge_heads);
> +	divergent = !can_ff && !already_up_to_date(&orig_head, &merge_heads);
>  
>  	/* ff-only takes precedence over rebase */
>  	if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
> -		if (!can_ff && !already_up_to_date(&orig_head, &merge_heads))
> +		if (divergent)
>  			die_ff_impossible();
>  		opt_rebase = REBASE_FALSE;
>  	}
>  	/* If no action specified and we can't fast forward, then warn. */
> -	if (!opt_ff && rebase_unspecified && !can_ff) {
> +	if (!opt_ff && rebase_unspecified && divergent) {
>  		show_advice_pull_non_ff();
>  		die(_("Need to specify how to reconcile divergent branches."));
>  	}

Looks correct. I wonder if there is a simplify these two checks, but let's keep the original code structure for now in this step, which is about correctness.

Will apply.  Thanks.
Show 19 quoted lines
> diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh
> index 6275641b9c2..bd238d89b0c 100755
> --- a/t/t7601-merge-pull-config.sh
> +++ b/t/t7601-merge-pull-config.sh
> @@ -387,6 +387,12 @@ test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
>  	test_must_fail git pull . c3
>  '
>  
> +test_expect_success 'already-up-to-date pull succeeds with unspecified pull.ff' '
> +	git reset --hard c1 &&
> +	git pull . c0 &&
> +	test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
> +'
> +
>  test_expect_success 'already-up-to-date pull succeeds with "only" in pull.ff' '
>  	git reset --hard c1 &&
>  	test_config pull.ff only &&
>
> base-commit: cd3e606211bb1cf8bc57f7d76bab98cc17a150bc

← back to recent threads