graph: Remove graph cache after command terminates
[guilt.git] / guilt-status
blob934ea53a669733e7cf980e6326f6eced6be5b8a0
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE="[-a|-A] [-c|-C] [-d|-D] [-m|-M] [-r|-R] [-t|-T] [-u|-U] [-x|-X] [-n]"
7 . guilt
9 untracked=""
10 DIFF_FILTER=""
11 while [ $# -gt 0 ]; do
12 case "$1" in
13 -a|-A)
14 DIFF_FILTER="A$DIFF_FILTER"
16 -c|-C)
17 DIFF_FILTER="C$DIFF_FILTER"
19 -d|-D)
20 DIFF_FILTER="D$DIFF_FILTER"
22 -m|-M)
23 DIFF_FILTER="M$DIFF_FILTER"
25 -r|-R)
26 DIFF_FILTER="R$DIFF_FILTER"
28 -t|-T)
29 DIFF_FILTER="T$DIFF_FILTER"
31 -u|-U)
32 DIFF_FILTER="U$DIFF_FILTER"
34 -x|-X)
35 untracked="t"
36 DIFF_FILTER="X$DIFF_FILTER"
38 -n)
39 no_prefix="t"
42 usage
44 esac
45 shift
46 done
48 # default status displays all
49 if [ -z "$DIFF_FILTER" ]; then
50 untracked="t"
51 DIFF_FILTER="ACDMRT"
54 git-rev-parse --verify HEAD >/dev/null 2>&1 || IS_INITIAL=t
56 function print_status
58 if [ -z "$no_prefix" ] ; then
59 Apfx="A "
60 Cpfx="C "
61 Dpfx="D "
62 Mpfx="M "
63 Rpfx="R "
64 Tpfx="T "
65 Upfx="U "
66 Xpfx="? "
69 while read status name newname
71 case "$status" in
72 A*) echo "$Apfx$name";;
73 C*) echo "$Cpfx$name -> $newname";;
74 D*) echo "$Dpfx$name";;
75 M ) echo "$Mpfx$name";;
76 R*) echo "$Rpfx$name -> $newname";;
77 T ) echo "$Tpfx$name";;
78 U ) echo "$Upfx$name";;
79 ? ) echo "$Xpfx$name";;
80 esac
81 done
84 cd "$TOP_DIR"
87 # untracked; FIXME: there's got to be a better way
88 if [ ! -z "$untracked" ]; then
89 if [ -f "$GIT_DIR/info/exclude" ]; then
90 git-ls-files -z --others \
91 --exclude-from="$GIT_DIR/info/exclude" \
92 --exclude-per-directory=.gitignore
93 else
94 git-ls-files -z --others --exclude-per-directory=.gitignore
95 fi | xargs -0 -L 1 echo | while read n; do
96 [ -z "$n" ] && continue
97 echo "$n" | sed -e "s/^/?\t/"
98 done
101 # added
102 if [ -z "$IS_INITIAL" ]; then
103 # non-initial commit
104 git-diff-index -M --name-status --diff-filter=$DIFF_FILTER HEAD
105 else
106 # initial commit
107 git-ls-files | sed -e "s/^/A\t/"
108 fi | sed -e '
109 s/\\/\\\\/g
110 s/ /\\ /g
112 ) | print_status
114 cd - 2>&1 >/dev/null