make 'got rm' report an "unexpected status" error for unversioned files ok millert@
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
diff --git a/lib/worktree.c b/lib/worktree.c
index 7b9584f..02ace08 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3978,7 +3978,7 @@ schedule_for_deletion(void *arg, unsigned char status,
ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
if (ie == NULL)
- return got_error_path(relpath, GOT_ERR_BAD_PATH);
+ return got_error_path(relpath, GOT_ERR_FILE_STATUS);
staged_status = get_staged_status(ie);
if (staged_status != GOT_STATUS_NO_CHANGE) {
diff --git a/regress/cmdline/rm.sh b/regress/cmdline/rm.sh
index 8b4c659..f82d2c0 100755
--- a/regress/cmdline/rm.sh
+++ b/regress/cmdline/rm.sh
@@ -213,6 +213,66 @@ test_rm_and_add_elsewhere() {
return 1
fi
+ # While here, test behaviour of rm on files in unversioned status.
+ (cd $testroot/wt && got rm epsilon/alpha > $testroot/stdout \
+ 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got rm command succeeded unexpectedly" >&2
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo -n '' > $testroot/stdout.expected
+ 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 "got: epsilon/alpha: file has unexpected status" \
+ > $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
+
+ # And test the same case with -f.
+ (cd $testroot/wt && got rm -f epsilon/alpha > $testroot/stdout \
+ 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got rm command succeeded unexpectedly" >&2
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo -n '' > $testroot/stdout.expected
+ 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 "got: epsilon/alpha: file has unexpected status" \
+ > $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 'A epsilon/alpha' > $testroot/stdout.expected
(cd $testroot/wt && got add epsilon/alpha > $testroot/stdout)