Last active
September 19, 2016 21:59
-
-
Save henryr/e89f9724eb85a6d5ea48ff0027f36793 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# If this is an amend, not a new commit, need to take diff against HEAD~1, not HEAD, to do | |
# formatting. | |
RELATIVE_COMMIT="HEAD" | |
GIT_CMD="$(ps -ocommand= -p $PPID)" | |
if [[ ${GIT_CMD} == *"--amend"* ]] | |
then | |
RELATIVE_COMMIT="HEAD~1" | |
fi | |
echo "Formatting against ${RELATIVE_COMMIT}" | |
# We need to ignore unstaged changes by stashing them, except for commit -a which will | |
# stage all changes after this script exits. | |
if [[ ${GIT_CMD} != *" -a"* ]] | |
then | |
echo "Changes for commit are only in index" | |
git stash -k | |
fi | |
${IMPALA_TOOLCHAIN}/llvm-${IMPALA_LLVM_VERSION}/bin/git-clang-format ${RELATIVE_COMMIT} \ | |
--binary=${IMPALA_TOOLCHAIN}/llvm-${IMPALA_LLVM_VERSION}/bin/clang-format | |
git add -u | |
if [[ ${GIT_CMD} != *" -a"* ]] | |
then | |
echo "Restoring unstaged changes" | |
git stash pop | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment