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

Re: [PATCH] rev-parse: add option for absolute or relative path formatting

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Nov 5, 2020, 03:11 UTC
Message-ID
<20201105031153.GA1332931@camp.crustytoothpaste.net>
In-Reply-To
<20201104221659.GA3183353@google.com>
On 2020-11-04 at 22:16:59, Jonathan Nieder wrote:
Show 17 quoted lines
> brian m. carlson wrote:
> 
> > This impetus for this patch is Git LFS, which is written in Go.  Go
> > lacks a cross-platform way to canonicalize paths in the same way that
> > Git does, so when Git produces relative paths, such as in some cases
> > with --git-common-dir, we end up with problems when users are doing
> > things with unusual paths on Windows, such as when using SUBST or
> > OneDrive or various other edge cases.  Go upstream does not appear eager
> > to address this problem.
> 
> Can you describe the user-facing symptom?  While reviewing
> https://lore.kernel.org/git/20201009191511.267461-1-sandals@crustytoothpaste.net/
> I'm trying to understand the motivation and I'm getting stuck at
> trying to understand the basics of the problem being solved.
> 
> E.g. is this about being able to compare paths, being able to open
> files, resolving symlinks, something else?

The goal is to resolve paths the way Git does and allow verify that a path is within the repository.

Some paths, such as SUBST drives, are canonicalized by Git using GetFinalPathNameByHandle, which is the standard way of canonicalizing paths on Windows.

Go provides filepath.EvalSymlinks, which does not handle these paths, and consequently, a check that a given path is within the repository (or git directory) fails because Go sees the path as being on one drive (after canonicalization) and Git sees the repository as being on another. This is in part because the .git directory we've canonicalized in Go is totally different from the path that Git has for it, and consequently they aren't comparable.

That's the user-facing symptom.

There are a variety of other Windows paths that are handled differently as well beyond the SUBST paths. I'm not an expert on Windows or Windows paths, so I can't enumerate all the cases where one case works and the other fails. Ideally Go would learn to canonicalize paths the way the system does using a cross-platform function. I believe there's an issue upstream to deal with this at https://github.com/golang/go/issues/42201.

This is also generally applicable for scripting, where realpath(1) is not always available (e.g., on macOS), but mostly this is here to make Windows work more nicely, since it has more complex path functionality.

-- 
brian m. carlson (he/him or they/them)
Houston, Texas, US
Previous: Jonathan NiederNext: Jonathan Nieder
Message 9 of 11 in “rev-parse: add option for absolute or relative path formatting”
  1. rev-parse: add option for absolute or relative path formattingbrian m. carlson, Sep 8, 2020
  2. Johannes SchindelinSep 9, 2020
  3. brian m. carlsonSep 9, 2020
  4. SZEDER GáborSep 9, 2020
  5. brian m. carlsonSep 9, 2020
  6. SZEDER GáborSep 10, 2020
  7. brian m. carlsonSep 11, 2020
  8. Jonathan NiederNov 4, 2020
  9. brian m. carlsonNov 5, 2020
  10. Jonathan NiederNov 6, 2020
  11. brian m. carlsonNov 6, 2020

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.