File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ # This script can be used to identify unnecessary entries in the .gitignore
4+ # file.
5+ #
6+ # Three modes are available:
7+ #
8+ # --validate
9+ # prints out unnecessary entries
10+ # --clean
11+ # prints out the contents of .gitignore, skipping unnecessary entries
12+ # --fix
13+ # overwrites .gitignore with the output of --clean
14+
15+ die () {
16+ echo " $* " >&2
17+ exit 1
18+ }
19+
20+ while test $# -gt 0
21+ do
22+ case " $1 " in
23+ --fix|--validate|--clean) mode=${1# --} ;;
24+ * ) die " Unknown command: $1 " ;;
25+ esac
26+ shift
27+ done
28+
29+ test -f .gitignore ||
30+ die " No .gitignore file?"
31+
32+ handle_line () {
33+ case " $1 " in
34+ ' ' |\# * )
35+ printf ' %s\n' " $1 "
36+ continue
37+ ;;
38+ /* )
39+ if eval ls -d ." $1 " > /dev/null 2>&1
40+ then
41+ printf " %s\n" " $1 "
42+ elif test " validate" = " $mode "
43+ then
44+ echo " Unnecessary: $1 " 1>&2
45+ fi
46+ ;;
47+ esac
48+ }
49+
50+ cleaned=" $( cat .gitignore |
51+ while read line
52+ do
53+ handle_line " $line "
54+ done)"
55+
56+ case " $mode " in
57+ fix)
58+ printf " %s" " $cleaned " > .gitignore
59+ ;;
60+ clean)
61+ printf " %s" " $cleaned "
62+ ;;
63+ esac
You can’t perform that action at this time.
0 commit comments