Skip to content

Instantly share code, notes, and snippets.

@jwliechty
Last active October 21, 2015 15:59
Show Gist options
  • Select an option

  • Save jwliechty/68b7b0efa01a184ac73b to your computer and use it in GitHub Desktop.

Select an option

Save jwliechty/68b7b0efa01a184ac73b to your computer and use it in GitHub Desktop.
Bash Library for Git Operations
#!/bin/bash -e
runTest(){
if hasStagedChanges; then
echo "There are staged changes"
fi
if hasWorkingChanges; then
echo "There are working changes"
fi
if hasUntrackedChanges; then
echo "There are untracked changes"
fi
}
hasStagedChanges(){
! git diff-index --quiet --cached HEAD
}
hasWorkingChanges(){
! git diff-files --quiet
}
hasUntrackedChanges(){
local u=
! ( u="$( git ls-files --exclude-standard --others )" && [ -z "${u}" ] )
}
runTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment