]> git.ipfire.org Git - thirdparty/git.git/blob - git-status.sh
Merge http://www.kernel.org/pub/scm/gitk/gitk
[thirdparty/git.git] / git-status.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Linus Torvalds
4 #
5 GIT_DIR=$(git-rev-parse --git-dir) || exit
6
7 report () {
8 header="#
9 # $1:
10 # ($2)
11 #
12 "
13 trailer=""
14 while read status name newname
15 do
16 echo -n "$header"
17 header=""
18 trailer="#
19 "
20 case "$status" in
21 M ) echo "# modified: $name";;
22 D*) echo "# deleted: $name";;
23 T ) echo "# typechange: $name";;
24 C*) echo "# copied: $name -> $newname";;
25 R*) echo "# renamed: $name -> $newname";;
26 A*) echo "# new file: $name";;
27 U ) echo "# unmerged: $name";;
28 esac
29 done
30 echo -n "$trailer"
31 [ "$header" ]
32 }
33
34 branch=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD)
35 case "$branch" in
36 refs/heads/master) ;;
37 *) echo "# On branch $branch" ;;
38 esac
39
40 git-update-index -q --unmerged --refresh || exit
41
42 if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1
43 then
44 git-diff-index -M --cached --name-status --diff-filter=MDTCRA HEAD |
45 sed -e '
46 s/\\/\\\\/g
47 s/ /\\ /g
48 ' |
49 report "Updated but not checked in" "will commit"
50
51 committable="$?"
52 else
53 echo '#
54 # Initial commit
55 #'
56 git-ls-files |
57 sed -e '
58 s/\\/\\\\/g
59 s/ /\\ /g
60 s/^/A /
61 ' |
62 report "Updated but not checked in" "will commit"
63
64 committable="$?"
65 fi
66
67 git-diff-files --name-status |
68 sed -e '
69 s/\\/\\\\/g
70 s/ /\\ /g
71 ' |
72 report "Changed but not updated" "use git-update-index to mark for commit"
73
74
75 if test -f "$GIT_DIR/info/exclude"
76 then
77 git-ls-files -z --others \
78 --exclude-from="$GIT_DIR/info/exclude" \
79 --exclude-per-directory=.gitignore
80 else
81 git-ls-files -z --others \
82 --exclude-per-directory=.gitignore
83 fi |
84 perl -e '$/ = "\0";
85 my $shown = 0;
86 while (<>) {
87 chomp;
88 s|\\|\\\\|g;
89 s|\t|\\t|g;
90 s|\n|\\n|g;
91 s/^/# /;
92 if (!$shown) {
93 print "#\n# Untracked files:\n";
94 print "# (use \"git add\" to add to commit)\n#\n";
95 $shown = 1;
96 }
97 print "$_\n";
98 }
99 '
100
101 case "$committable" in
102 0)
103 echo "nothing to commit"
104 exit 1
105 esac
106 exit 0