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

[PATCH] allow git-am to run in a subdirectory

From
Jeff King <peff@peff.net>
Date
Mar 1, 2008, 06:22 UTC
Message-ID
<20080301062255.GA27538@coredump.intra.peff.net>

We just move to the top of the tree and proceed. This shouldn't break any existing callers, since the behavior was previously disallowed.

Signed-off-by: Jeff King <peff@peff.net>
---
I can't imagine anyone would be confused by this behavior. The only
other behavior that would make sense is perhaps trying to apply from the
given prefix rather than moving to the toplevel, but that just seems
crazy and useless to me.

It will fail to find your mbox file if you specified a relative path and it had to change directories. I don't know if that case is worth handling.

My use case, btw, is that I have an "apply this patch" macro in my MUA. For some messages, it's easy to guess "cd /my/git/repo && git am". But for others, the repo is not obvious, so I apply in the current directory. If I am at the root of the repo, it works fine. If I'm not, then it fails annoyingly.

 git-am.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index 2ecebc4..a2c6fea 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2005, 2006 Junio C Hamano
 
+SUBDIRECTORY_OK=Yes
 OPTIONS_KEEPDASHDASH=
 OPTIONS_SPEC="\
 git-am [options] <mbox>|<Maildir>...
@@ -25,6 +26,7 @@ skip            skip the current patch"
 . git-sh-setup
 set_reflog_action am
 require_work_tree
+cd_to_toplevel
 
 git var GIT_COMMITTER_IDENT >/dev/null || exit
 
-- 
1.5.4.3.422.g55194
Next: Junio C Hamano
Message 1 of 11 in “allow git-am to run in a subdirectory”
  1. allow git-am to run in a subdirectoryJeff King, Mar 1, 2008
  2. Junio C HamanoMar 1, 2008
  3. Jeff KingMar 1, 2008
  4. Junio C HamanoMar 1, 2008
  5. Jeff KingMar 1, 2008
  6. Jay SoffianMar 3, 2008
  7. Re* [PATCH] allow git-am to run in a subdirectoryJunio C Hamano, Mar 3, 2008
  8. Jeff KingMar 3, 2008
  9. Junio C HamanoMar 3, 2008
  10. Johannes SchindelinMar 3, 2008
  11. Junio C HamanoMar 3, 2008

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.