Last active
October 21, 2015 15:59
-
-
Save jwliechty/68b7b0efa01a184ac73b to your computer and use it in GitHub Desktop.
Bash Library for Git Operations
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
# 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