Skip to content

Commit

Permalink
Add flags to git-is-clean/git-is-dirty.
Browse files Browse the repository at this point in the history
-w    Check if worktree is clean/dirty
-i    Check if index is clean/dirty
  • Loading branch information
nvie committed Sep 2, 2013
1 parent 06ef17c commit a2687ee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
13 changes: 1 addition & 12 deletions git-has-local-changes
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
#!/bin/sh
set -e

# Unstaged local changes?
if ! git diff --no-ext-diff --ignore-submodules --quiet --exit-code; then
exit 1
else
# Staged local changes?
if ! git diff-index --cached --quiet --ignore-submodules --exit-code HEAD --; then
exit 2
else
exit 0
fi
fi
git is-clean
39 changes: 38 additions & 1 deletion git-is-clean
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
#!/bin/sh
set -e
git has-local-changes

is_index_clean () {
git diff-index --cached --quiet --ignore-submodules --exit-code HEAD --
}

is_worktree_clean () {
git diff --no-ext-diff --ignore-submodules --quiet --exit-code
}

check_index=0
check_worktree=0
while getopts iw flag; do
case "$flag" in
i) check_index=1;;
w) check_worktree=1;;
esac
done
shift $(($OPTIND - 1))

# If nothing is explicitly specified, check everything
if [ $check_index -eq 0 -a $check_worktree -eq 0 ]; then
check_index=1
check_worktree=1
fi

if [ $check_index -eq 1 ]; then
if ! is_index_clean; then
exit 1
fi
fi

if [ $check_worktree -eq 1 ]; then
if ! is_worktree_clean; then
exit 1
fi
fi

exit 0
6 changes: 1 addition & 5 deletions git-is-dirty
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#!/bin/sh
set -e
if git has-local-changes; then
exit 1
else
exit 0
fi
! git is-clean "$@"

0 comments on commit a2687ee

Please sign in to comment.