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

Re: [PATCH 2/3] Treat CHERRY_PICK_HEAD as a pseudo ref

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 18, 2020, 21:05 UTC
Message-ID
<xmqqsgcjwtpv.fsf@gitster.c.googlers.com>
In-Reply-To
<06a8e8cbd1370ba3d4ea8a0a9f1e69d27b1d62c4.1597753075.git.gitgitgadget@gmail.com>
"Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Han-Wen Nienhuys <hanwen@google.com>
>
> Check for existence and delete CHERRY_PICK_HEAD through ref functions.
> This will help cherry-pick work with alternate ref storage backends.

These two sentences are true, but this patch does another thing that is not advertised here. It stops recommending removal of CHERRY_PICK_HEAD from the filesystem with "rm" (or using "git update-ref -d" for that matter) as a way to avoid recording the current commit as a cherry-pick.

The intent of the warning message touched by this patch, I think, is that there is CHERRY_PICK_HEAD, but that might be a leftover one that does not have to do anything to do with the commit the user is making, and continuing blindly may record the commit incorrectly (perhaps 'cherry-picked-from' trailer is added incorrectly? existing notes data would be copied to the newly created commit?).

To recover from the situation, the user would want to abort the commit while keeping the changes made to the working tree and to the index to avoid the result recorded as a cherry-pick of an irrelevant commit, get rid of CHERRY_PICK_HEAD and then attempt the "git commit" again.

Does "git cherry-pick --abort" only remove CHERRY_PICK_HEAD without doing any other damage to the working tree files and to the index?

Show 53 quoted lines
> Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
> ---
>  builtin/commit.c | 34 +++++++++++++++++++---------------
>  builtin/merge.c  |  2 +-
>  path.c           |  1 -
>  path.h           |  7 ++++---
>  sequencer.c      | 42 ++++++++++++++++++++++++++----------------
>  wt-status.c      |  4 ++--
>  6 files changed, 52 insertions(+), 38 deletions(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 69ac78d5e5..619b71bcb4 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -847,21 +847,25 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  			if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
>  				!merge_contains_scissors)
>  				wt_status_add_cut_line(s->fp);
> -			status_printf_ln(s, GIT_COLOR_NORMAL,
> -			    whence == FROM_MERGE
> -				? _("\n"
> -					"It looks like you may be committing a merge.\n"
> -					"If this is not correct, please remove the file\n"
> -					"	%s\n"
> -					"and try again.\n")
> -				: _("\n"
> -					"It looks like you may be committing a cherry-pick.\n"
> -					"If this is not correct, please remove the file\n"
> -					"	%s\n"
> -					"and try again.\n"),
> -				whence == FROM_MERGE ?
> -					git_path_merge_head(the_repository) :
> -					git_path_cherry_pick_head(the_repository));
> +			if (whence == FROM_MERGE)
> +				status_printf_ln(
> +					s, GIT_COLOR_NORMAL,
> +
> +					_("\n"
> +					  "It looks like you may be committing a merge.\n"
> +					  "If this is not correct, please remove the file\n"
> +					  "	%s\n"
> +					  "and try again.\n"),
> +					git_path_merge_head(the_repository));
> +			else
> +				status_printf_ln(
> +					s, GIT_COLOR_NORMAL,
> +
> +					_("\n"
> +					  "It looks like you may be committing a cherry-pick.\n"
> +					  "If this is not correct, please run\n"
> +					  "	git cherry-pick --abort\n"
> +					  "and try again.\n"));
>  		}
I do not know about this change (see above).
Show 10 quoted lines
> diff --git a/builtin/merge.c b/builtin/merge.c
> index 74829a838e..b9a89ba858 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -1348,7 +1348,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
>  		else
>  			die(_("You have not concluded your merge (MERGE_HEAD exists)."));
>  	}
> -	if (file_exists(git_path_cherry_pick_head(the_repository))) {
> +	if (ref_exists("CHERRY_PICK_HEAD")) {
This, and all the rest, look quite sensible.
Show 15 quoted lines
> diff --git a/wt-status.c b/wt-status.c
> index d75399085d..c6abf2f3ca 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1672,8 +1672,8 @@ void wt_status_get_state(struct repository *r,
>  		state->merge_in_progress = 1;
>  	} else if (wt_status_check_rebase(NULL, state)) {
>  		;		/* all set */
> -	} else if (!stat(git_path_cherry_pick_head(r), &st) &&
> -			!get_oid("CHERRY_PICK_HEAD", &oid)) {
> +	} else if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
> +		   !get_oid("CHERRY_PICK_HEAD", &oid)) {
>  		state->cherry_pick_in_progress = 1;
>  		oidcpy(&state->cherry_pick_head_oid, &oid);
>  	}
Previous: Han-Wen Nienhuys via GitGitGadgetNext: Han-Wen Nienhuys
Message 5 of 23 in “Use refs API for handling sundry pseudorefs”
  1. 0/3 Use refs API for handling sundry pseudorefsHan-Wen Nienhuys via GitGitGadget, Aug 18, 2020
  2. 1/3 Make refs_ref_exists publicHan-Wen Nienhuys via GitGitGadget, Aug 18, 2020
  3. Junio C HamanoAug 18, 2020
  4. 2/3 Treat CHERRY_PICK_HEAD as a pseudo refHan-Wen Nienhuys via GitGitGadget, Aug 18, 2020
  5. Junio C HamanoAug 18, 2020
  6. Han-Wen NienhuysAug 19, 2020
  7. Junio C HamanoAug 19, 2020
  8. 3/3 Treat REVERT_HEAD as a pseudo refHan-Wen Nienhuys via GitGitGadget, Aug 18, 2020
  9. Junio C HamanoAug 18, 2020
  10. Junio C HamanoAug 18, 2020
  11. 0/4 Use refs API for handling sundry pseudorefsHan-Wen Nienhuys via GitGitGadget, Aug 19, 2020
  12. 1/4 refs: make refs_ref_exists publicHan-Wen Nienhuys via GitGitGadget, Aug 19, 2020
  13. 2/4 sequencer: treat CHERRY_PICK_HEAD as a pseudo refHan-Wen Nienhuys via GitGitGadget, Aug 19, 2020
  14. 3/4 builtin/commit: suggest update-ref for pseudoref removalHan-Wen Nienhuys via GitGitGadget, Aug 19, 2020
  15. Junio C HamanoAug 19, 2020
  16. Han-Wen NienhuysAug 21, 2020
  17. 4/4 sequencer: treat REVERT_HEAD as a pseudo refHan-Wen Nienhuys via GitGitGadget, Aug 19, 2020
  18. 0/4 Use refs API for handling sundry pseudorefsHan-Wen Nienhuys via GitGitGadget, Aug 21, 2020
  19. 4/4 sequencer: treat REVERT_HEAD as a pseudo refHan-Wen Nienhuys via GitGitGadget, Aug 21, 2020
  20. 2/4 sequencer: treat CHERRY_PICK_HEAD as a pseudo refHan-Wen Nienhuys via GitGitGadget, Aug 21, 2020
  21. 1/4 refs: make refs_ref_exists publicHan-Wen Nienhuys via GitGitGadget, Aug 21, 2020
  22. 3/4 builtin/commit: suggest update-ref for pseudoref removalHan-Wen Nienhuys via GitGitGadget, Aug 21, 2020
  23. Junio C HamanoAug 21, 2020

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.