Merge branch 'pw/clean-sequencer-state-upon-final-commit'
authorJunio C Hamano <gitster@pobox.com>
Mon, 13 May 2019 14:50:35 +0000 (23:50 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 May 2019 14:50:35 +0000 (23:50 +0900)
"git chery-pick" (and "revert" that shares the same runtime engine)
that deals with multiple commits got confused when the final step
gets stopped with a conflict and the user concluded the sequence
with "git commit".  Attempt to fix it by cleaning up the state
files used by these commands in such a situation.

* pw/clean-sequencer-state-upon-final-commit:
  fix cherry-pick/revert status after commit
  commit/reset: try to clean up sequencer state

1  2 
builtin/commit.c
sequencer.c
sequencer.h
t/t3507-cherry-pick-conflict.sh
wt-status.c

Simple merge
diff --cc sequencer.c
@@@ -2168,8 -2142,43 +2168,43 @@@ static int parse_insn_line(struct repos
        return !item->commit;
  }
  
 -      if (parse_insn_line(r, &item, buf.buf, eol))
+ int sequencer_get_last_command(struct repository *r, enum replay_action *action)
+ {
+       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 */
 -static int parse_insn_buffer(struct repository *r, char *buf,
 -                           struct todo_list *todo_list)
++      if (parse_insn_line(r, &item, buf.buf, 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;
+       ret = 0;
+  fail:
+       strbuf_release(&buf);
+       return ret;
+ }
 +int todo_list_parse_insn_buffer(struct repository *r, char *buf,
 +                              struct todo_list *todo_list)
  {
        struct todo_item *item;
        char *p = buf, *next_p;
diff --cc sequencer.h
@@@ -199,4 -143,7 +199,7 @@@ int read_author_script(const char *path
  
  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);
 +                    struct commit *onto, const char *orig_head);
+ void sequencer_post_commit_cleanup(struct repository *r);
+ int sequencer_get_last_command(struct repository* r,
+                              enum replay_action *action);
Simple merge
diff --cc wt-status.c
Simple merge