Skip to content

Instantly share code, notes, and snippets.

@giuliocalzolari
Created June 24, 2015 14:12
Show Gist options
  • Save giuliocalzolari/e87e659ab2c2484705d3 to your computer and use it in GitHub Desktop.
Save giuliocalzolari/e87e659ab2c2484705d3 to your computer and use it in GitHub Desktop.
in case of new commit you can execute multiple action
# checks if branch has something pending
function parse_git_dirty() {
git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*"
}
# gets the current git branch
function parse_git_branch() {
git branch --quiet --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
# get last commit hash prepended with @ (i.e. @8a323d0)
function parse_git_hash() {
git rev-parse HEAD 2> /dev/null | sed "s/\(.*\)/\1/"
}
# DEMO
REMOTE_HASH=$(git ls-remote --heads --quiet | grep $(parse_git_branch) | awk '{print $1}')
LOCAL_HASH=$(parse_git_hash)
if [[ "${REMOTE_HASH}" != "${LOCAL_HASH}" ]];then
echo " local repo hash ${LOCAL_HASH}"
echo "remote repo hash ${REMOTE_HASH}"
echo " -- you need to update your local repo -- "
# git pull
else
echo "nothing to do local and remote repo are equal"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment