-
Notifications
You must be signed in to change notification settings - Fork 71
/
git-finddirty
executable file
·49 lines (43 loc) · 1.42 KB
/
git-finddirty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
##############################################################################
# Find any dirty git projects in the current working directory
# and recursively beneath this directory
#
# USAGE:
# finddirtygit
# Quiet mode that outputs only the project that is dirty
# finddirtygit -v
# Verbose mode that outputs what folders are being tested
# finddirtygit -vv
# Very verbose mode that outputs what files are dirty
##############################################################################
# Preserve the old input field separator
OLDIFS=$IFS
# Change the input field separator from a space to a null
IFS=$'\n'
# Find all directories that have a .git directory in them
for gitprojpath in `find . -type d -name .git | sort | sed "s/\/\.git//"`; do
# Save the current working directory before CDing for git's purpose
pushd . >/dev/null
# Switch to the git-enabled project directory
if [ "$1" = "-v" ]; then
echo "TESTING:" $gitprojpath
fi
cd $gitprojpath
# Are there any changed files in the status output?
isdirty=$(git status -s | grep "^.*")
if [ -n "$isdirty" ]; then
# Should output be verbose?
if [ "$1" = "-vv" ]; then
echo "DIRTY:" $gitprojpath
git status -s
# Or should output be quiet?
else
echo "DIRTY:" $gitprojpath
fi
fi
# Return to the starting directory, suppressing the output
popd >/dev/null
done
# restore the input field separator
IFS=$OLDIFS