revert: allow reverting a root commit

Although it is probably an uncommon operation, there is no reason to disallow it, as it works just fine. It is the reverse of a cherry-pick of a root commit, which is already allowed. We do have to tweak one check on whether we have a merge commit, which assumed we had at least one parent. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 12, 2011 at 07:09 UTC fad2652673247203014e2c57622a5ffe0eb5ad93
1 file changed +1 -3
builtin/revert.c
+1 -3
@@ -408,8 +408,6 @@ static int do_pick_commit(void)
408 discard_cache();
409
410 if (!commit->parents) {
411 - if (action == REVERT)
412 - die (_("Cannot revert a root commit"));
411 parent = NULL;
412 }
413 else if (commit->parents->next) {
@@ -467,7 +465,7 @@ static int do_pick_commit(void)
465 strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
466 strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
467
470 - if (commit->parents->next) {
468 + if (commit->parents && commit->parents->next) {
469 strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
470 strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
471 }