Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@henryr
Last active September 19, 2016 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryr/e89f9724eb85a6d5ea48ff0027f36793 to your computer and use it in GitHub Desktop.
Save henryr/e89f9724eb85a6d5ea48ff0027f36793 to your computer and use it in GitHub Desktop.
#!/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