fix 'mv foo bar; got rm foo; got add bar' and put paths in error messages
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
diff --git a/lib/worktree.c b/lib/worktree.c
index 86889ab..d52d55e 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2597,13 +2597,14 @@ schedule_for_deletion(const char *ondisk_path, struct got_fileindex *fileindex,
if (status != GOT_STATUS_NO_CHANGE) {
if (status == GOT_STATUS_DELETE)
return NULL;
- if (status != GOT_STATUS_MODIFY)
- return got_error(GOT_ERR_FILE_STATUS);
- if (!delete_local_mods)
- return got_error(GOT_ERR_FILE_MODIFIED);
+ if (status == GOT_STATUS_MODIFY && !delete_local_mods)
+ return got_error_path(relpath, GOT_ERR_FILE_MODIFIED);
+ if (status != GOT_STATUS_MODIFY &&
+ status != GOT_STATUS_MISSING)
+ return got_error_path(relpath, GOT_ERR_FILE_STATUS);
}
- if (unlink(ondisk_path) != 0)
+ if (status != GOT_STATUS_MISSING && unlink(ondisk_path) != 0)
return got_error_from_errno2("unlink", ondisk_path);
got_fileindex_entry_mark_deleted_from_disk(ie);
diff --git a/regress/cmdline/rm.sh b/regress/cmdline/rm.sh
index 8d663c8..03c8d8f 100755
--- a/regress/cmdline/rm.sh
+++ b/regress/cmdline/rm.sh
@@ -70,7 +70,8 @@ function test_rm_with_local_mods {
fi
echo "modified beta" > $testroot/wt/beta
- echo 'got: file contains modifications' > $testroot/stderr.expected
+ echo 'got: beta: file contains modifications' \
+ > $testroot/stderr.expected
(cd $testroot/wt && got rm beta 2>$testroot/stderr)
cmp -s $testroot/stderr.expected $testroot/stderr
@@ -134,6 +135,65 @@ function test_double_rm {
test_done "$testroot" "0"
}
+function test_rm_and_add_elsewhere {
+ local testroot=`test_init rm_and_add_elsewhere`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && mv alpha epsilon/)
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+
+ echo '! alpha' > $testroot/stdout.expected
+ echo '? epsilon/alpha' >> $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 'D alpha' > $testroot/stdout.expected
+ (cd $testroot/wt && got rm alpha > $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 epsilon/alpha' > $testroot/stdout.expected
+ (cd $testroot/wt && got add epsilon/alpha > $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 status > $testroot/stdout)
+
+ echo 'D alpha' > $testroot/stdout.expected
+ echo 'A epsilon/alpha' >> $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+}
+
run_test test_rm_basic
run_test test_rm_with_local_mods
run_test test_double_rm
+run_test test_rm_and_add_elsewhere