Skip to content

Commit fd7bcfb

Browse files
author
Junio C Hamano
committed
git-am: give better diagnostics when the patch does not apply during --3way
If the user tries to apply a patch that was hand-edited in such a way that it does not apply to the original file recorded on its "index" line anymore, we did detect the situation but did not issue an error message that is specific enough. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 022f25e commit fd7bcfb

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

git-am.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,36 @@ go_next () {
4545
this=$next
4646
}
4747

48+
cannot_fallback () {
49+
echo "$1"
50+
echo "Cannot fall back to three-way merge."
51+
exit 1
52+
}
53+
4854
fall_back_3way () {
4955
O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
5056

5157
rm -fr "$dotest"/patch-merge-*
5258
mkdir "$dotest/patch-merge-tmp-dir"
5359

5460
# First see if the patch records the index info that we can use.
55-
if git-apply -z --index-info "$dotest/patch" \
56-
>"$dotest/patch-merge-index-info" 2>/dev/null &&
57-
GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
58-
git-update-index -z --index-info <"$dotest/patch-merge-index-info" &&
59-
GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
60-
git-write-tree >"$dotest/patch-merge-base+" &&
61-
# index has the base tree now.
62-
GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
61+
git-apply -z --index-info "$dotest/patch" \
62+
>"$dotest/patch-merge-index-info" &&
63+
GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
64+
git-update-index -z --index-info <"$dotest/patch-merge-index-info" &&
65+
GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
66+
git-write-tree >"$dotest/patch-merge-base+" ||
67+
cannot_fallback "Patch does not record usable index information."
68+
69+
echo Using index info to reconstruct a base tree...
70+
if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
6371
git-apply $binary --cached <"$dotest/patch"
6472
then
65-
echo Using index info to reconstruct a base tree...
6673
mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
6774
mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
75+
else
76+
cannot_fallback "Did you hand edit your patch?
77+
It does not apply to blobs recorded in its index."
6878
fi
6979

7080
test -f "$dotest/patch-merge-index" &&

0 commit comments

Comments
 (0)