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

Re: git-am failed, what's next ?

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 22, 2007, 19:11 UTC
Message-ID
<Pine.LNX.4.63.0702222009380.22628@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<38b2ab8a0702220022wab25519hbb57629934e7f104@mail.gmail.com>
Hi,
On Thu, 22 Feb 2007, Francis Moreau wrote:
Show 7 quoted lines
> I'm a bit clueless when git-am failed to apply a patch. I dunno what I
> should do at this point since errors reported by git-am are not
> usefull for me. For example I got:
> 
> ----
> error: patch failed: foo:1
> error: foo: patch does not apply
I had that quite often. I then ran
	git apply --verbose < .dotest/patch

to find out why it fails, but alas it did not tell me more. That's why I wrote this patch:

-- snipsnap -- [PATCH] apply: make --verbose a little more useful

When a patch fails, I automatically add '-v' to the command line to see what fails.

This patch makes -v a synonym to --verbose, and actually tells the user which text was not found.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 builtin-apply.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 630d8fd..2dde341 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1723,6 +1723,8 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, i
 			/* Ignore it, we already handled it */
 			break;
 		default:
+			if (apply_verbosely)
+				error("invalid start of line: '%c'", first);
 			return -1;
 		}
 		patch += len;
@@ -1820,6 +1822,9 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, i
 		}
 	}
 
+	if (offset && apply_verbosely)
+		error("while searching for:\n%.*s", oldsize, oldlines);
+
 	free(old);
 	free(new);
 	return offset;
@@ -2811,7 +2816,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
 			apply = apply_with_reject = apply_verbosely = 1;
 			continue;
 		}
-		if (!strcmp(arg, "--verbose")) {
+		if (!strcmp(arg, "-v") || !strcmp(arg, "--verbose")) {
 			apply_verbosely = 1;
 			continue;
 		}
-- 
1.5.0.51.ge5582-dirty
Previous: Junio C Hamano
Message 10 of 10 in “git-am failed, what's next ?”
  1. Francis MoreauFeb 22, 2007
  2. Andy ParkinsFeb 22, 2007
  3. Francis MoreauFeb 22, 2007
  4. Junio C HamanoFeb 22, 2007
  5. Francis MoreauFeb 22, 2007
  6. Junio C HamanoFeb 22, 2007
  7. Francis MoreauFeb 22, 2007
  8. Andy ParkinsFeb 22, 2007
  9. Junio C HamanoFeb 22, 2007
  10. Johannes SchindelinFeb 22, 2007

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.