Skip to content

Instantly share code, notes, and snippets.

@jwliechty
Last active October 21, 2015 15:59
Show Gist options
  • Save jwliechty/68b7b0efa01a184ac73b to your computer and use it in GitHub Desktop.
Save jwliechty/68b7b0efa01a184ac73b to your computer and use it in GitHub Desktop.
Bash Library for Git Operations
# Library methods for git operations
# See http://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git
git::run_test(){
if git::has_staged_changes; then
echo "There are staged changes"
fi
if git::has_working_changes; then
echo "There are working changes"
fi
if git::has_untracked_changes; then
echo "There are untracked changes"
fi
if git::has_any_changes; then
echo 'Repo is dirty!'
fi
}
git::has_any_changes(){
git::has_staged_changes \
|| git::has_working_changes \
|| git::has_untracked_changes
}
git::has_staged_changes(){
! git diff-index --quiet --cached HEAD
}
git::has_working_changes(){
# fixes modified but unchanged files from reporting being changed
git status > /dev/null
! git diff-files --quiet
}
git::has_untracked_changes(){
local u=
! ( u="$( git ls-files --exclude-standard --others )" && [ -z "${u}" ] )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment