Commit Diff


commit - 748b46b9f4f7af3736a2bdc81e204d250a56b3c7
commit + c9a4f4fa65c4e3f4457190460a0b3ec4c50c8d4d
blob - ecf6989cbca1d92de8eb26b076cf13a213f9cd4c
blob + 6f6b8fb3d771e42ab874179bfc9aa6defacadbef
--- lib/patch.c
+++ lib/patch.c
@@ -640,7 +640,11 @@ apply_patch(int *overlapcnt, struct got_worktree *work
 	/* don't run the diff3 merge on creations/deletions */
 	if (*p->blob != '\0' && p->old != NULL && p->new != NULL) {
 		err = open_blob(&apath, &afile, p->blob, repo);
-		if (err && err->code != GOT_ERR_NOT_REF)
+		/*
+		 * ignore failures to open this blob, we might have
+		 * parsed gibberish.
+		 */
+		if (err && !(err->code == GOT_ERR_ERRNO && errno == ENOENT))
 			return err;
 		else if (err == NULL)
 			do_merge = 1;
blob - 20e899eab3a352dc9e8636b15e894c186595d20a
blob + 5d79b58c66cb3e7160cfdb8ce13e13901219e70e
--- regress/cmdline/patch.sh
+++ regress/cmdline/patch.sh
@@ -1588,9 +1588,11 @@ test_patch_merge_unknown_blob() {
 
 	cat <<EOF > $testroot/wt/patch
 I've got a
+diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
+with a
 blob - aaaabbbbccccddddeeeeffff0000111122223333
 and also a
-blob + 0000111122223333444455556666888899990000
+blob + 0000111122223333444455556666777788889999
 for this dummy diff
 --- alpha
 +++ alpha
@@ -1612,7 +1614,40 @@ EOF
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done $testroot $ret
+		return 1
 	fi
+
+	# try again without a `diff' header
+
+	cat <<EOF > $testroot/wt/patch
+I've got a
+blob - aaaabbbbccccddddeeeeffff0000111122223333
+and also a
+blob + 0000111122223333444455556666777788889999
+for this dummy diff
+--- alpha
++++ alpha
+@@ -1 +1 @@
+-alpha
++ALPHA
+will it work?
+EOF
+
+	(cd $testroot/wt && got revert alpha > /dev/null && 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
+	fi
 	test_done $testroot $ret
 }