Commit Diff


commit - 0f6d7415053c3cb56d6d4bafb624866ae4554f3e
commit + d3bcc3d18ab565811e1da723157c85657570b010
blob - 092546cdf650ee446d066428524ec86d90630a74
blob + 1fdda693ee6ec447c666e69535d782fcfb137e00
--- lib/worktree.c
+++ lib/worktree.c
@@ -2707,16 +2707,15 @@ revert_file(void *arg, unsigned char status, unsigned 
 	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) {
blob - d21ecfe6a104e79385d30557b70718afef39b876
blob + e7fb40ff27a838ef389cac5d09189a21b2d212d1
--- regress/cmdline/stage.sh
+++ 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="$?"