summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-02-09 17:52:43 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2018-02-09 17:53:51 -0500
commit4bd8ed3045197132ae8a3eef5303757dbecb8514 (patch)
tree64d8a634485c4e2a76801254fd51590a97756d69
parentfe95d9386908cd2b199778db38eefdce1d054020 (diff)
parent87ce1bc0de3bf1368f3160e0ca28bd282384e109 (diff)
make: post-commit: backport safety (+worktree!) things from andrewdm.me
This does not change the pre-generate logic to match Andrew's, just the worktree setup bits.
-rwxr-xr-xpost-commit35
1 files changed, 20 insertions, 15 deletions
diff --git a/post-commit b/post-commit
index d3a81ba..b8f816a 100755
--- a/post-commit
+++ b/post-commit
@@ -1,24 +1,29 @@
#!/usr/bin/env bash
+# Copyright 2016-2017 Luke Shumaker
+set -e
branch=$(git name-rev --name-only HEAD)
if [[ $branch == master ]]; then
+ gitdir="$(git rev-parse --git-dir)"
+ workdir="${gitdir}/pre-generated"
+ exec 8>"${workdir}.lock"
+ flock 8
- stash=false
- if [[ -n "$(git status --porcelain)" ]]; then
- stash=true
- git add .
- git stash
- fi
+ rm -rf -- "$workdir"
+ git worktree prune
- git checkout pre-generated
- git merge master -m 'bogus'
- make --always-make -j12
- git add .
- git commit --amend -m "make: $(git log -n1 master --pretty=format:%B)"
- git checkout master
+ unset GIT_INDEX_FILE
+ git worktree add "${gitdir}/pre-generated" pre-generated
+ (
+ unset GIT_DIR GIT_WORK_TREE
+ cd "$workdir"
- if $stash; then
- git stash pop
- fi
+ git merge master -m 'bogus'
+ make --always-make -j12
+ git add .
+ git commit --amend -m "make: $(git log -n1 master --pretty=format:%B)"
+ )
+ rm -rf -- "$workdir"
+ git worktree prune
fi