summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2011-05-19 20:37:19 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2011-05-19 20:37:19 -0700
commit6699c959efccc7cb969b87bdf8e0154a0fe9ccc8 (patch)
tree96b536942f08c30e8d5f9f7dc6ec950ddd67f0e3 /builtin
parentMerge branch 'jc/maint-pathspec-stdin-and-cmdline' (diff)
parentt3503: test cherry picking and reverting root commits (diff)
downloadtgif-6699c959efccc7cb969b87bdf8e0154a0fe9ccc8.tar.xz
Merge branch 'jk/cherry-pick-root-with-resolve'
* 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
Diffstat (limited to 'builtin')
-rw-r--r--builtin/merge.c12
-rw-r--r--builtin/revert.c4
2 files changed, 11 insertions, 5 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index 7eebb71491..5a2a1eb797 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -608,6 +608,14 @@ static void write_tree_trivial(unsigned char *sha1)
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)
@@ -628,11 +636,11 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
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 f697e66953..1f27c63343 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -408,8 +408,6 @@ static int do_pick_commit(void)
discard_cache();
if (!commit->parents) {
- if (action == REVERT)
- die (_("Cannot revert a root commit"));
parent = NULL;
}
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, 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));
}