add -s option to 'got status' which acts as a status code filter Advantages over using grep are that the list of codes is validated against a list of known status codes, and that it is easier to match staged files which can display status codes in one or both of two columns. Prompted by feedback from krw@
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
diff --git a/got/got.1 b/got/got.1
index f9e5cd6..8f04918 100644
--- a/got/got.1
+++ b/got/got.1
@@ -607,7 +607,7 @@ branch will be used.
.It Cm up
Short alias for
.Cm update .
-.It Cm status Op Ar path ...
+.It Cm status Oo Fl s Ar status-codes Oc Op Ar path ...
Show the current modification status of files in a work tree,
using the following status codes:
.Bl -column YXZ description
@@ -646,6 +646,20 @@ Changes created on top of staged changes are indicated in the first column:
.It MA Ta file was modified after having been staged for addition
.El
.Pp
+The options for
+.Cm got status
+are as follows:
+.Bl -tag -width Ds
+.It Fl s Ar status-codes
+Only show files with a modification status matching any of the
+single-character status codes contained in the
+.Ar status-codes
+argument.
+Any combination of codes from the above list of possible status codes
+may be specified.
+For staged files, status codes displayed in either column will be matched.
+.El
+.Pp
For compatibility with
.Xr cvs 1
and
@@ -1955,9 +1969,12 @@ Check out a work tree from the Git repository to /usr/src:
.Pp
View local changes in a work tree directory:
.Pp
-.Dl $ got status
.Dl $ got diff | less
.Pp
+In a work tree, display files in a potentially problematic state:
+.Pp
+.Dl $ got status -s 'C!~?'
+.Pp
Interactively revert selected local changes in a work tree directory:
.Pp
.Dl $ got revert -p -R\ .
diff --git a/got/got.c b/got/got.c
index 7d306e8..93fe92b 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4642,7 +4642,8 @@ done:
__dead static void
usage_status(void)
{
- fprintf(stderr, "usage: %s status [path ...]\n", getprogname());
+ fprintf(stderr, "usage: %s status [-s status-codes ] [path ...]\n",
+ getprogname());
exit(1);
}
@@ -4654,6 +4655,18 @@ print_status(void *arg, unsigned char status, unsigned char staged_status,
{
if (status == staged_status && (status == GOT_STATUS_DELETE))
status = GOT_STATUS_NO_CHANGE;
+ if (arg) {
+ char *status_codes = arg;
+ size_t ncodes = strlen(status_codes);
+ int i;
+ for (i = 0; i < ncodes ; i++) {
+ if (status == status_codes[i] ||
+ staged_status == status_codes[i])
+ break;
+ }
+ if (i == ncodes)
+ return NULL;
+ }
printf("%c%c %s\n", status, staged_status, path);
return NULL;
}
@@ -4664,15 +4677,35 @@ cmd_status(int argc, char *argv[])
const struct got_error *error = NULL;
struct got_repository *repo = NULL;
struct got_worktree *worktree = NULL;
- char *cwd = NULL;
+ char *cwd = NULL, *status_codes = NULL;;
struct got_pathlist_head paths;
struct got_pathlist_entry *pe;
- int ch;
+ int ch, i;
TAILQ_INIT(&paths);
- while ((ch = getopt(argc, argv, "")) != -1) {
+ while ((ch = getopt(argc, argv, "s:")) != -1) {
switch (ch) {
+ case 's':
+ for (i = 0; i < strlen(optarg); i++) {
+ switch (optarg[i]) {
+ case GOT_STATUS_MODIFY:
+ case GOT_STATUS_ADD:
+ case GOT_STATUS_DELETE:
+ case GOT_STATUS_CONFLICT:
+ case GOT_STATUS_MISSING:
+ case GOT_STATUS_OBSTRUCTED:
+ case GOT_STATUS_UNVERSIONED:
+ case GOT_STATUS_MODE_CHANGE:
+ case GOT_STATUS_NONEXISTENT:
+ break;
+ default:
+ errx(1, "invalid status code '%c'",
+ optarg[i]);
+ }
+ }
+ status_codes = optarg;
+ break;
default:
usage_status();
/* NOTREACHED */
@@ -4714,8 +4747,8 @@ cmd_status(int argc, char *argv[])
if (error)
goto done;
- error = got_worktree_status(worktree, &paths, repo, print_status, NULL,
- check_cancelled, NULL);
+ error = got_worktree_status(worktree, &paths, repo, print_status,
+ status_codes, check_cancelled, NULL);
done:
TAILQ_FOREACH(pe, &paths, entry)
free((char *)pe->path);
diff --git a/regress/cmdline/status.sh b/regress/cmdline/status.sh
index 57f0661..46a1853 100755
--- a/regress/cmdline/status.sh
+++ b/regress/cmdline/status.sh
@@ -634,6 +634,122 @@ function test_status_gitignore {
test_done "$testroot" "$ret"
}
+function test_status_status_code {
+ local testroot=`test_init status_status_code`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified alpha" > $testroot/wt/alpha
+ (cd $testroot/wt && got rm beta >/dev/null)
+ echo "unversioned file" > $testroot/wt/foo
+ rm $testroot/wt/epsilon/zeta
+ touch $testroot/wt/beta
+ echo "new file" > $testroot/wt/new
+ (cd $testroot/wt && got add new >/dev/null)
+
+ (cd $testroot/wt && got status -s xDM \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "status succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo "got: invalid status code 'x'" > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo 'M alpha' > $testroot/stdout.expected
+ (cd $testroot/wt && got status -s M > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo 'D beta' > $testroot/stdout.expected
+ (cd $testroot/wt && got status -s D > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo '! epsilon/zeta' > $testroot/stdout.expected
+ echo '? foo' >> $testroot/stdout.expected
+ (cd $testroot/wt && got status -s \!? > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo 'A new' > $testroot/stdout.expected
+ (cd $testroot/wt && got status -s A > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got stage new > $testroot/stdout)
+
+ echo ' A new' > $testroot/stdout.expected
+ (cd $testroot/wt && got status -s A > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo 'changed file new' > $testroot/wt/new
+
+ echo 'MA new' > $testroot/stdout.expected
+ (cd $testroot/wt && got status -s A > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo 'M alpha' > $testroot/stdout.expected
+ echo 'MA new' >> $testroot/stdout.expected
+ (cd $testroot/wt && got status -s M > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ test_done "$testroot" "$ret"
+}
+
+
test_parseargs "$@"
run_test test_status_basic
run_test test_status_subdir_no_mods
@@ -649,3 +765,4 @@ run_test test_status_empty_dir_unversioned_file
run_test test_status_many_paths
run_test test_status_cvsignore
run_test test_status_gitignore
+run_test test_status_status_code