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

Re: [PATCH 5/3] revert: introduce --abort to cancel a failed cherry-pick

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 30, 2011, 22:52 UTC
Message-ID
<7vty5lp6jc.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20111122112001.GF7399@elie.hsd1.il.comcast.net>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 5 quoted lines
> After running some ill-advised command like "git cherry-pick
> HEAD..linux-next", the bewildered novice may want to return to more
> familiar territory.  Introduce a "git cherry-pick --abort" command
> that rolls back the entire cherry-pick sequence and places the
> repository back on solid ground.

This is confusing; if you have many commits in the range, and a handful of them replayed without conflicts and then you hit a conflict, where should (I am not asking "where does ... with your patch") abort take us? The state after the random commit that happened to have replayed successfully? The state before the entire cherry-pick sequence started? "back on solid ground" does not tell us which one you meant.

I am assuming that it is the latter.
Show 11 quoted lines
> diff --git a/Documentation/sequencer.txt b/Documentation/sequencer.txt
> index 75f8e869..5747f442 100644
> --- a/Documentation/sequencer.txt
> +++ b/Documentation/sequencer.txt
> @@ -7,3 +7,6 @@
>  	Forget about the current operation in progress.  Can be used
>  	to clear the sequencer state after a failed cherry-pick or
>  	revert.
> +
> +--abort::
> +	Cancel the operation and return to the pre-sequence state.
Ok, it is the latter.
Show 9 quoted lines
> +static int reset_for_rollback(const unsigned char *sha1)
> +{
> +	const char *argv[4];	/* reset --merge <arg> + NULL */
> +	argv[0] = "reset";
> +	argv[1] = "--merge";
> +	argv[2] = sha1_to_hex(sha1);
> +	argv[3] = NULL;
> +	return run_command_v_opt(argv, RUN_GIT_CMD);
> +}

So you give the value of the HEAD before the sequence started to this function and all should go well. Where do you read that value from?

Show 11 quoted lines
> +static int rollback_single_pick(void)
> +{
> +	unsigned char head_sha1[20];
> +
> +	if (!file_exists(git_path("CHERRY_PICK_HEAD")) &&
> +	    !file_exists(git_path("REVERT_HEAD")))
> +		return error(_("no cherry-pick or revert in progress"));
> +	if (!resolve_ref("HEAD", head_sha1, 0, NULL))
> +		return error(_("cannot resolve HEAD"));
> +	if (is_null_sha1(head_sha1))
> +		return error(_("cannot abort from a branch yet to be born"));
Ok, this is for single-pick so HEAD is where we came from. Good.
Show 28 quoted lines
> +	return reset_for_rollback(head_sha1);
> +}
> +
> +static int sequencer_rollback(struct replay_opts *opts)
> +{
> +	const char *filename;
> +	FILE *f;
> +	unsigned char sha1[20];
> +	struct strbuf buf = STRBUF_INIT;
> +
> +	filename = git_path(SEQ_HEAD_FILE);
> +	f = fopen(filename, "r");
> +	if (!f && errno == ENOENT) {
> +		/*
> +		 * There is no multiple-cherry-pick in progress.
> +		 * If CHERRY_PICK_HEAD or REVERT_HEAD indicates
> +		 * a single-cherry-pick in progress, abort that.
> +		 */
> +		return rollback_single_pick();
> +	}
> +	if (!f)
> +		return error(_("cannot open %s: %s"), filename,
> +						strerror(errno));
> +	if (strbuf_getline(&buf, f, '\n')) {
> +		error(_("cannot read %s: %s"), filename, ferror(f) ?
> +			strerror(errno) : _("unexpected end of file"));
> +		goto fail;
> +	}
And when we are in multi-pick, SEQ_HEAD_FILE has it.
Looks good from a cursory review. Thanks.
Previous: Alex RiesenNext: Jonathan Nieder
Message 47 of 52 in “cherry-pick/revert error messages”
  1. Jonathan NiederNov 20, 2011
  2. Ramkumar RamachandraNov 20, 2011
  3. 0/3 Re: cherry-pick/revert error messagesJonathan Nieder, Nov 20, 2011
  4. 1/3 revert: rename --reset option to --quitJonathan Nieder, Nov 20, 2011
  5. Junio C HamanoNov 21, 2011
  6. Jakub NarebskiNov 21, 2011
  7. Jonathan NiederNov 21, 2011
  8. 2/3 revert: rearrange pick_revisions() for clarityJonathan Nieder, Nov 20, 2011
  9. 3/3 revert: improve error message for cherry-pick during cherry-pickJonathan Nieder, Nov 20, 2011
  10. 0/3 Re: cherry-pick/revert error messagesJonathan Nieder, Nov 22, 2011
  11. 1/3 revert: rename --reset option to --quitJonathan Nieder, Nov 22, 2011
  12. 2/3 revert: rearrange pick_revisions() for clarityJonathan Nieder, Nov 22, 2011
  13. 3/3 revert: improve error message for cherry-pick during cherry-pickJonathan Nieder, Nov 22, 2011
  14. 4/3 revert: write REVERT_HEAD pseudoref during conflicted revertJonathan Nieder, Nov 22, 2011
  15. Thiago FarinaNov 22, 2011
  16. Ramkumar RamachandraDec 1, 2011
  17. 5/3 revert: introduce --abort to cancel a failed cherry-pickJonathan Nieder, Nov 22, 2011
  18. Junio C HamanoNov 23, 2011
  19. Jonathan NiederNov 23, 2011
  20. Fix revert --abort on WindowsJohannes Sixt, Nov 23, 2011
  21. Jonathan NiederNov 23, 2011
  22. Johannes SixtNov 23, 2011
  23. 0/7 some sequencer loose ends (Re: Fix revert --abort on Windows)Jonathan Nieder, Dec 10, 2011
  24. 1/7 revert: give --continue handling its own functionJonathan Nieder, Dec 10, 2011
  25. Ramkumar RamachandraDec 14, 2011
  26. 2/7 revert: allow cherry-pick --continue to commit before resumingJonathan Nieder, Dec 10, 2011
  27. Ramkumar RamachandraDec 14, 2011
  28. Jonathan NiederDec 14, 2011
  29. 3/7 revert: pass around rev-list args in already-parsed formJonathan Nieder, Dec 10, 2011
  30. Ramkumar RamachandraDec 14, 2011
  31. 4/7 revert: allow single-pick in the middle of cherry-pick sequenceJonathan Nieder, Dec 10, 2011
  32. Ramkumar RamachandraDec 14, 2011
  33. Jonathan NiederDec 14, 2011
  34. Ævar Arnfjörð BjarmasonApr 5, 2012
  35. Jonathan NiederApr 5, 2012
  36. 5/7 revert: do not remove state until sequence is finishedJonathan Nieder, Dec 10, 2011
  37. Ramkumar RamachandraDec 14, 2011
  38. 6/7 Revert "reset: Make reset remove the sequencer state"Jonathan Nieder, Dec 10, 2011
  39. Ramkumar RamachandraDec 14, 2011
  40. 7/7 revert: stop creating and removing sequencer-old directoryJonathan Nieder, Dec 10, 2011
  41. Ramkumar RamachandraDec 14, 2011
  42. Jonathan NiederDec 11, 2011
  43. Junio C HamanoDec 12, 2011
  44. Junio C HamanoDec 12, 2011
  45. Jonathan NiederDec 14, 2011
  46. Alex RiesenNov 23, 2011
  47. Junio C HamanoNov 30, 2011
  48. 6/3 revert: remove --reset compatibility optionJonathan Nieder, Nov 22, 2011
  49. Junio C HamanoNov 22, 2011
  50. Jonathan NiederNov 22, 2011
  51. Junio C HamanoNov 22, 2011
  52. Jonathan NiederNov 22, 2011

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.