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 <junkio@cox.net>
Junio C Hamano committed
Aug 12, 2006 at 16:16 UTC
fd7bcfb524a3313ef5361bdd8493ba50635f50f0
1 file changed
+19
-9
git-am.sh
+19
-9
@@ -45,6 +45,12 @@ go_next () {
45
this=$next
46
}
47
48
+cannot_fallback () {
49
+ echo "$1"
50
+ echo "Cannot fall back to three-way merge."
51
+ exit 1
52
+}
53
+
54
fall_back_3way () {
55
O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
56
@@ -52,19 +58,23 @@ fall_back_3way () {
58
mkdir "$dotest/patch-merge-tmp-dir"
59
60
# 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" \
71
git-apply $binary --cached <"$dotest/patch"
72
then
65
- echo Using index info to reconstruct a base tree...
73
mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
74
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."
78
fi
79
80
test -f "$dotest/patch-merge-index" &&