Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx> --- builtin/revert.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 47 insertions(+), 4 deletions(-) diff --git a/builtin/revert.c b/builtin/revert.c index 0720721..c050d4f 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -743,6 +743,51 @@ static int pick_commits(void) return persist_todo_done(res, revs.commits, done_list); } +static int process_args(int argc, const char **argv) +{ + const char *me; + int fd; + + parse_args(argc, argv); + me = (cmd_opts.action == REVERT ? "revert" : "cherry-pick"); + if (cmd_opts.abort_oper) { + const char *args[3] = {NULL, NULL, NULL}; + char head[DEFAULT_ABBREV]; + + args[0] = "rerere"; + args[1] = "clear"; + cmd_rerere(2, args, NULL); + + if (!file_exists(HEAD_FILE)) + goto error; + + if ((fd = open(HEAD_FILE, O_RDONLY, 0666)) < 0) + return error_errno(_("Could not open '%s' for reading"), HEAD_FILE); + if (xread(fd, head, DEFAULT_ABBREV) < DEFAULT_ABBREV) + return error_errno(_("Corrupt '%s'"), HEAD_FILE); + close(fd); + + args[0] = "reset"; + args[1] = "--hard"; + args[2] = head; + return cmd_reset(3, args, NULL); + } + else if (cmd_opts.skip_oper) { + if (!file_exists(TODO_FILE)) + goto error; + return 0; + } + else if (cmd_opts.continue_oper) { + if (!file_exists(TODO_FILE)) + goto error; + return 0; + } + + return pick_commits(); +error: + return error(_("No %s in progress"), me); +} + int cmd_revert(int argc, const char **argv, const char *prefix) { if (isatty(0)) @@ -752,9 +797,8 @@ int cmd_revert(int argc, const char **argv, const char *prefix) memset(&cmd_opts, 0, sizeof(cmd_opts)); cmd_opts.action = REVERT; setenv(GIT_REFLOG_ACTION, "revert", 0); - parse_args(argc, argv); - return pick_commits(); + return process_args(argc, argv); } int cmd_cherry_pick(int argc, const char **argv, const char *prefix) @@ -763,7 +807,6 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix) memset(&cmd_opts, 0, sizeof(cmd_opts)); cmd_opts.action = CHERRY_PICK; setenv(GIT_REFLOG_ACTION, "cherry-pick", 0); - parse_args(argc, argv); - return pick_commits(); + return process_args(argc, argv); } -- 1.7.4.rc1.7.g2cf08.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html