Revert "check_packed_git_idx(): check integrity of the idx file itself."
[git.git] / git-status.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Linus Torvalds
4 #
5
6 USAGE=''
7 SUBDIRECTORY_OK='Yes'
8
9 . git-sh-setup
10
11 if [ "$#" != "0" ]
12 then
13   usage
14 fi
15
16 report () {
17   header="#
18 # $1:
19 #   ($2)
20 #
21 "
22   trailer=""
23   while read status name newname
24   do
25     printf '%s' "$header"
26     header=""
27     trailer="#
28 "
29     case "$status" in
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";;
35     A*) echo "# new file: $name";;
36     U ) echo "# unmerged: $name";;
37     esac
38   done
39   printf '%s' "$trailer"
40   [ "$header" ]
41 }
42
43 branch=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD)
44 case "$branch" in
45 refs/heads/master) ;;
46 *)      echo "# On branch $branch" ;;
47 esac
48
49 git-update-index -q --unmerged --refresh || exit
50
51 if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1
52 then
53         git-diff-index -M --cached --name-status --diff-filter=MDTCRA HEAD |
54         sed -e '
55                 s/\\/\\\\/g
56                 s/ /\\ /g
57         ' |
58         report "Updated but not checked in" "will commit"
59
60         committable="$?"
61 else
62         echo '#
63 # Initial commit
64 #'
65         git-ls-files |
66         sed -e '
67                 s/\\/\\\\/g
68                 s/ /\\ /g
69                 s/^/A /
70         ' |
71         report "Updated but not checked in" "will commit"
72
73         committable="$?"
74 fi
75
76 git-diff-files  --name-status |
77 sed -e '
78         s/\\/\\\\/g
79         s/ /\\ /g
80 ' |
81 report "Changed but not updated" "use git-update-index to mark for commit"
82
83
84 if test -f "$GIT_DIR/info/exclude"
85 then
86     git-ls-files -z --others \
87         --exclude-from="$GIT_DIR/info/exclude" \
88         --exclude-per-directory=.gitignore
89 else
90     git-ls-files -z --others \
91         --exclude-per-directory=.gitignore
92 fi |
93 perl -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) {
102                         print "#\n# Untracked files:\n";
103                         print "#   (use \"git add\" to add to commit)\n#\n";
104                         $shown = 1;
105                 }
106                 print "$_\n";
107         }
108 '
109
110 case "$committable" in
111 0)
112         echo "nothing to commit"
113         exit 1
114 esac
115 exit 0