[GUILT 4/6] Run regression tests in a directory which contains spaces
[guilt.git] / guilt-status
blobc701fd1ac1fc494988de53d8552b5c6c329a49f7
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006-2011
6 USAGE="[-a|-A] [-c|-C] [-d|-D] [-m|-M] [-r|-R] [-t|-T] [-u|-U] [-x|-X] [-n]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename $0` directly is no longer supported." >&2
9 exit 1
12 print_status()
14 if [ -z "$no_prefix" ] ; then
15 Apfx="A "
16 Cpfx="C "
17 Dpfx="D "
18 Mpfx="M "
19 Rpfx="R "
20 Tpfx="T "
21 Upfx="U "
22 Xpfx="? "
25 while read status name newname
27 case "$status" in
28 A*) disp "$Apfx$name";;
29 C*) disp "$Cpfx$name -> $newname";;
30 D*) disp "$Dpfx$name";;
31 M ) disp "$Mpfx$name";;
32 R*) disp "$Rpfx$name -> $newname";;
33 T ) disp "$Tpfx$name";;
34 U ) disp "$Upfx$name";;
35 ? ) disp "$Xpfx$name";;
36 esac
37 done
40 _main() {
42 untracked=""
43 DIFF_FILTER=""
44 while [ $# -gt 0 ]; do
45 case "$1" in
46 -a|-A)
47 DIFF_FILTER="A$DIFF_FILTER"
49 -c|-C)
50 DIFF_FILTER="C$DIFF_FILTER"
52 -d|-D)
53 DIFF_FILTER="D$DIFF_FILTER"
55 -m|-M)
56 DIFF_FILTER="M$DIFF_FILTER"
58 -r|-R)
59 DIFF_FILTER="R$DIFF_FILTER"
61 -t|-T)
62 DIFF_FILTER="T$DIFF_FILTER"
64 -u|-U)
65 DIFF_FILTER="U$DIFF_FILTER"
67 -x|-X)
68 untracked="t"
69 DIFF_FILTER="X$DIFF_FILTER"
71 -n)
72 no_prefix="t"
75 usage
77 esac
78 shift
79 done
81 # default status displays all
82 if [ -z "$DIFF_FILTER" ]; then
83 untracked="t"
84 DIFF_FILTER="ACDMRT"
87 git rev-parse --verify HEAD >/dev/null 2>&1 || IS_INITIAL=t
90 cd_to_toplevel
91 # untracked; FIXME: there's got to be a better way
92 if [ ! -z "$untracked" ]; then
93 if [ -f "$GIT_DIR/info/exclude" ]; then
94 git ls-files -z --others \
95 --exclude-from="$GIT_DIR/info/exclude" \
96 --exclude-per-directory=.gitignore
97 else
98 git ls-files -z --others --exclude-per-directory=.gitignore
99 fi | xargs -0 -L 1 echo | while read n; do
100 [ -z "$n" ] && continue
101 echo "$n" | sed -e "s/^/?\t/"
102 done
105 # added
106 if [ -z "$IS_INITIAL" ]; then
107 # non-initial commit
108 git diff-index -M --name-status --diff-filter=$DIFF_FILTER HEAD
109 else
110 # initial commit
111 git ls-files | sed -e "s/^/A\t/"
112 fi | sed -e '
113 s/\\/\\\\/g
114 s/ /\\ /g
116 ) | print_status