From: Eric Sunshine Date: Mon, 24 Nov 2014 23:14:34 GMT Subject: Re: [PATCH] commit: inform pre-commit if --amend is used Message-ID: In-Reply-To: <1416828111-4567-1-git-send-email-oystwa@gmail.com> On Mon, Nov 24, 2014 at 6:21 AM, Øystein Walle wrote: > When a commit is amended a pre-commit hook that verifies the commit's > contents might not find what it's looking for if for example 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 > --- > diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh > index 984889b..be97676 100755 > --- a/t/t7503-pre-commit-hook.sh > +++ b/t/t7503-pre-commit-hook.sh > @@ -136,4 +136,18 @@ test_expect_success 'check the author in hook' ' > git show -s > ' > > +# a hook that checks if "amend" is passed as an argument > +cat > "$HOOK" < +#!/bin/sh > +test "\$1" = amend > +EOF write_script would be the modern way to create this hook. > + > +test_expect_success 'check that "amend" argument is given' ' > + git commit --amend --allow-empty > +' > + > +test_expect_success 'check that "amend" argument is NOT given' ' > + ! git commit --allow-empty You probably want test_must_fail rather than '!' [1]. > +' > + > test_done > -- [1]: http://thread.gmane.org/gmane.comp.version-control.git/259871/focus=260092