On Mon, Nov 24, 2014 at 6:21 AM, Øystein Walle <oys...@gmail.com> 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 <oys...@gmail.com>
> ---
> 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" <<EOF
> +#!/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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to