Commit Diff


commit - 04a87797cb37c4787fdc83040ba75f0ddd60e46d
commit + 27aa2674c93e2cb1cbf231640e9d2ca4969ad008
blob - 48cb8593b6e8b312d7e33d3d1f606ab4ae17d423
blob + 43c4a8b4c2b0d6b7faedd25e5cc9f3cb3bfed8fa
--- regress/cmdline/patch.sh
+++ regress/cmdline/patch.sh
@@ -823,26 +823,81 @@ test_patch_empty_file() {
 
 	echo -n > $testroot/wt/alpha
 	(cd "$testroot/wt" && got commit -m 'edit alpha' alpha) >/dev/null
+
+	# try a patch which re-adds file contents; should suceeed
 	cat <<EOF >$testroot/wt/patch
 --- alpha
 +++ alpha
 @@ -0,0 +1 @@
 +alpha
 EOF
-
 	(cd $testroot/wt && got patch patch) > $testroot/stdout
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		test_done $testroot $ret
 		return 1
 	fi
-
 	echo 'M  alpha' > $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done $testroot $ret
+		return 1
 	fi
+
+	(cd $testroot/wt && got revert -R . > /dev/null)
+
+	# try a patch which edits the file; should fail
+	cat <<EOF >$testroot/wt/patch
+--- alpha
++++ alpha
+@@ -1 +1 @@
+-alpha
++beta
+EOF
+	(cd $testroot/wt && got patch patch) > $testroot/stdout \
+		2> $testroot/stderr
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got patch suceeded unexpectedly" >&2
+		test_done $testroot $ret
+		return 1
+	fi
+
+	echo 'got: patch failed to apply' > $testroot/stderr.expected
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done $testroot $ret
+		return 1
+	fi
+
+	(cd $testroot/wt && got revert -R . > /dev/null)
+
+	# try a patch which deletes lines from the file; should fail
+	cat <<EOF >$testroot/wt/patch
+--- alpha
++++ alpha
+@@ -1,2 +0 @@
+-alpha
+-beta
+EOF
+	(cd $testroot/wt && got patch patch) > $testroot/stdout \
+		2> $testroot/stderr
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got patch suceeded unexpectedly" >&2
+		test_done $testroot $ret
+		return 1
+	fi
+	echo 'got: patch failed to apply' > $testroot/stderr.expected
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+	fi
 	test_done $testroot $ret
 }