Skip to content

Commit

Permalink
Update pre commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Aug 26, 2021
1 parent 1b8f0d3 commit 7b559c1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ci/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

# Installing the hook: at root of repo: cd .git/hooks && ln -s ../../ci/pre-commit.sh pre-commit

# stash unstaged changes
git stash -k -u
# First, stash index and work dir, keeping only the
# to-be-committed changes in the working directory.
old_stash=$(git rev-parse -q --verify refs/stash)
git stash push --quiet --keep-index --include-untracked --message "os_pre_commit"
new_stash=$(git rev-parse -q --verify refs/stash)

# Run clang format
./ci/clang-format.sh HEAD develop
# Pop stash
git stash pop
RESULT=$?
[ -f clang_format.patch ] && rm -f clang_format.patch

# Restore changes, only if we stashed something to begin with
if [ "$old_stash" != "$new_stash" ]; then
# stash apply then drop is same as pop
git stash apply --index --quiet && git stash drop --quiet
fi

# If the clang-format script returned non zero, don't allow the commit. The format changes will be in the unstaged queue, ready for approval
exit $RESULT

0 comments on commit 7b559c1

Please # to comment.