aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-08-22 01:09:10 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-08-22 01:09:10 +1200
commit6be02569463c012cda55a7001727912fc4b12900 (patch)
tree7fe80cedd27bdc3aa467efae3ce05d41b37c496b
parent444821e8dfd7f15ef4bff0c80cb5104f213dc972 (diff)
parentcfb840bbb83824a538daadd65a073f52cbd203f5 (diff)
downloaddotfiles-6be02569463c012cda55a7001727912fc4b12900.tar.gz
Merge branch 'release/v7.15.0'v7.15.0
* release/v7.15.0: Rewrite Git pre-commit hook, silence bad error
-rw-r--r--ISSUES.md6
-rw-r--r--VERSION4
-rw-r--r--git/template/hooks/pre-commit.sh22
3 files changed, 17 insertions, 15 deletions
diff --git a/ISSUES.md b/ISSUES.md
index 597d7bd8..103c3a98 100644
--- a/ISSUES.md
+++ b/ISSUES.md
@@ -30,9 +30,3 @@ Known issues
pushed upstream.
* The `_text_filenames` completion handler for Bash won't work on files with
newlines in their names. Can it be made to?
-* First commit to a new repository fails with the Git template hooks because
- the HEAD ref doesn't exist yet:
-
- fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
- Use '--' to separate paths from revisions, like this:
- 'git <command> [<revision>...] -- [<file>...]'
diff --git a/VERSION b/VERSION
index f27bdfb6..33f00879 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-tejr dotfiles v7.14.0
-Sat, 17 Aug 2019 00:31:09 +0000
+tejr dotfiles v7.15.0
+Wed, 21 Aug 2019 13:09:08 +0000
diff --git a/git/template/hooks/pre-commit.sh b/git/template/hooks/pre-commit.sh
index f0e093b3..4d29cb58 100644
--- a/git/template/hooks/pre-commit.sh
+++ b/git/template/hooks/pre-commit.sh
@@ -1,15 +1,23 @@
# Reject a commit directly to a branch named 'master' if a branch named
# 'develop' exists
-# Allow commit if it's not to master
-[ "$(git rev-parse --abbrev-ref HEAD)" = master ] || exit 0
+# Allow commit if no HEAD ref (new repo), master branch, or develop branch
+if ! git show-ref --quiet --verify \
+ HEAD refs/heads/develop refs/heads/master ; then
+ exit 0
+fi
-# Allow commit if there's no develop branch
-git show-ref --quiet --verify refs/heads/develop || exit 0
+# Allow merge commit
+if git show-ref --quiet --verify MERGE_HEAD ; then
+ exit 0
+fi
-# Allow commit if it's a merge. Is there a better way to test this?
-! git rev-parse --quiet --verify MERGE_HEAD >/dev/null || exit 0
+# Allow commit if not on master
+case $(git rev-parse --abbrev-ref --verify HEAD) in
+ master) ;;
+ *) exit 0 ;;
+esac
-# Throw toys
+# Refuse to commit
printf >&2 'Branch develop exists, commits to master blocked\n'
exit 1