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

Re: [PATCH] push: fix --force-if-includes when remote-tracking ref has no reflog

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 3, 2026, 16:16 UTC
Message-ID
<xmqq5x0mfgyh.fsf@gitster.g>
In-Reply-To
<20260903010547.85469-1-f@lex.la>
Aleksei Sviridkin <f@lex.la> writes:
Show 21 quoted lines
> Since 99a1f9ae10 (push: add reflog check for "--force-if-includes",
> 2020-10-03), is_reachable_in_reflog() stops walking the reflog of the
> local branch at entries older than the newest reflog entry of the
> remote-tracking ref. That timestamp is read by a callback of
> refs_for_each_reflog_ent_reverse() into a variable that is never
> initialized, so when the remote-tracking ref has no reflog the walk
> is cut off at whatever happens to be on the stack.
>
> With the files backend a remote-tracking ref created by "git clone"
> has no reflog and does not get one until it moves. On my machine the
> leftover value exceeds any real timestamp: the walk stops at the very
> first entry, never reaches the "Created from" entry that "checkout
> --track" wrote, and the push is rejected with "remote ref updated
> since checkout" although nothing on the remote has changed.
>
> Initialize the timestamp to zero, so that a remote-tracking ref
> without reflog makes the walk cover the whole reflog of the local
> branch, as documented.
>
> Signed-off-by: Aleksei Sviridkin <f@lex.la>
> Assisted-by: LLM

The last line adds no useful information, though. Besides, you are fully responsible for whatever LLM emitted and contributed into this patch, so your sign-off must be the last line in the trailers.

> ---
> The new test fails without the fix on my machine (macOS, arm64). As
> the value read is uninitialized, other platforms may pass it by luck.
The code change looks good.

It is a bit surprising to see the fallout from a change 6 years ago to be addressed now, and makes me wonder what else changed recently. Certainly year 2026 is not the first year in which macOS on arm64 started becoming widely used, or you are not the only user of Git on that platform.

Show 31 quoted lines
>  remote.c            |  2 +-
>  t/t5533-push-cas.sh | 18 ++++++++++++++++++
>  2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/remote.c b/remote.c
> index 00723b3..6d30169 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -2751,7 +2751,7 @@ static int check_and_collect_until(const char *refname UNUSED,
>   */
>  static int is_reachable_in_reflog(const char *local, const struct ref *remote)
>  {
> -	timestamp_t date;
> +	timestamp_t date = 0;
>  	struct commit *commit;
>  	struct commit **chunk;
>  	struct check_and_collect_until_cb_data cb;
> diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
> index cba26a8..77f46f3 100755
> --- a/t/t5533-push-cas.sh
> +++ b/t/t5533-push-cas.sh
> @@ -396,4 +396,22 @@ test_expect_success '"--force-if-includes" should allow deletes' '
>  	)
>  '
>  
> +test_expect_success '"--force-if-includes" should allow forced update when remote-tracking ref has no reflog' '
> +	rm -fr dst src &&
> +	git init --bare dst &&
> +	git push dst main main:branch &&
> +	git clone --no-local dst src &&
> +	test_when_finished "rm -fr dst src" &&

You'd want to move "test_when_finished" immediately before "git init --bare dst", no? That way, you can clean things up after any or the "init", "push", "clone" fails (as well as the main part of the test that is done in the subdirectory).

Show 15 quoted lines
> +	(
> +		cd src &&
> +		# a clone leaves the remote-tracking refs without reflog
> +		# entries with the files backend, but not with reftable
> +		git reflog expire --all --expire=all &&
> +		git switch -c branch --track origin/branch &&
> +		git reset --hard HEAD^ &&
> +		test_commit D &&
> +		git push --force-if-includes --force-with-lease="branch"
> +	)
> +'
> +
>  test_done
>
> base-commit: e9019fcafe0040228b8631c30f97ae1adb61bcdc
Previous: Aleksei SviridkinNext: Aleksei Sviridkin
Message 2 of 27 in “push: fix --force-if-includes when remote-tracking ref has no reflog”
  1. push: fix --force-if-includes when remote-tracking ref has no reflogAleksei Sviridkin, Sep 3, 2026
  2. Junio C HamanoSep 3, 2026
  3. Aleksei SviridkinSep 3, 2026
  4. Junio C HamanoSep 3, 2026
  5. Aleksei SviridkinSep 3, 2026
  6. Kristoffer HaugsbakkSep 4, 2026
  7. Junio C HamanoSep 4, 2026
  8. Aleksei SviridkinSep 5, 2026
  9. Kristoffer HaugsbakkSep 6, 2026
  10. Junio C HamanoSep 6, 2026
  11. Thomas BachemSep 7, 2026
  12. Weijie YuanSep 7, 2026
  13. push: fix --force-if-includes when remote-tracking ref has no reflogAleksei Sviridkin, Sep 4, 2026
  14. Junio C HamanoSep 4, 2026
  15. Junio C HamanoSep 6, 2026
  16. Aleksei SviridkinSep 6, 2026
  17. Junio C HamanoSep 8, 2026
  18. Aleksei SviridkinSep 9, 2026
  19. Junio C HamanoSep 10, 2026
  20. Aleksei SviridkinSep 10, 2026
  21. Tyler CiprianiSep 25, 2026
  22. Junio C HamanoSep 25, 2026
  23. push: fix --force-if-includes when remote-tracking ref has no reflogAleksei Sviridkin, Sep 5, 2026
  24. Tyler CiprianiSep 29, 2026
  25. Junio C HamanoSep 29, 2026
  26. push: fix --force-if-includes when remote-tracking ref has no reflogAleksei Sviridkin, Sep 29, 2026
  27. Junio C HamanoSep 29, 2026

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.