make revert of a staged deletion a no-op for better interaction with -R
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
diff --git a/lib/worktree.c b/lib/worktree.c
index 092546c..1fdda69 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2707,16 +2707,15 @@ revert_file(void *arg, unsigned char status, unsigned char staged_status,
char *ondisk_path = NULL;
struct got_blob_object *blob = NULL;
+ /* Reverting a staged deletion is a no-op. */
+ if (status == GOT_STATUS_DELETE &&
+ staged_status != GOT_STATUS_NO_CHANGE)
+ return NULL;
+
ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
if (ie == NULL)
return got_error(GOT_ERR_BAD_PATH);
- if (status == GOT_STATUS_DELETE &&
- staged_status != GOT_STATUS_NO_CHANGE) {
- err = got_error_path(ie->path, GOT_ERR_FILE_STAGED);
- goto done;
- }
-
/* Construct in-repository path of tree which contains this blob. */
err = got_path_dirname(&parent_path, ie->path);
if (err) {
diff --git a/regress/cmdline/stage.sh b/regress/cmdline/stage.sh
index d21ecfe..e7fb40f 100755
--- a/regress/cmdline/stage.sh
+++ b/regress/cmdline/stage.sh
@@ -708,13 +708,22 @@ function test_stage_revert {
(cd $testroot/wt && got revert beta > $testroot/stdout \
2> $testroot/stderr)
ret="$?"
- if [ "$ret" == "0" ]; then
- echo "revert command succeeded unexpectedly" >&2
- test_done "$testroot" "1"
+ if [ "$ret" != "0" ]; then
+ echo "revert command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
return 1
fi
- echo "got: beta: file is staged" > $testroot/stderr.expected
+ 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 -n > $testroot/stderr.expected
cmp -s $testroot/stderr.expected $testroot/stderr
ret="$?"
if [ "$ret" != "0" ]; then
@@ -807,13 +816,14 @@ function test_stage_revert {
(cd $testroot/wt && got revert -R . > $testroot/stdout \
2> $testroot/stderr)
ret="$?"
- if [ "$ret" == "0" ]; then
- echo "revert command succeeded unexpectedly" >&2
+ if [ "$ret" != "0" ]; then
+ echo "revert command failed unexpectedly" >&2
test_done "$testroot" "$ret"
return 1
fi
echo "R alpha" > $testroot/stdout.expected
+ echo "R foo" >> $testroot/stdout.expected
cmp -s $testroot/stdout.expected $testroot/stdout
ret="$?"
if [ "$ret" != "0" ]; then
@@ -822,7 +832,7 @@ function test_stage_revert {
return 1
fi
- echo "got: beta: file is staged" > $testroot/stderr.expected
+ echo -n > $testroot/stderr.expected
cmp -s $testroot/stderr.expected $testroot/stderr
ret="$?"
if [ "$ret" != "0" ]; then
@@ -833,7 +843,7 @@ function test_stage_revert {
echo ' M alpha' > $testroot/stdout.expected
echo ' D beta' >> $testroot/stdout.expected
- echo 'MA foo' >> $testroot/stdout.expected
+ echo ' A foo' >> $testroot/stdout.expected
(cd $testroot/wt && got status > $testroot/stdout)
cmp -s $testroot/stdout.expected $testroot/stdout
ret="$?"