got patch: ignore blobs not found since diffs are often enclosed in other formats (e.g. emails) we might parse something and think it's a blob id when it's not. This should already happens, but apply_patch is looking for the wrong error due to a leftover from previous attempts. Reported by stsp@ while here tweak the test_patch_merge_unknown_blob to also try with a dummy commit id, as now got-read-patch requires it in order to consider a blob id. ok stsp@
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
diff --git a/lib/patch.c b/lib/patch.c
index 9209e54..1fc82c6 100644
--- a/lib/patch.c
+++ b/lib/patch.c
@@ -643,7 +643,11 @@ apply_patch(int *overlapcnt, struct got_worktree *worktree,
/* 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;
diff --git a/regress/cmdline/patch.sh b/regress/cmdline/patch.sh
index 20e899e..5d79b58 100755
--- a/regress/cmdline/patch.sh
+++ b/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,6 +1614,39 @@ 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
}