-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcg-status
executable file
·311 lines (279 loc) · 9.24 KB
/
cg-status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/usr/bin/env bash
#
# Show status of the repository and your working tree
# Copyright (c) Petr Baudis, 2005
# Copyright (c) Pavel Roskin 2005
#
# The output includes the list of branches and merge status.
# Current branch is marked with ">", remote branches are marked with "R".
# Branches with shelved local changes (currently produced only by
# `cg-switch -l`) are marked with "s".
#
# Then, the files in the working tree are printed out. The output has
# the following format:
#
# <status flag> <file>
#
# where '<status flag>' can be one of the following:
#
# ?::
# '<file>' is not known to Cogito. See the IGNORING section below.
# A::
# '<file>' has been added.
# D::
# '<file>' has been deleted.
# !::
# '<file>' is gone from your working copy but not deleted by `cg-rm`.
# M::
# '<file>' has been touched or modified.
# m::
# '<file>' has been touched or modified, but will not be automatically
# committed the next time you call `cg-commit`. This is used during a
# merge to mark files which contained local changes before the merge.
#
# OPTIONS
# -------
# If neither -g or -w is passed, both is shown; otherwise, only the
# corresponding parts are shown.
#
# -g:: Show the GIT repository information
# Show the GIT repository information.
#
# -n:: Do not show status flags
# Do not show status flags. This is probably useful only when you filter
# the flags for a single specific flag using the '-s' option.
#
# -s STATUS:: Limit to files matching the STATUS flags
# Show only files with the given status flag, e.g. '-s D'. You can list
# multiple flags ('-s MmA') to filter for all of them. You can prepend
# '^' to the STATUS argument to invert the filter - only items with flags
# NOT listed in the STATUS string will be printed out.
#
# -S:: Do not squash directories
# By default, cg-status will not list full contents of untracked
# directories but only their name. This option will make it show the
# all untracked files inside as well.
#
# -w:: Show working files
# Show the working tree file list.
#
# -x:: Disable file exclusion
# Don't exclude any files from listing.
#
# DIRPATH::
# Path to the directory to use as the base for the working tree
# file list (instead of the current directory).
#
# NOTES
# -----
# If a file has been removed with `cg-rm` without using the `-f` option
# to remove it physically from the tree it will be reported as both being
# deleted and unknown. The reason for this is that the file is internally
# marked as deleted and thus also untracked. After next commit it will only
# be reported as being untracked.
#
# IGNORING
# --------
# You can declare some files to be ignored: this means that they will
# not be listed as unknown in `cg-status`, `cg-clean` will not remove
# them (unless '-x' is passed), and `cg-init` and `cg-add -a` will
# not add them. However, the moment you explicitly tell Cogito about
# them using `cg-add`, Cogito will stop ignoring them; it will commit
# any modifications in them, etc.: the concept is the same as e.g. in CVS.
# Typically, autogenerated and backup files are marked as ignored.
#
# Which files to ignore is determined by lists of exclude patterns
# stored in various files. There is one pattern per line and the
# patterns are classic shell glob patterns (with '*' and '?' wildcards).
# The pattern can be prefixed by '!' to unignore matching files.
# If the pattern does not contain a slash, it is applied in all
# directories; otherwise, only to the given path in the tree; use
# leading slash to denote the tree root.
#
# For example, consider the following:
#
# -------------------------------------------------------------------
# .*
# !.gitignore
# !/.list
# -------------------------------------------------------------------
#
# This will ignore all hidden files except '.gitignore' in all
# directories and the '.list' file in project root.
#
# When collecting the ignore patterns, first the default ignore
# patterns are loaded from '/usr/share/cogito/default-exclude'
# (or a slightly different path depending on your installation prefix).
# Then, '.git/info/exclude' from your working copy is loaded. At last,
# during the actual tree traversal '.gitignore' in each visited directory
# is loaded for the time of its traversal.
#
# FILES
# -----
# $GIT_DIR/info/exclude::
# The list of ignore patterns; the list itself is not version-tracked
# and is local to this particular clone.
#
# '.gitignore'::
# '.gitignore' in the working tree will be also scanned for ignore
# patterns. Contrary to the exclude file, it is usually version-tracked.
#
# BUGS
# ----
# One known bug is that when you `cg-add` a new file and then delete it
# but do not call `cg-rm`, it will not be listed in `cg-status` output,
# but from the merging point of view there will still be "local changes"
# and `cg-diff` will show a diff.
# Testsuite: Marginal (part of t9202-merge-on-dirty)
USAGE="cg-status [-g] [[-n] -s STATUS] [-w] [-x] [DIRPATH]"
_git_wc_unneeded=1
. "${COGITO_LIB}"cg-Xlib || exit 1
should_show_flag() {
[[ -z "$flagfilter" || "$flagfilter" == *"$1"* ]]
}
gitstatus=
workstatus=
exclude=yes
flagfilter=
noflags=
squashdirs=squashdirs
while optparse; do
if optparse -g; then
gitstatus=1
elif optparse -n; then
noflags=1
elif optparse -s=; then
flagfilter="$OPTARG"
echo "$flagfilter" | grep -qx '[a-zA-Z?!^]*' \
|| die "invalid -s status flag"
if [ x"${flagfilter:0:1}" = x"^" ]; then
flagfilter="$(echo "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!" | tr -d "${flagfilter:1}")"
fi
elif optparse -S; then
squashdirs=nosquashdirs
elif optparse -w; then
workstatus=1
elif optparse -x; then
exclude=no
else
optfail
fi
done
if [ ! "$gitstatus" ] && [ ! "$workstatus" ]; then
gitstatus=1
workstatus=1
fi
if [ "$_git_no_wc" ]; then
workstatus=
fi
mstatedir="$_git/cg-merge-state"
if [ "$gitstatus" ]; then
[ -s "$_git/branch-name" ] && echo "Branch (informal): $(cat "$_git/branch-name")"
if [ -s "$_git/head-name" ]; then
headsha1=$(cat "$_git/$(git-symbolic-ref HEAD)")
echo "Seeked from head: $(cat "$_git/head-name")"
echo "Seeked at commit: $headsha1"
echo
fi
# -name * will prevent listing hidden heads
maxlen="$(git-for-each-ref --format="%(refname)" refs/heads | column_width "refs/heads/")"
maxlen=$((maxlen + 1))
maxloglen=$(tput cols)
# 5 status flags + 2 times separating spaces = 7
maxloglen=$((maxloglen - maxlen - 7))
#maxsha1len=$((maxloglen - 40))
#[ $maxsha1len -lt 12 ] && maxsha1len=12
#[ $maxsha1len -gt 40 ] && maxsha1len=40
maxsha1len=12
sha1digits="$maxsha1len"
if [ $maxsha1len -lt 40 ]; then
trimmark="~"
maxsha1len=$((maxsha1len+1))
else
trimmark=
fi
maxloglen=$((maxloglen - maxsha1len))
[ $maxlen -gt 1 ] && echo "Heads:"
git-for-each-ref --format="%(refname) %(objectname) %(subject)" refs/heads |
while read head sha1 headlog; do
headname="${head#refs/heads/}"
headsha1="${sha1:0:$sha1digits}"
[ "$headname" = "cg-seek-point" ] && continue
cf=" "; rf=" "; sf=" ";
[ "$headname" = "$_git_head" ] && cf=">"
[ -s "$_git/branches/$headname" ] && rf="R"
# ..cg-shelve deprecated as of 2006-11-19
exists_ref "refs/heads/.cg-shelve-$headname" && sf="s"
exists_ref "refs/shelves/$headname" && sf="s"
columns_print " $sf$rf$cf" - "$headname" $maxlen "$headsha1$trimmark" $((maxsha1len + 1)) "$headlog" m$maxloglen
done
if [ -s "$mstatedir/merging" ]; then
tmp="$(cat "$mstatedir/merging")"
echo
echo "Merging: $(cat "$mstatedir/merging") ($(cat "$mstatedir/merging-sym"))"
echo "Merge base: $(cat "$mstatedir/merge-base")"
[ -s "$mstatedir/squashing" ] && echo "Squash-merge."
fi
if [ -s "$mstatedir/commit-ignore" ]; then
echo "Files not to be committed now (contained local changes before the merge):"
sed 's/^/ /' "$mstatedir/commit-ignore"
fi
if [ -s "$_git/blocked" ]; then
echo
echo "Changes recording BLOCKED:"
sed 's/^/ /' "$_git/blocked"
fi
if [ ! -s "$_git/$(git-symbolic-ref HEAD)" ]; then
echo
echo "Before initial commit."
fi
if [ "$_git_no_wc" ]; then
echo
echo "Repository without attached working copy."
fi
fi
if [ "$gitstatus" ] && [ "$workstatus" ]; then
echo
fi
if [ "$workstatus" ]; then
git-update-index --refresh > /dev/null
basepath="$_git_relpath"
[ "${ARGS[0]}" ] && basepath="$(echo "$_git_relpath${ARGS[0]}" | normpath)"
should_show_flag '?' &&
list_untracked_files $exclude $squashdirs | tr '\0' '\n' |
if [ "$basepath" ]; then
while IFS=$'' read path; do
[ x"${path#$basepath}" != x"$path" ] &&
echo "${path#$_git_relpath}"
done
else
cat
fi |
sed 's,^,? ,'
if [ ! -s "$_git/$(git-symbolic-ref HEAD)" ]; then
# Initial commit
should_show_flag 'A' && git-ls-files | sed 's,^,A ,'
else
commitignore=
[ -s "$mstatedir/commit-ignore" ] && commitignore=1
git-diff-index HEAD -- "${basepath:-.}" | cut -f5- -d' ' |
while IFS=$'\t' read -r mode file; do
if [ "$mode" = D ]; then
[ "$(git-diff-files -- "$file")" ] && continue # "!"
elif [ "$mode" = M ] && [ "$commitignore" ]; then
fgrep -qx "$file" "$mstatedir/commit-ignore" && mode=m
fi
should_show_flag "$mode" && echo "$mode ${file#$_git_relpath}"
done
git-diff-files -- "${basepath:-.}" | cut -f5- -d' ' |
while IFS=$'\t' read -r mode file; do
if [ "$mode" = D ]; then
should_show_flag "!" && echo "! ${file#$_git_relpath}"
fi
done
fi
fi | if [ "$noflags" ]; then
sed 's/^. //'
else
cat
fi