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

[BUG] pre-applypatch can no longer add to staging area

From
Chris Packham <judge.packham@gmail.com>
Date
Nov 18, 2015, 02:15 UTC
Message-ID
<CAFOYHZB_2EfFkO0_PtQXYmh9wbUcZPEtEFDiE-mzotgmm+3TCQ@mail.gmail.com>
Hi,

At $dayjob we've been using a pre-applypatch hook to keep an eye on some software metrics as sub-area maintainers receive changes from developers. When a particular metric goes up we inform the maintainer that they should reject the patch and stop 'git am' from continuing. When the metric goes down automatically update the stored metric count and include that change in the commit. Prior to git 2.6.3 this was working, its probably prior to 2.6.0 the last version I know worked was 2.5.3

Consider the following pre-applypatch hook to stop people adding more uses of strcpy() to an existing code base.

  #/bin/sh
  current=$(cat .count)
  new=$(git grep -c strcpy)
  if test "$new" -gt "$current"; then
    echo "Bad patch"
    exit 1
  fi
  if  test "$new" -lt "$current"; then
     echo "Awesome patch"
     echo "$new" >.count
     git add .count
  fi
  exit 0

When a maintainer runs 'git am patch.patch' the hook would run and record the new metric value in the staging area before the commit is created.

Based on my reading of the pre-applypatch documentation I think this is a valid use-case. The hook is invoked with the changes applied but before they are committed so it should be OK to add additional changes to the staging area as part of the hook. Interestingly with the newer git version the change is not even staged.

Thanks, Chris

Message 1 of 1 in “[BUG] pre-applypatch can no longer add to staging area”
  1. Chris PackhamNov 18, 2015

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.