{diff,import-commit,new}: fix handling of binary files
[guilt/mob.git] / guilt-status
blob3236f599d2c7e04a545faea60ea31d3e2ac3df77
1 #!/bin/sh
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 . `dirname $0`/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 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*) disp "$Apfx$name";;
73 C*) disp "$Cpfx$name -> $newname";;
74 D*) disp "$Dpfx$name";;
75 M ) disp "$Mpfx$name";;
76 R*) disp "$Rpfx$name -> $newname";;
77 T ) disp "$Tpfx$name";;
78 U ) disp "$Upfx$name";;
79 ? ) disp "$Xpfx$name";;
80 esac
81 done
85 cd_to_toplevel
86 # untracked; FIXME: there's got to be a better way
87 if [ ! -z "$untracked" ]; then
88 if [ -f "$GIT_DIR/info/exclude" ]; then
89 git ls-files -z --others \
90 --exclude-from="$GIT_DIR/info/exclude" \
91 --exclude-per-directory=.gitignore
92 else
93 git ls-files -z --others --exclude-per-directory=.gitignore
94 fi | xargs -0 -L 1 echo | while read n; do
95 [ -z "$n" ] && continue
96 echo "$n" | sed -e "s/^/?\t/"
97 done
100 # added
101 if [ -z "$IS_INITIAL" ]; then
102 # non-initial commit
103 git diff-index -M --name-status --diff-filter=$DIFF_FILTER HEAD
104 else
105 # initial commit
106 git ls-files | sed -e "s/^/A\t/"
107 fi | sed -e '
108 s/\\/\\\\/g
109 s/ /\\ /g
111 ) | print_status