author | Junio C Hamano <gitster@pobox.com> | |
Fri, 20 May 2011 03:37:19 +0000 (20:37 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 20 May 2011 03:37:19 +0000 (20:37 -0700) |
* jk/cherry-pick-root-with-resolve:
t3503: test cherry picking and reverting root commits
revert: allow reverting a root commit
cherry-pick: handle root commits with external strategies
t3503: test cherry picking and reverting root commits
revert: allow reverting a root commit
cherry-pick: handle root commits with external strategies
builtin/merge.c | patch | blob | history | |
builtin/revert.c | patch | blob | history | |
t/t3503-cherry-pick-root.sh | patch | blob | history |
diff --git a/builtin/merge.c b/builtin/merge.c
index 7eebb71491047b2df6231df500e5fc28db1881b4..5a2a1eb797c88990337f0b9cbb5dcabc73222a22 100644 (file)
--- a/builtin/merge.c
+++ b/builtin/merge.c
die(_("git write-tree failed to write a tree"));
}
+static const char *merge_argument(struct commit *commit)
+{
+ if (commit)
+ return sha1_to_hex(commit->object.sha1);
+ else
+ return EMPTY_TREE_SHA1_HEX;
+}
+
int try_merge_command(const char *strategy, size_t xopts_nr,
const char **xopts, struct commit_list *common,
const char *head_arg, struct commit_list *remotes)
args[i++] = s;
}
for (j = common; j; j = j->next)
- args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
+ args[i++] = xstrdup(merge_argument(j->item));
args[i++] = "--";
args[i++] = head_arg;
for (j = remotes; j; j = j->next)
- args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
+ args[i++] = xstrdup(merge_argument(j->item));
args[i] = NULL;
ret = run_command_v_opt(args, RUN_GIT_CMD);
strbuf_release(&buf);
diff --git a/builtin/revert.c b/builtin/revert.c
index f697e6695374d06e7b08c9faac1ebaefe4ff31d7..1f27c63343904a969e60ab19408495007f59d133 100644 (file)
--- a/builtin/revert.c
+++ b/builtin/revert.c
discard_cache();
if (!commit->parents) {
- if (action == REVERT)
- die (_("Cannot revert a root commit"));
parent = NULL;
}
else if (commit->parents->next) {
strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
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, sha1_to_hex(parent->object.sha1));
}
index b0faa299183df5fe06ccaf383bce47cbb9a0cf89..9aefe3a1becac200f2c29beee84fab278f9fcfa0 100755 (executable)
#!/bin/sh
-test_description='test cherry-picking a root commit'
+test_description='test cherry-picking (and reverting) a root commit'
. ./test-lib.sh
test_expect_success 'cherry-pick a root commit' '
git cherry-pick master &&
- test first = $(cat file1)
+ echo first >expect &&
+ test_cmp expect file1
+
+'
+
+test_expect_success 'revert a root commit' '
+
+ git revert master &&
+ test_path_is_missing file1
+
+'
+
+test_expect_success 'cherry-pick a root commit with an external strategy' '
+
+ git cherry-pick --strategy=resolve master &&
+ echo first >expect &&
+ test_cmp expect file1
+
+'
+
+test_expect_success 'revert a root commit with an external strategy' '
+
+ git revert --strategy=resolve master &&
+ test_path_is_missing file1
'