commit - 13b170bf44646fbf9838bf22a722c499157656ea
commit + ec05a5dec4dd8db58402c3cc719fd2c2c594dc68
blob - 48cb8593b6e8b312d7e33d3d1f606ab4ae17d423
blob + 43c4a8b4c2b0d6b7faedd25e5cc9f3cb3bfed8fa
--- regress/cmdline/patch.sh
+++ regress/cmdline/patch.sh
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
}