-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathvalidate-gitignore.sh
More file actions
executable file
·63 lines (56 loc) · 951 Bytes
/
validate-gitignore.sh
File metadata and controls
executable file
·63 lines (56 loc) · 951 Bytes
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
#!/bin/sh
# This script can be used to identify unnecessary entries in the .gitignore
# file.
#
# Three modes are available:
#
# --validate
# prints out unnecessary entries
# --clean
# prints out the contents of .gitignore, skipping unnecessary entries
# --fix
# overwrites .gitignore with the output of --clean
die () {
echo "$*" >&2
exit 1
}
while test $# -gt 0
do
case "$1" in
--fix|--validate|--clean) mode=${1#--};;
*) die "Unknown command: $1";;
esac
shift
done
test -f .gitignore ||
die "No .gitignore file?"
handle_line () {
case "$1" in
''|\#*)
printf '%s\n' "$1"
continue
;;
/*)
if eval ls -d ."$1" > /dev/null 2>&1
then
printf "%s\n" "$1"
elif test "validate" = "$mode"
then
echo "Unnecessary: $1" 1>&2
fi
;;
esac
}
cleaned="$(cat .gitignore |
while read line
do
handle_line "$line"
done)"
case "$mode" in
fix)
printf "%s" "$cleaned" > .gitignore
;;
clean)
printf "%s" "$cleaned"
;;
esac