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

Re: Merge git-gui into 1.5.0 ?

From
MTMichael S. Tsirkin <mst@mellanox.co.il>
Date
Feb 12, 2007, 06:25 UTC
Message-ID
<20070212062529.GE28231@mellanox.co.il>
In-Reply-To
<20070212055903.GD28231@mellanox.co.il>
Show 24 quoted lines
> Quoting Michael S. Tsirkin <mst@mellanox.co.il>:
> Subject: Re: Merge git-gui into 1.5.0 ?
> 
> > Quoting Junio C Hamano <junkio@cox.net>:
> > Subject: Re: Merge git-gui into 1.5.0 ?
> > 
> > "Michael S. Tsirkin" <mst@mellanox.co.il> writes:
> > 
> > > Actually, -p<n> option to git-am is also useful for piping
> > > patches to git-am directly from mail: sometimes people would generate
> > > a patch by hand and this results in patches incorrect -p level.
> > 
> > You also would need negative -p option to deal with it as well.
> > Think of getting "diff a/git-add.txt b/git-add.txt" and wanting
> > to apply it to Documentation/git-add.txt.
> 
> Heh, right. With patch I just switch to another shell, cd to the correct
> directory, start mutt *there* and pipe the message to patch.  Since this already
> seems to work for git-apply, maybe this can be made to work with git-am as well?
> 
> Currently:
> $git-am mbox
> fatal: Not a git repository: '.git'
> You need to run this command from the toplevel of the working tree.

Junio, the following seems to work for me. Is this correct? If yes, adding -p is trivial.

Make git-am support "negative strip-level" patches by running it in a subdirectory.

Signed-off-by: Michael S. Tsirkin <mst@mellanox.co.il>
---
diff --git a/git-am.sh b/git-am.sh
index 9a61234..4cea1d2 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -5,6 +5,8 @@
 USAGE='[--signoff] [--dotest=<dir>] [--utf8 | --no-utf8] [--binary] [--3way]
   [--interactive] [--whitespace=<option>] [-CNUM] <mbox>...
   or, when resuming [--skip | --resolved]'
+where=$PWD
+SUBDIRECTORY_OK=Yes
 . git-sh-setup
 set_reflog_action am
 require_work_tree
@@ -60,7 +62,7 @@ fall_back_3way () {
     mkdir "$dotest/patch-merge-tmp-dir"
 
     # First see if the patch records the index info that we can use.
-    git-apply -z --index-info "$dotest/patch" \
+    (cd $where && 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" &&
@@ -69,8 +71,8 @@ fall_back_3way () {
     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"
+    if (cd $where && GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
+	git-apply $binary --cached <"$dotest/patch")
     then
 	mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
 	mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
@@ -398,7 +400,7 @@ do
 
 	case "$resolved" in
 	'')
-		git-apply $git_apply_opt $binary --index "$dotest/patch"
+		(cd $where && git-apply $git_apply_opt $binary --index "$dotest/patch")
 		apply_status=$?
 		;;
 	t)
-- 
MST
Previous: Michael S. TsirkinNext: Johannes Schindelin
Message 13 of 24 in “Merge git-gui into 1.5.0 ?”
  1. Shawn O. PearceFeb 11, 2007
  2. Mark LevedahlFeb 11, 2007
  3. Shawn O. PearceFeb 11, 2007
  4. Johannes SchindelinFeb 11, 2007
  5. Junio C HamanoFeb 11, 2007
  6. Shawn O. PearceFeb 11, 2007
  7. Johannes SchindelinFeb 11, 2007
  8. Shawn O. PearceFeb 11, 2007
  9. Johannes SchindelinFeb 11, 2007
  10. Michael S. TsirkinFeb 12, 2007
  11. Junio C HamanoFeb 12, 2007
  12. Michael S. TsirkinFeb 12, 2007
  13. Michael S. TsirkinFeb 12, 2007
  14. add negative -p to git-am, Re: Merge git-gui into 1.5.0 ?Johannes Schindelin, Feb 12, 2007
  15. Michael S. TsirkinFeb 12, 2007
  16. Johannes SchindelinFeb 12, 2007
  17. Michael S. TsirkinFeb 12, 2007
  18. Junio C HamanoFeb 12, 2007
  19. Shawn O. PearceFeb 12, 2007
  20. Johannes SchindelinFeb 12, 2007
  21. Shawn O. PearceFeb 12, 2007
  22. Johannes SchindelinFeb 12, 2007
  23. Jakub NarebskiFeb 13, 2007
  24. Shawn O. PearceFeb 13, 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.