-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathgit-ignored
executable file
·277 lines (220 loc) · 5.63 KB
/
git-ignored
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env bash
set -u
############################################################
# Adjust for each check
############################################################
# Name and messages
MY_NAME="git-ignored"
MY_DESC="Scans your git repository for ignored files still present in git cache."
MY_FINISH_OK="No ignored files within git cache."
MY_FINISH_ERR="Found ignored files in git cache."
# Custom required binaries
REQUIRED_CUST_BINS="git"
# How to check for files
# Note: '%' comes from xargs and represents
# one file as parameter.
# Called like this:
# eval "xargs -I % sh '${MY_CHECK}'"
MY_CHECK="git ls-files --ignored --exclude-standard 2>&1 || true"
# Command to be displayed for --info
MY_INFO="git --version"
############################################################
# Do not edit from here
############################################################
#
# Version
#
MY_VERSION="0.15"
MY_DATE="2018-04-09"
#
# Credits
#
MY_AUTHOR="cytopia"
MY_EMAIL="[email protected]"
#
# Required system binaries
#
REQUIRED_BINS="sed"
#
# Variables populated by cmd args or config file
#
MY_PATH=
MY_DRY=0
MY_LST=0
MY_DEB=0
CLR_SUC="\033[0;32m"
CLR_ERR="\033[0;31m"
CLR_CLS="\033[0m"
################################################################################
#
# F U N C T I O N S
#
################################################################################
print_usage() {
echo "Usage: ${MY_NAME} [--debug] [--dry] [--list] --path=dir"
echo " ${MY_NAME} --info"
echo " ${MY_NAME} --help"
echo " ${MY_NAME} --version"
echo
echo "${MY_DESC}"
echo "Will return 1 on occurance, otherwise 0."
echo
echo "Required arguments:"
echo " --path= Specify directory where to scan."
echo
echo
echo "Optional run arguments:"
echo " --debug Print system messages."
echo
echo
echo "Optional training arguments:"
echo " --dry Don't do anything, just display the commands."
echo
echo " --list Instead of searching inside the files, just display the filenames"
echo " that would be found by --path, --extension and --ignore"
echo
echo "System arguments:"
echo " --info Show command version."
echo " --help Show help screen."
echo " --version Show version information."
echo
echo
echo "${MY_NAME} is part of the awesome-ci collection."
echo "https://github.com/cytopia/awesome-ci"
}
print_version() {
echo "tool: ${MY_NAME}"
echo "version: v${MY_VERSION} (${MY_DATE})"
echo "author: ${MY_AUTHOR}"
echo "email: ${MY_EMAIL}"
echo
echo "${MY_NAME} is part of the awesome-ci collection."
echo "https://github.com/cytopia/awesome-ci"
}
check_requirements() {
_debug="${1}"
_ret1=0
_ret2=0
# System binaries
for _bin in ${REQUIRED_BINS}; do
if ! command -v "${_bin}" >/dev/null 2>&1; then
echo "[ERR] Required sys binary '${_bin}' not found."
_ret1=1
else
if [ "${_debug}" = "1" ]; then
echo "[OK] Required system binary '${_bin}' found."
fi
fi
done
# Specific binaries for this check
for _bin in ${REQUIRED_CUST_BINS}; do
if ! command -v "${_bin}" >/dev/null 2>&1; then
echo "[ERR] Required custom binary '${_bin}' not found."
_ret2=1
else
if [ "${_debug}" = "1" ]; then
echo "[OK] Required custom binary '${_bin}' found."
fi
fi
done
return $((_ret1 + _ret2))
}
################################################################################
#
# M A I N E N T R Y P O I N T
#
################################################################################
############################################################
# Command Line arguments
############################################################
#
# Read command line arguments
#
while [ $# -gt 0 ]; do
case "${1}" in
# ----------------------------------------
--path=*)
MY_PATH="$( echo "${1}" | sed 's/--path=//g' )"
;;
# ----------------------------------------
--dry)
MY_DRY=1
;;
# ----------------------------------------
--list)
MY_LST=1
;;
# ----------------------------------------
--debug)
MY_DEB=1
;;
# ----------------------------------------
--info)
echo "\$ ${MY_INFO}"
eval "${MY_INFO}"
exit 0
;;
# ----------------------------------------
--help)
print_usage
exit 0
;;
# ----------------------------------------
--version)
print_version
exit 0
;;
# ----------------------------------------
*)
echo "Invalid argument: ${1}"
echo "Type '${MY_NAME} --help' for available options."
exit 1
;;
esac
shift
done
############################################################
# Sanity Checks
############################################################
#
# Check general requirements
#
if ! check_requirements "${MY_DEB}"; then
exit 1
fi
#
# Check path
#
if [ "${MY_PATH}" = "" ]; then
echo "--path not specified"
echo "Type '${MY_NAME} --help' for available options."
exit 1
fi
if [ ! -e "${MY_PATH}" ]; then
echo "Specified path does not exist: '${MY_PATH}'."
echo "Type '${MY_NAME} --help' for available options."
exit 1
fi
############################################################
# Execute
############################################################
# Dry mode?
if [ "${MY_DRY}" = "1" ]; then
echo "\$ ${MY_CHECK}"
exit 0
fi
echo "\$ ${MY_CHECK}"
output="$(eval "cd ${MY_PATH} && ${MY_CHECK}")"
# If showing files only, exit normally
if [ "${MY_LST}" = "1" ]; then
echo "${output}"
exit 0
fi
if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi