Re: [PATCH v2] Introduce CHERRY_PICK_HEAD
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Feb 16, 2011, 21:42 UTC
- Message-ID
- <20110216214236.GC2615@elie>
- In-Reply-To
- <1297876835-70613-1-git-send-email-jaysoffian@gmail.com>
Jay Soffian wrote:
Show 14 quoted lines
> When a cherry-pick conflicts git advises to use: > > $ git commit -c <original commit id> > > to preserve the original commit message and authorship. Instead, let's > record the original commit id in CHERRY_PICK_HEAD and advise to use: > > $ git commit -c CHERRY_PICK_HEAD > > In the next commit, we teach git to handle the '-c CHERRY_PICK_HEAD' > part. Note that we record CHERRY_PICK_HEAD even in the case where there > are no conflicts so that we may use it to communicate authorship to > commit; this will then allow us to remove set_author_ident_env from > revert.c.
This "In the next commit" phrasing is dangerous, since a person can build on top of your first commit at any time. :) I would say:
A later patch will teach "git commit" without -c to use CHERRY_PICK_HEAD to set the authorship automatically. Note that[...]
[...]
Show 10 quoted lines
> +++ b/builtin/revert.c
> @@ -263,6 +279,11 @@ static void print_advice(void)
>
> if (msg) {
> fprintf(stderr, "%s\n", msg);
> + /*
> + * rebase interactive takes care of the authorship
> + * when the user invokes rebase --continue
> + */
> + unlink(git_path("CHERRY_PICK_HEAD"));Nit: GIT_CHERRY_PICK_HELP is not just for rebase --interactive but for arbitrary porcelain that wants to take care of the commit itself (see v1.5.4-rc0~106^2~1, revert/cherry-pick: Allow overriding the help text by the calling Porcelain, 2007-11-28).
The conservative thing to do is indeed to remove CHERRY_PICK_HEAD in this case, I suppose. But I'd like to have the CHERRY_PICK_HEAD to get the --amend safety when rebasing. I can send a separate patch for it if you'd like.
> --- a/t/t3507-cherry-pick-conflict.sh > +++ b/t/t3507-cherry-pick-conflict.sh > @@ -11,6 +11,12 @@ test_description='test cherry-pick and revert with conflicts
[...]
> +test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' '
Some more tests. Yes, they are repetitive. A patch on top to factor out the setup into a function might help, but that feels out of scope here.
With whatever subset of the below looks good, Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Thanks. --- t/t3507-cherry-pick-conflict.sh | 116 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 116 insertions(+), 0 deletions(-)
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index fd569c8..ea52720 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -78,6 +78,122 @@ test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' ' test_cmp_rev picked CHERRY_PICK_HEAD ' +test_expect_success 'successful cherry-pick does not set CHERRY_PICK_HEAD' ' + + git checkout -f initial^0 && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x && + + git update-index --refresh && + git diff-index --exit-code HEAD && + + git cherry-pick base && + + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success 'cherry-pick --no-commit sets CHERRY_PICK_HEAD' ' + + git checkout -f initial^0 && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x && + + git update-index --refresh && + git diff-index --exit-code HEAD && + + git cherry-pick --no-commit base && + + test_cmp_rev base CHERRY_PICK_HEAD +' + +test_expect_success 'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' ' + + git checkout -f initial^0 && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x && + + git update-index --refresh && + git diff-index --exit-code HEAD && + + ( + GIT_CHERRY_PICK_HELP="and then do something else" && + export GIT_CHERRY_PICK_HELP && + test_must_fail git cherry-pick picked + ) && + + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success 'git reset clears CHERRY_PICK_HEAD' ' + + git checkout -f initial^0 && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x && + + git update-index --refresh && + git diff-index --exit-code HEAD && + + test_must_fail git cherry-pick picked && + git reset && + + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success 'failed commit does not clear CHERRY_PICK_HEAD' ' + + git checkout -f initial^0 && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x && + + git update-index --refresh && + git diff-index --exit-code HEAD && + + test_must_fail git cherry-pick picked && + test_must_fail git commit && + + test_cmp_rev picked CHERRY_PICK_HEAD +' + +test_expect_success 'cancelled commit does not clear CHERRY_PICK_HEAD' ' + + git checkout -f initial^0 && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x && + + git update-index --refresh && + git diff-index --exit-code HEAD && + + test_must_fail git cherry-pick picked && + echo resolved >foo && + git add foo && + git update-index --refresh -q && + test_must_fail git diff-index --exit-code HEAD && + ( + GIT_EDITOR=false && + export GIT_EDITOR && + test_must_fail git commit + ) && + + test_cmp_rev picked CHERRY_PICK_HEAD +' + +test_expect_success 'successful commit clears CHERRY_PICK_HEAD' ' + + git checkout -f initial^0 && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x && + + git update-index --refresh && + git diff-index --exit-code HEAD && + + test_must_fail git cherry-pick picked && + echo resolved >foo && + git add foo && + git commit && + + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + test_expect_success 'failed cherry-pick produces dirty index' ' git checkout -f initial^0 &&
-- 1.7.4.1