forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-check-clean
executable file
·147 lines (136 loc) · 3.26 KB
/
git-check-clean
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/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
## from the git mailinglist:
function git
{
LC_MESSAGES=C command git "$@"
}
export git
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