Skip to content

Commit 3e8fb61

Browse files
committed
status: do not report errors in sequencer/todo
commit 4a72486 ("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 b07d9bf ("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/[email protected]/ Reported-by: Espen Antonsen <[email protected]> Signed-off-by: Phillip Wood <[email protected]>
1 parent c3885c0 commit 3e8fb61

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

sequencer.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,34 +2177,26 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
21772177

21782178
int sequencer_get_last_command(struct repository *r, enum replay_action *action)
21792179
{
2180-
struct todo_item item;
2181-
char *eol;
2182-
const char *todo_file;
2180+
const char *todo_file, *bol;
21832181
struct strbuf buf = STRBUF_INIT;
2184-
int ret = -1;
2182+
int ret = 0;
21852183

21862184
todo_file = git_path_todo_file();
21872185
if (strbuf_read_file(&buf, todo_file, 0) < 0) {
2188-
if (errno == ENOENT)
2186+
if (errno == ENOENT || errno == ENOTDIR)
21892187
return -1;
21902188
else
21912189
return error_errno("unable to open '%s'", todo_file);
21922190
}
2193-
eol = strchrnul(buf.buf, '\n');
2194-
if (buf.buf != eol && eol[-1] == '\r')
2195-
eol--; /* strip Carriage Return */
2196-
if (parse_insn_line(r, &item, buf.buf, buf.buf, eol))
2197-
goto fail;
2198-
if (item.command == TODO_PICK)
2191+
bol = buf.buf + strspn(buf.buf, " \t\r\n");
2192+
if (is_command(TODO_PICK, &bol) && (*bol == ' ' || *bol == '\t'))
21992193
*action = REPLAY_PICK;
2200-
else if (item.command == TODO_REVERT)
2194+
else if (is_command(TODO_REVERT, &bol) &&
2195+
(*bol == ' ' || *bol == '\t'))
22012196
*action = REPLAY_REVERT;
22022197
else
2203-
goto fail;
2204-
2205-
ret = 0;
2198+
ret = -1;
22062199

2207-
fail:
22082200
strbuf_release(&buf);
22092201

22102202
return ret;

t/t7512-status-help.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,22 @@ EOF
798798
test_i18ncmp expected actual
799799
'
800800

801+
test_expect_success 'status shows cherry-pick with invalid oid' '
802+
mkdir .git/sequencer &&
803+
test_write_lines "pick invalid-oid" >.git/sequencer/todo &&
804+
git status --untracked-files=no >actual 2>err &&
805+
git cherry-pick --quit &&
806+
test_must_be_empty err &&
807+
test_i18ncmp expected actual
808+
'
809+
810+
test_expect_success 'status does not show error if .git/sequencer is a file' '
811+
test_when_finished "rm .git/sequencer" &&
812+
test_write_lines hello >.git/sequencer &&
813+
git status --untracked-files=no 2>err &&
814+
test_must_be_empty err
815+
'
816+
801817
test_expect_success 'status showing detached at and from a tag' '
802818
test_commit atag tagging &&
803819
git checkout atag &&

0 commit comments

Comments
 (0)