make 'got status' detect obstructed files
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
diff --git a/got/got.1 b/got/got.1
index 374ed5e..4918b98 100644
--- a/got/got.1
+++ b/got/got.1
@@ -115,6 +115,7 @@ using the following status codes:
.Bl -column YXZ description
.It M Ta modified file
.It ! Ta versioned file was expected on disk but is missing
+.It ~ Ta versioned file is obstructed by a non-regular file
.It ? Ta unversioned item not tracked by
.Nm
.El
diff --git a/include/got_worktree.h b/include/got_worktree.h
index 58867ae..879b57c 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -25,6 +25,7 @@ struct got_worktree;
#define GOT_STATUS_MODIFIY 'M'
#define GOT_STATUS_MISSING '!'
#define GOT_STATUS_UNVERSIONED '?'
+#define GOT_STATUS_OBSTRUCTED '~'
/*
* Attempt to initialize a new work tree on disk.
diff --git a/lib/worktree.c b/lib/worktree.c
index 6f599b3..063b75f 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -936,8 +936,10 @@ get_file_status(unsigned char *status, struct got_fileindex_entry *ie,
if (lstat(abspath, &sb) == -1)
return got_error_from_errno();
- if (!S_ISREG(sb.st_mode))
+ if (!S_ISREG(sb.st_mode)) {
+ *status = GOT_STATUS_OBSTRUCTED;
return NULL;
+ }
if (ie->ctime_sec == sb.st_ctime &&
ie->ctime_nsec == sb.st_ctimensec &&
diff --git a/regress/cmdline/status.sh b/regress/cmdline/status.sh
index 787e05f..d6d36bc 100755
--- a/regress/cmdline/status.sh
+++ b/regress/cmdline/status.sh
@@ -125,6 +125,33 @@ function test_status_subdir_no_mods2 {
test_done "$testroot" "0"
}
+function test_status_obstructed {
+ local testroot=`test_init status_obstructed`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ if [ "$?" != "0" ]; then
+ test_done "$testroot" "$?"
+ return 1
+ fi
+
+ rm $testroot/wt/epsilon/zeta
+ mkdir $testroot/wt/epsilon/zeta
+
+ echo '~ epsilon/zeta' > $testroot/stdout.expected
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+
+ cmp $testroot/stdout.expected $testroot/stdout
+ if [ "$?" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$?"
+ return 1
+ fi
+
+ test_done "$testroot" "0"
+}
+
run_test test_status_basic
run_test test_status_subdir_no_mods
run_test test_status_subdir_no_mods2
+run_test test_status_obstructed