@@ -2142,6 +2142,43 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
return !item->commit;
}
+int sequencer_get_last_command(struct repository *r, enum replay_action *action,
+ struct object_id *oid)
+{
+ struct todo_item item;
+ char *eol;
+ const char *todo_file;
+ struct strbuf buf = STRBUF_INIT;
+ int ret = -1;
+
+ todo_file = git_path_todo_file();
+ if (strbuf_read_file(&buf, todo_file, 0) < 0) {
+ if (errno == ENOENT)
+ 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, eol))
+ goto fail;
+ if (item.command == TODO_PICK)
+ *action = REPLAY_PICK;
+ else if (item.command == TODO_REVERT)
+ *action = REPLAY_REVERT;
+ else
+ goto fail;
+
+ oidcpy(oid, &item.commit->object.oid);
+ ret = 0;
+
+ fail:
+ strbuf_release(&buf);
+
+ return ret;
+}
+
static int parse_insn_buffer(struct repository *r, char *buf,
struct todo_list *todo_list)
{
@@ -145,3 +145,5 @@ void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
int write_basic_state(struct replay_opts *opts, const char *head_name,
const char *onto, const char *orig_head);
void sequencer_post_commit_cleanup(void);
+int sequencer_get_last_command(struct repository* r, enum replay_action *action,
+ struct object_id *oid);
@@ -780,6 +780,25 @@ EOF
test_i18ncmp expected actual
'
+test_expect_success 'status when cherry-picking after committing conflict resolution' '
+ git reset --hard cherry_branch &&
+ test_when_finished "git cherry-pick --abort" &&
+ test_must_fail git cherry-pick cherry_branch_second one_cherry &&
+ TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
+ echo end >main.txt &&
+ git commit -a &&
+ cat >expected <<EOF &&
+On branch cherry_branch
+You are currently cherry-picking commit $TO_CHERRY_PICK.
+ (all conflicts fixed: run "git cherry-pick --continue")
+ (use "git cherry-pick --abort" to cancel the cherry-pick operation)
+
+nothing to commit (use -u to show untracked files)
+EOF
+ git status --untracked-files=no >actual &&
+ test_i18ncmp expected actual
+'
+
test_expect_success 'status showing detached at and from a tag' '
test_commit atag tagging &&
git checkout atag &&
@@ -17,6 +17,7 @@
#include "utf8.h"
#include "worktree.h"
#include "lockfile.h"
+#include "sequencer.h"
static const char cut_line[] =
"------------------------ >8 ------------------------\n";
@@ -1563,6 +1564,7 @@ void wt_status_get_state(struct repository *r,
{
struct stat st;
struct object_id oid;
+ enum replay_action action;
if (!stat(git_path_merge_head(r), &st)) {
wt_status_check_rebase(NULL, state);
@@ -1580,7 +1582,15 @@ void wt_status_get_state(struct repository *r,
state->revert_in_progress = 1;
oidcpy(&state->revert_head_oid, &oid);
}
-
+ if (!sequencer_get_last_command(r, &action, &oid)) {
+ if (action == REPLAY_PICK) {
+ state->cherry_pick_in_progress = 1;
+ oidcpy(&state->cherry_pick_head_oid, &oid);
+ } else {
+ state->revert_in_progress = 1;
+ oidcpy(&state->revert_head_oid, &oid);
+ }
+ }
if (get_detached_from)
wt_status_get_detached_from(r, state);
}