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