Re: [PATCH 2/2] commit: inform pre-commit that --amend was used
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Nov 26, 2014, 01:36 UTC
- Message-ID
- <CAPig+cQXAbh1d1XcnOfvCn6XNYB2OrzBbxz7zNGFPLA-hQbXhA@mail.gmail.com>
- In-Reply-To
- <b9ef551633329702559e4cee6528b68ab757b531.1416955873.git.oystwa@gmail.com>
On Tue, Nov 25, 2014 at 5:51 PM, Øystein Walle <oystwa@gmail.com> wrote:
Show 34 quoted lines
> When a commit is amended a pre-commit hook that verifies the commit's > contents might not find what it's looking for if it looks at the > differences against HEAD when HEAD~1 might be more appropriate. Inform > the commit hook that --amend is being used so that hook authors can do > e.g. > > if test "$1" = amend; then > ... > else > ... > fi > > to handle these situations. > > Signed-off-by: Øystein Walle <oystwa@gmail.com> > --- > diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh > index 99ed967..b400afe 100755 > --- a/t/t7503-pre-commit-hook.sh > +++ b/t/t7503-pre-commit-hook.sh > @@ -133,4 +133,15 @@ test_expect_success 'check the author in hook' ' > git show -s > ' > > +# a hook that checks if "amend" is passed as an argument > +write_script "$HOOK" <<EOF > +test "\$1" = amend > +EOF > + > +test_expect_success 'check that "amend" argument is given' ' > + git commit --amend --allow-empty > +' > + > +test_must_fail git commit --allow-empty
test_must_fail is a direct replacement for '!' when invoking a git command which should fail _within_ a test. Your original version of this test was in the previous round:
test_expect_success 'check that "amend" argument is NOT given' '
! git commit --allow-empty
'Just replace '!', like this:
test_expect_success 'check that "amend" argument is NOT given' '
test_must_fail git commit --allow-empty
'> + > test_done > -- > 2.2.0.rc3