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

Standardized escaping to store a .git in git?

From
Josh Triplett <josh@joshtriplett.org>
Date
May 19, 2021, 21:00 UTC
Message-ID
<YKV8hEAxIzolnROX@localhost>

On rare occasions, a project may need to store and version a .git directory in a git repository. For instance, a project that interacts with git repositories may need test cases. Or, a project using git to store backups may also want to back up git repositories. `.git` is the only filename that git can't transparently store and version.

I've seen projects take different approaches to work around this. For instance, the libgit2 project renames the `.git` directory to `.gitted`, and then their test framework copies that to a temporary directory as `.git`.

Would it make sense to have a standardized escaping mechanism for this, that git could then standardize the handling of in a safe way (taking both project configuration and local configuration into account)? Such a mechanism would not, by default, result in git checking out a `.git` directory verbatim, as that wouldn't be safe (due to hook scripts and due to searches for .git directories), but a user could configure their own system to do so for a specific project, tools like `git archive` could have a way to un-escape the directory in a generated archive, and references to objects within a treeish could use such paths. Standardizing this would allow tools to interoperate rather than each inventing their own convention.

(Note that today, git *can* successfully check in, version, update, and check out a bare repo.git directory, just not a non-bare .git directory.)

As one possible escaping (absolutely subject to bikeshedding):
- Reserve names starting with a specified character (e.g. \x01); call
  that escape character E.
- Encode filenames that actually start with E to start with EE
- Encode .git as E.git
- Require an opt-in to interpret this escaping; tools that don't
  interpret this escaping will still be able to operate on the files, in
  much the same way that it's possible to operate on a symlink as if it
  were a file containing the target path.

There are tradeoffs here: using a more type-able escape character would be convenient if a user ever had to deal with the raw name, but on the other hand, using a more type-able escape character would make the need to escape the escape character come up more often.

Regardless of the specific approach to escaping `.git`, does the general idea of standardizing such escaping across tools seem like something git could potentially do, to allow transparently storing *any* file or directory in a git repository?

- Josh Triplett
Next: Jonathan Nieder
Message 1 of 5 in “Standardized escaping to store a .git in git?”
  1. Josh TriplettMay 19, 2021
  2. Jonathan NiederMay 19, 2021
  3. Josh TriplettMay 19, 2021
  4. Jonathan NiederMay 19, 2021
  5. Josh TriplettMay 20, 2021

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.