{"thread":{"id":"40820","subject":"[BUG] pre-applypatch can no longer add to staging area","startedAt":"2015-11-18T02:15:41Z","lastAt":"2015-11-18T02:15:41Z","messageCount":1,"participants":["Chris Packham"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"273462","messageId":"CAFOYHZB_2EfFkO0_PtQXYmh9wbUcZPEtEFDiE-mzotgmm+3TCQ@mail.gmail.com","threadId":"40820","inReplyTo":null,"subject":"[BUG] pre-applypatch can no longer add to staging area","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2015-11-18T02:15:41Z","receivedAt":"2015-11-18T02:15:41Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"Hi,\n\nAt $dayjob we've been using a pre-applypatch hook to keep an eye on\nsome software metrics as sub-area maintainers receive changes from\ndevelopers. When a particular metric goes up we inform the maintainer\nthat they should reject the patch and stop 'git am' from continuing.\nWhen the metric goes down automatically update the stored metric count\nand include that change in the commit. Prior to git 2.6.3 this was\nworking, its probably prior to 2.6.0 the last version I know worked\nwas 2.5.3\n\nConsider the following pre-applypatch hook to stop people adding more\nuses of strcpy() to an existing code base.\n\n  #/bin/sh\n  current=$(cat .count)\n  new=$(git grep -c strcpy)\n  if test \"$new\" -gt \"$current\"; then\n    echo \"Bad patch\"\n    exit 1\n  fi\n\n  if  test \"$new\" -lt \"$current\"; then\n     echo \"Awesome patch\"\n     echo \"$new\" >.count\n     git add .count\n  fi\n\n  exit 0\n\nWhen a maintainer runs 'git am patch.patch' the hook would run and\nrecord the new metric value in the staging area before the commit is\ncreated.\n\nBased on my reading of the pre-applypatch documentation I think this\nis a valid use-case. The hook is invoked with the changes applied but\nbefore they are committed so it should be OK to add additional changes\nto the staging area as part of the hook. Interestingly with the newer\ngit version the change is not even staged.\n\nThanks,\nChris\n"}]}