diff options
Diffstat (limited to 'resources/com/google/gerrit/server/tools/root/hooks/commit-msg')
-rwxr-xr-x | resources/com/google/gerrit/server/tools/root/hooks/commit-msg | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/resources/com/google/gerrit/server/tools/root/hooks/commit-msg b/resources/com/google/gerrit/server/tools/root/hooks/commit-msg index 3f4cd7aa6e..e9ff5977e3 100755 --- a/resources/com/google/gerrit/server/tools/root/hooks/commit-msg +++ b/resources/com/google/gerrit/server/tools/root/hooks/commit-msg @@ -27,11 +27,6 @@ if test ! -f "$1" ; then exit 1 fi -if test ! -s "$1" ; then - echo "file is empty: $1" - exit 1 -fi - # Do not create a change id if requested if test "false" = "`git config --bool --get gerrit.createChangeId`" ; then exit 0 @@ -41,8 +36,32 @@ fi random=$( (whoami ; hostname ; date; cat $1 ; echo $RANDOM) | git hash-object --stdin) dest="$1.tmp.${random}" +trap 'rm -f "${dest}"' EXIT + +if ! git stripspace --strip-comments < "$1" > "${dest}" ; then + echo "cannot strip comments from $1" + exit 1 +fi + +if test ! -s "${dest}" ; then + echo "file is empty: $1" + exit 1 +fi + +if ! mv "${dest}" "$1" ; then + echo "cannot mv ${dest} to $1" + exit 1 +fi + # Avoid the --in-place option which only appeared in Git 2.8 # Avoid the --if-exists option which only appeared in Git 2.15 -cat "$1" \ - | git -c trailer.ifexists=doNothing interpret-trailers --trailer "Change-Id: I${random}" > "${dest}" \ - && mv "${dest}" "$1" +if ! git -c trailer.ifexists=doNothing interpret-trailers \ + --trailer "Change-Id: I${random}" < "$1" > "${dest}" ; then + echo "cannot insert change-id line in $1" + exit 1 +fi + +if ! mv "${dest}" "$1" ; then + echo "cannot mv ${dest} to $1" + exit 1 +fi |