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

[PATCH 3/3] status: do not report errors in sequencer/todo

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 25, 2019, 10:11 UTC
Message-ID
<af4b823caac84899b5ac71da61af5ec00f88bb2f.1561457483.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.275.git.gitgitgadget@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

commit 4a72486de9 ("fix cherry-pick/revert status after commit", 2019-04-16) used parse_insn_line() to parse the first line of the todo list to check if it was a pick or revert. However if the todo list is left over from an old cherry-pick or revert and references a commit that no longer exists then parse_insn_line() prints an error message which is confusing for users [1]. Instead parse just the command name so that the user is alerted to the presence of stale sequencer state by status reporting that a cherry-pick or revert is in progress.

Note that we should not be leaving stale sequencer state lying around (or at least not as often) after commit b07d9bfd17 ("commit/reset: try to clean up sequencer state", 2019-04-16). However the user may still have stale state that predates that commit.

Also avoid printing an error message if for some reason the user has a file called `sequencer` in $GIT_DIR.

[1] https://public-inbox.org/git/3bc58c33-4268-4e7c-bf1a-fe349b3cb037@www.fastmail.com/
Reported-by: Espen Antonsen <espen@inspired.no>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c            | 24 ++++++++----------------
 t/t7512-status-help.sh | 16 ++++++++++++++++
 2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 793f86bf9a..f8eab1697e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2177,34 +2177,26 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
 
 int sequencer_get_last_command(struct repository *r, enum replay_action *action)
 {
-	struct todo_item item;
-	char *eol;
-	const char *todo_file;
+	const char *todo_file, *bol;
 	struct strbuf buf = STRBUF_INIT;
-	int ret = -1;
+	int ret = 0;
 
 	todo_file = git_path_todo_file();
 	if (strbuf_read_file(&buf, todo_file, 0) < 0) {
-		if (errno == ENOENT)
+		if (errno == ENOENT || errno == ENOTDIR)
 			return -1;
 		else
 			return error_errno("unable to open '%s'", todo_file);
 	}
-	eol = strchrnul(buf.buf, '\n');
-	if (buf.buf != eol && eol[-1] == '\r')
-		eol--; /* strip Carriage Return */
-	if (parse_insn_line(r, &item, buf.buf, buf.buf, eol))
-		goto fail;
-	if (item.command == TODO_PICK)
+	bol = buf.buf + strspn(buf.buf, " \t\r\n");
+	if (is_command(TODO_PICK, &bol) && (*bol == ' ' || *bol == '\t'))
 		*action = REPLAY_PICK;
-	else if (item.command == TODO_REVERT)
+	else if (is_command(TODO_REVERT, &bol) &&
+		 (*bol == ' ' || *bol == '\t'))
 		*action = REPLAY_REVERT;
 	else
-		goto fail;
-
-	ret = 0;
+		ret = -1;
 
- fail:
 	strbuf_release(&buf);
 
 	return ret;
diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index c1eb72555d..3c9308709a 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -798,6 +798,22 @@ EOF
 	test_i18ncmp expected actual
 '
 
+test_expect_success 'status shows cherry-pick with invalid oid' '
+	mkdir .git/sequencer &&
+	test_write_lines "pick invalid-oid" >.git/sequencer/todo &&
+	git status --untracked-files=no >actual 2>err &&
+	git cherry-pick --quit &&
+	test_must_be_empty err &&
+	test_i18ncmp expected actual
+'
+
+test_expect_success 'status does not show error if .git/sequencer is a file' '
+	test_when_finished "rm .git/sequencer" &&
+	test_write_lines hello >.git/sequencer &&
+	git status --untracked-files=no 2>err &&
+	test_must_be_empty err
+'
+
 test_expect_success 'status showing detached at and from a tag' '
 	test_commit atag tagging &&
 	git checkout atag &&
-- 
gitgitgadget
Previous: Phillip WoodNext: Johannes Schindelin
Message 6 of 17 in “Wip/quieter sequencer status parsing”
  1. 0/3 Wip/quieter sequencer status parsingPhillip Wood via GitGitGadget, Jun 25, 2019
  2. 1/3 sequencer: always allow tab after command namePhillip Wood via GitGitGadget, Jun 25, 2019
  3. 2/3 sequencer: factor out todo command name parsingPhillip Wood via GitGitGadget, Jun 25, 2019
  4. René ScharfeJun 25, 2019
  5. Phillip WoodJun 25, 2019
  6. 3/3 status: do not report errors in sequencer/todoPhillip Wood via GitGitGadget, Jun 25, 2019
  7. Johannes SchindelinJun 25, 2019
  8. Junio C HamanoJun 25, 2019
  9. Phillip WoodJun 26, 2019
  10. Phillip WoodJul 1, 2019
  11. Phillip WoodJun 25, 2019
  12. 0/3 Quieter sequencer status parsingPhillip Wood via GitGitGadget, Jun 27, 2019
  13. 1/3 sequencer: always allow tab after command namePhillip Wood via GitGitGadget, Jun 27, 2019
  14. Junio C HamanoJun 27, 2019
  15. 2/3 sequencer: factor out todo command name parsingPhillip Wood via GitGitGadget, Jun 27, 2019
  16. Junio C HamanoJun 27, 2019
  17. 3/3 status: do not report errors in sequencer/todoPhillip Wood via GitGitGadget, Jun 27, 2019

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.