git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to resolve git-am conflict (possible bug)

From
Junio C Hamano <junkio@cox.net>
Date
Aug 12, 2006, 19:49 UTC
Message-ID
<7vzme9oht9.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<ebk6be$31k$2@sea.gmane.org>
Jakub Narebski <jnareb@gmail.com> writes:
Show 9 quoted lines
> Jakub Narebski wrote:
>
>> Junio C Hamano wrote:
> [...] 
>>> More likely explanation is that you edited the patch by hand for
>>> some reason, and made it inapplicable to the base blob the
>>> "index" line records.
>
> Original (not edited) version of patch generates nice merge conflict.

The moral of the story is that either (1) you hand edit the patch to apply cleanly to the target, or (2) if you do edit, do not make it inapplicable to the preimage blob recorded in the patch, so that -3 still would work.

Show 6 quoted lines
>> It would be nice then if git-am was more verbose, for example
>> "Applying patch to blob 7ea52b1... gitweb/gitweb.perl" or something
>> like that.
>
> Or at least some information what git-am is attempting before second 
> 'patch failed' error message...
How about this?
diff --git a/git-am.sh b/git-am.sh
index 04f0119..aff4bb7 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -45,6 +45,12 @@ go_next () {
 	this=$next
 }
 
+cannot_fallback () {
+	echo >&2 "$1"
+	echo >&2 "Cannot fall back to three-way merge."
+	exit 1
+}
+
 fall_back_3way () {
     O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
 
@@ -52,19 +58,23 @@ fall_back_3way () {
     mkdir "$dotest/patch-merge-tmp-dir"
 
     # First see if the patch records the index info that we can use.
-    if git-apply -z --index-info "$dotest/patch" \
-	>"$dotest/patch-merge-index-info" 2>/dev/null &&
-	GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
-	git-update-index -z --index-info <"$dotest/patch-merge-index-info" &&
-	GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
-	git-write-tree >"$dotest/patch-merge-base+" &&
-	# index has the base tree now.
-	GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
+    git-apply -z --index-info "$dotest/patch" \
+    	>"$dotest/patch-merge-index-info" &&
+    GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
+    git-update-index -z --index-info <"$dotest/patch-merge-index-info" &&
+    GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
+    git-write-tree >"$dotest/patch-merge-base+" ||
+    cannot_fallback "Patch does not record usable index information."
+
+    echo Using index info to reconstruct a base tree...
+    if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
 	git-apply $binary --cached <"$dotest/patch"
     then
-	echo Using index info to reconstruct a base tree...
 	mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
 	mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
+    else
+        cannot_fallback "Did you hand edit your patch?
+It does not apply to blobs recorded in its index."
     fi
 
     test -f "$dotest/patch-merge-index" &&
Previous: Jakub NarebskiNext: Johannes Schindelin
Message 6 of 8 in “How to resolve git-am conflict (possible bug)”
  1. Jakub NarebskiAug 12, 2006
  2. Junio C HamanoAug 12, 2006
  3. Junio C HamanoAug 12, 2006
  4. Jakub NarebskiAug 12, 2006
  5. Jakub NarebskiAug 12, 2006
  6. Junio C HamanoAug 12, 2006
  7. Johannes SchindelinAug 12, 2006
  8. Junio C HamanoAug 12, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.