From 405f3d9475c82f802c389020bfb1324791e438fe Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 9 Jun 2013 14:24:34 -0500 Subject: [PATCH] cherry-pick: copy notes and run hooks If no action-name is specified, nothing is done. Signed-off-by: Felipe Contreras --- Documentation/config.txt | 9 ++++----- Documentation/githooks.txt | 8 ++++---- git-rebase--interactive.sh | 4 ++-- sequencer.c | 28 +++++++++++++++++++++++++++- t/t3514-revert-cherry-notes.sh | 18 ++++++++++++++++++ t/t5407-post-rewrite-hook.sh | 16 ++++++++++++++++ 6 files changed, 71 insertions(+), 12 deletions(-) create mode 100755 t/t3514-revert-cherry-notes.sh diff --git a/Documentation/config.txt b/Documentation/config.txt index 2cd6bdd7d2..ed9204e5db 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -2041,11 +2041,10 @@ GIT_NOTES_REF) is also implicitly added to the list of refs to be displayed. notes.rewrite.:: - When rewriting commits with (currently `amend` or - `rebase`) and this variable is set to `true`, Git - automatically copies your notes from the original to the - rewritten commit. Defaults to `true`, but see - "notes.rewriteRef" below. + When rewriting commits with (currently `amend`, `rebase`, or + `cherry-pick`) and this variable is set to `true`, Git automatically + copies your notes from the original to the rewritten commit. Defaults + to `true`, but see "notes.rewriteRef" below. notes.rewriteMode:: When copying notes during a rewrite (see the diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index a2f59b194c..c9d1f592b1 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -382,10 +382,10 @@ post-rewrite ~~~~~~~~~~~~ This hook is invoked by commands that rewrite commits (`git commit ---amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call -it!). Its first argument denotes the command it was invoked by: -currently one of `amend` or `rebase`. Further command-dependent -arguments may be passed in the future. +--amend`, `git rebase`, `git cherry-pick`; currently `git filter-branch` does +'not' call it!). Its first argument denotes the command it was invoked by +(e.g. `rebase`). Further command-dependent arguments may be passed in the +future. The hook receives a list of the rewritten commits on stdin, in the format diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 4cde685b43..979012b5b4 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -269,7 +269,7 @@ pick_one () { test -d "$rewritten" && pick_one_preserving_merges "$@" && return - output eval git cherry-pick \ + output eval git cherry-pick "--action-name ''" \ ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \ "$strategy_args" $empty_args $ff "$@" @@ -389,7 +389,7 @@ pick_one_preserving_merges () { echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list" ;; *) - output eval git cherry-pick \ + output eval git cherry-pick "--action-name ''" \ ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \ "$strategy_args" "$@" || die_with_patch $sha1 "Could not pick $sha1" diff --git a/sequencer.c b/sequencer.c index b0d62181df..ab0a67b2f7 100644 --- a/sequencer.c +++ b/sequencer.c @@ -28,6 +28,25 @@ static GIT_PATH_FUNC(git_path_opts_file, SEQ_OPTS_FILE) static GIT_PATH_FUNC(git_path_seq_dir, SEQ_DIR) static GIT_PATH_FUNC(git_path_head_file, SEQ_HEAD_FILE) +static void finish(struct replay_opts *opts) +{ + const char *name; + struct strbuf msg = STRBUF_INIT; + + if (opts->action != REPLAY_PICK) + return; + + name = opts->action_name ? opts->action_name : "cherry-pick"; + + if (!*name) + return; + + strbuf_addf(&msg, "Notes added by 'git %s'", name); + copy_rewrite_notes(&rewritten, name, msg.buf); + run_rewrite_hook(&rewritten, name); + strbuf_release(&msg); +} + static int is_rfc2822_line(const char *buf, int len) { int i; @@ -1010,6 +1029,8 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts) } } + finish(opts); + /* * Sequence of picks finished successfully; cleanup by * removing the .git/sequencer directory @@ -1083,8 +1104,13 @@ static int sequencer_skip(struct replay_opts *opts) static int single_pick(struct commit *cmit, struct replay_opts *opts) { + int ret; setenv(GIT_REFLOG_ACTION, action_name(opts), 0); - return do_pick_commit(cmit, opts); + ret = do_pick_commit(cmit, opts); + if (ret) + return ret; + finish(opts); + return 0; } int sequencer_pick_revisions(struct replay_opts *opts) diff --git a/t/t3514-revert-cherry-notes.sh b/t/t3514-revert-cherry-notes.sh new file mode 100755 index 0000000000..9e9e611252 --- /dev/null +++ b/t/t3514-revert-cherry-notes.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +test_description='test cherry-pick and revert notes' + +. ./test-lib.sh + +test_expect_success 'notes are rewritten' ' + test_config notes.rewrite.cherry-pick true && + test_config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + git notes add -m "a note" n2 && + git checkout n1 && + git cherry-pick n2 && + git notes show HEAD +' + +test_done diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh index 7a48236e87..6614787da0 100755 --- a/t/t5407-post-rewrite-hook.sh +++ b/t/t5407-post-rewrite-hook.sh @@ -53,6 +53,22 @@ test_expect_success 'git commit --amend --no-post-rewrite' ' test ! -f post-rewrite.data ' +test_expect_success 'git cherry-pick' ' + git reset --hard D && + clear_hook_input && + git checkout A && + test_must_fail git cherry-pick B..D && + echo C > foo && + git add foo && + git cherry-pick --continue && + echo cherry-pick >expected.args && + cat >expected.data <