Signed-off-by: Felipe Contreras <[email protected]>
---
builtin/revert.c | 2 ++
sequencer.c | 33 ++++++++++++++++++++++++++++++++-
sequencer.h | 1 +
t/t3500-cherry.sh | 32 ++++++++++++++++++++++++++++++++
4 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index 0e5ce71..b977124 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -119,6 +119,7 @@ static void parse_args(int argc, const char **argv, struct
replay_opts *opts)
OPT_END(),
OPT_END(),
OPT_END(),
+ OPT_END(),
};
if (opts->action == REPLAY_PICK) {
@@ -129,6 +130,7 @@ static void parse_args(int argc, const char **argv, struct
replay_opts *opts)
OPT_BOOLEAN(0, "allow-empty-message",
&opts->allow_empty_message, N_("allow commits with empty messages")),
OPT_BOOLEAN(0, "keep-redundant-commits",
&opts->keep_redundant_commits, N_("keep redundant, empty commits")),
OPT_BOOLEAN(0, "skip-empty", &opts->skip_empty,
N_("skip empty commits")),
+ OPT_BOOLEAN(0, "copy-notes", &opts->copy_notes,
N_("copy notes")),
OPT_END(),
};
if (parse_options_concat(options, ARRAY_SIZE(options),
cp_extra))
diff --git a/sequencer.c b/sequencer.c
index 3aa480e..cc9c2bc 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -127,6 +127,27 @@ static void add_rewritten(unsigned char *from, unsigned
char *to)
rewritten.nr++;
}
+static void copy_notes(void)
+{
+ unsigned char note_commit[20];
+ struct strbuf buf = STRBUF_INIT;
+ struct notes_tree *t = &default_notes_tree;
+ int i;
+
+ init_notes(t, NULL, NULL, 0);
+
+ for (i = 0; i < rewritten.nr; i++) {
+ struct rewritten_list_item *item = &rewritten.items[i];
+ copy_note(t, item->from, item->to, 0, NULL);
+ }
+
+ strbuf_addstr(&buf, "Notes added by 'git cherry-pick'\n");
+ create_notes_commit(&default_notes_tree, NULL, &buf, note_commit);
+ strbuf_insert(&buf, 0, "notes: ", 7);
+ update_ref(buf.buf, t->ref, note_commit, NULL, 0, MSG_ON_ERR);
+ strbuf_release(&buf);
+}
+
static void run_rewrite_hook(void)
{
struct strbuf buf = STRBUF_INIT;
@@ -908,7 +929,10 @@ static int populate_opts_cb(const char *key, const char
*value, void *data)
else if (!strcmp(key, "options.strategy-option")) {
ALLOC_GROW(opts->xopts, opts->xopts_nr + 1, opts->xopts_alloc);
opts->xopts[opts->xopts_nr++] = xstrdup(value);
- } else
+ }
+ else if (!strcmp(key, "options.copy-notes"))
+ opts->copy_notes = git_config_bool_or_int(key, value,
&error_flag);
+ else
return error(_("Invalid key: %s"), key);
if (!error_flag)
@@ -1108,6 +1132,8 @@ static void save_opts(struct replay_opts *opts)
"options.strategy-option",
opts->xopts[i], "^$",
0);
}
+ if (opts->copy_notes)
+ git_config_set_in_file(opts_file, "options.copy-notes", "true");
}
static int pick_commits(struct commit_list *todo_list, struct replay_opts
*opts)
@@ -1132,6 +1158,9 @@ static int pick_commits(struct commit_list *todo_list,
struct replay_opts *opts)
run_rewrite_hook();
+ if (opts->copy_notes)
+ copy_notes();
+
/*
* Sequence of picks finished successfully; cleanup by
* removing the .git/sequencer directory
@@ -1186,6 +1215,8 @@ static int single_pick(struct commit *cmit, struct
replay_opts *opts)
if (ret)
return ret;
run_rewrite_hook();
+ if (opts->copy_notes)
+ copy_notes();
return 0;
}
diff --git a/sequencer.h b/sequencer.h
index 84b9957..6cc072c 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -36,6 +36,7 @@ struct replay_opts {
int allow_empty_message;
int keep_redundant_commits;
int skip_empty;
+ int copy_notes;
int mainline;
diff --git a/t/t3500-cherry.sh b/t/t3500-cherry.sh
index f038f34..79c1219 100755
--- a/t/t3500-cherry.sh
+++ b/t/t3500-cherry.sh
@@ -55,4 +55,36 @@ test_expect_success \
expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* - .*"
'
+test_expect_success \
+ 'copy notes' \
+ 'git checkout master &&
+ echo notes > C &&
+ test_tick &&
+ git commit -a -m "Update C" &&
+ git notes add -m "a note" &&
+ git checkout -b note-test HEAD^ &&
+ git cherry-pick --copy-notes -x master &&
+ test "a note" = "$(git notes show HEAD)"
+'
+
+test_expect_success \
+ 'copy multiple notes' \
+ 'git checkout master &&
+ echo "multiple notes" > C &&
+ git commit -a -m "Update C again" &&
+ git notes add -m "another note" &&
+ git commit -a -m "Empty" --allow-empty &&
+ echo "more notes" > C &&
+ git commit -a -m "Update C once more" &&
+ git notes add -m "final note" &&
+ git checkout note-test &&
+ git reset --hard master~3 &&
+ test_expect_code 1 git cherry-pick --copy-notes -x HEAD..master &&
+ git reset --hard &&
+ git cherry-pick --continue
+ test "a note" = "$(git notes show HEAD~2)" &&
+ test "another note" = "$(git notes show HEAD~1)" &&
+ test "final note" = "$(git notes show HEAD)"
+'
+
test_done
--
1.8.3.rc3.312.g47657de
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html