Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 141 lines (130 sloc) 3.16 KB
#!/bin/bash -e
## check for modified content and uncommitted changes
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Check for cleanliness of repository
This command can be used to check for modified content,
uncommitted changes and many other things.
Usage:
git check-clean [--exit-code] [--unstaged] [--uncommitted]
[--untracked] [--unmerged] [--ignore-submodules[=<when>]]
--exit-code: return an exit code instead of a message
--unstaged: check for unstaged files
--uncommitted: check for staged but uncommitted files
--untracked: check for untracked files
--unmerged: check for unmerged files
--ignore-submodules: ignore submodules, optionally specifying
in when to ignore submodules (see help of git-status),
defaults to "all".
--warn: do not issue an error, but just a warning.
EOF
exit 0;
elif [[ "$@" == "" || "$@" == "--warn" ]]; then
unstaged=1
uncommitted=1
untracked=1
unmerged=1
if [[ "$@" == "--warn" ]]; then
warn=1
fi
else
while test $# -ne 0
do
case "$1" in
--exit-code)
exitcode=1
;;
--unstaged)
unstaged=1
;;
--uncommitted)
uncommitted=1
;;
--untracked)
untracked=1
;;
--unmerged)
unmerged=1
;;
--ignore-submodules)
ignoresub="all"
;;
--ignore-submodules=*)
ignoresub="${1#--ignore-submodules=}"
;;
--warn)
warn=1
;;
*)
break
;;
esac
shift
done
fi
if [[ "$ignoresub" ]]; then
status=`git status --porcelain --ignore-submodules=$ignoresub`
else
status=`git status --porcelain`
fi
if [[ $unstaged -eq 1 ]]; then
if echo "$status" | grep -E '^[ MARC][MD]' -q; then
if [[ $exitcode -eq 1 ]]; then
exit 1;
else
if [[ "$ignoresub" ]] || git status --porcelain --ignore-submodules | grep -E '^[ MARC][MD]' -q; then
output=" There are unstaged changes. Use \"git add <file>\" to add.
"
fi
sub=`git ls-files --error-unmatch --stage | grep -E '^160000' | sed -e 's/^.* //' | tr '\n' ' '`
if [[ ! "$ignoresub" && "$sub" ]]; then
if git status --porcelain -- $sub | grep -E '^[ MARC][MD]' -q; then
output="$output There is modified content in submodules.
"
fi
fi
fi
fi
fi
if [[ $unmerged -eq 1 ]]; then
if echo "$status" | grep -E '^(DD|AU|UD|UA|DU|AU|UU)' -q; then
if [[ $exitcode -eq 1 ]]; then
exit 1;
else
output="$output There are unmerged files. Use \"git add <file>\" when merged.
"
fi
fi
fi
if [[ $uncommitted -eq 1 ]]; then
if echo "$status" | grep -E '^[MADRC]' -q; then
if [[ $exitcode -eq 1 ]]; then
exit 1;
else
output="$output There are uncommitted files. Use \"git rcommit\" or \"git commit\" to commit.
"
fi
fi
fi
if [[ $untracked -eq 1 ]]; then
if echo "$status" | grep -E '^\?\?' -q; then
if [[ $exitcode -eq 1 ]]; then
exit 1;
else
output="$output There are untracked files not in .gitignore. Try \"make clean\" to remove temporary files.
"
fi
fi
fi
if [[ "$output" ]]; then
if [[ "$warn" ]]; then
echo >&2 -n "Warning in $PWD:
$output"
exit 0
else
echo >&2 -n "Error in $PWD:
$output"
exit 1
fi
fi