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

Re: Getting path to a file from arbitrary project directory

From
KKKonstantin Kharlamov <hi-angel@yandex.ru>
Date
Jun 23, 2023, 10:02 UTC
Message-ID
<0610eb14b9ebafd531d9e952e135171267479c66.camel@yandex.ru>
In-Reply-To
<20230623094525.GA4204@szeder.dev>
Thank you very much, works for me!
On Fri, 2023-06-23 at 11:45 +0200, SZEDER Gábor wrote:
Show 33 quoted lines
> On Fri, Jun 23, 2023 at 11:52:58AM +0300, Konstantin Kharlamov wrote:
> > (please keep me CC'ed, I'm not subscribed)
> > 
> > Hello! I'm trying to solve a simple problem: while I am inside an arbitrary
> > project directory, I want to get a path to a file `filename.c` located
> > elsewhere in the same project.¹
> > 
> > One way to implement that is with a command chain:
> > 
> >         cd $(git rev-parse --show-toplevel) && git ls-files --full-name --
> > "*filename.c"
> > 
> > But it is pretty clunky, because that requires you to modify state (changing
> > current directory). It may not matter though, but I'm just wondering if
> > there's a better way to do that, something like `git ls-files --top -- …`,
> > or anything like that? Haven't found nothing similar in `man git-ls-files`.
> 
> When a command expects pathspecs as arguments, then in general the
> leading ':/' magic means the root of the working tree (not sure where
> it is documented, though), i.e. you could try this:
> 
>   git ls-files --full-name ':/*filename.c'
> 
> 
> > As a separate note, this doesn't work:
> > 
> >         ls-files --full-name -- $(git rev-parse --show-
> > toplevel)"*filename.c"
> > 
> > 1: the usecase is I have a Emacs helper function to pick up a an aribtrarily
> > mangled path to a file in the project from the primary clipboard and open
> > that file. It's often "mangled", because gdb prints it with `../`, then logs
> > print no path whatsoever, just a filename… So it's generally useful to have.
Previous: SZEDER GáborNext: Junio C Hamano
Message 3 of 5 in “Getting path to a file from arbitrary project directory”
  1. Konstantin KharlamovJun 23, 2023
  2. SZEDER GáborJun 23, 2023
  3. Konstantin KharlamovJun 23, 2023
  4. Junio C HamanoJun 23, 2023
  5. Konstantin KharlamovJun 23, 2023

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.