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>
This commit is contained in:

committed by
Junio C Hamano

parent
161807349a
commit
fad2652673
@ -408,8 +408,6 @@ static int do_pick_commit(void)
|
|||||||
discard_cache();
|
discard_cache();
|
||||||
|
|
||||||
if (!commit->parents) {
|
if (!commit->parents) {
|
||||||
if (action == REVERT)
|
|
||||||
die (_("Cannot revert a root commit"));
|
|
||||||
parent = NULL;
|
parent = NULL;
|
||||||
}
|
}
|
||||||
else if (commit->parents->next) {
|
else if (commit->parents->next) {
|
||||||
@ -467,7 +465,7 @@ static int do_pick_commit(void)
|
|||||||
strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
|
strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
|
||||||
strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
|
strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
|
||||||
|
|
||||||
if (commit->parents->next) {
|
if (commit->parents && commit->parents->next) {
|
||||||
strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
|
strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
|
||||||
strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
|
strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user