git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] commit: inform pre-commit if --amend is used

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Nov 24, 2014, 23:14 UTC
Message-ID
<CAPig+cQ=Ea2K0AJRu62q1w2tGmN1kgZ15oc3kHisSo3gpuU6=Q@mail.gmail.com>
In-Reply-To
<1416828111-4567-1-git-send-email-oystwa@gmail.com>
On Mon, Nov 24, 2014 at 6:21 AM, Øystein Walle <oystwa@gmail.com> wrote:
Show 30 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 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 <oystwa@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.
Show 7 quoted lines
> +
> +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
Previous: Øystein WalleNext: Jeff King
Message 2 of 9 in “commit: inform pre-commit if --amend is used”
  1. commit: inform pre-commit if --amend is usedØystein Walle, Nov 24, 2014
  2. Eric SunshineNov 24, 2014
  3. Jeff KingNov 25, 2014
  4. Junio C HamanoNov 25, 2014
  5. Jeff KingNov 25, 2014
  6. Mark LevedahlNov 27, 2014
  7. Jeff KingNov 28, 2014
  8. Mark LevedahlNov 28, 2014
  9. Junio C HamanoDec 1, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.