]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
contrib: Make prepare-commit-msg hook safe for older branches
authorJonathan Wakely <jwakely@redhat.com>
Tue, 2 Jun 2020 10:18:21 +0000 (11:18 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 2 Jun 2020 10:18:21 +0000 (11:18 +0100)
If a user installs this script as .git/hooks/prepare-commit-msg and then
works on an old branch which doesn't have the mklog.py script, trying to
commit will fail with an error like:

environment: /.../gcc/contrib/mklog.py: No such file or directory

This makes it exit cleanly so it's possible to commit.

contrib/ChangeLog:

* prepare-commit-msg: Do nothing if the mklog.py script isn't
present.

contrib/prepare-commit-msg

index fd59bfbcf8837335cf5b095f2cfb267e1c7e9a17..24f0783aae24e59b7954dac3693ae598a3180db7 100755 (executable)
@@ -23,6 +23,9 @@ COMMIT_MSG_FILE=$1
 COMMIT_SOURCE=$2
 SHA1=$3
 
+# We might be on a branch before the file was added.
+if ! [ -x contrib/mklog.py ]; then exit 0; fi
+
 # Can't do anything if $COMMIT_MSG_FILE isn't a file.
 if ! [ -f "$COMMIT_MSG_FILE" ]; then exit 0; fi