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

gitattributes filter: add new %r that expands to repository root

From
CMCalum McConnell <calumlikesapplepie@gmail.com>
Date
Jan 22, 2021, 17:11 UTC
Message-ID
<508da412f239180b3cbfff4f676cc0072d04cd93.camel@gmail.com>
Dear Git Maintainers,

When building content filters with gitattributes, for instance to ensure git stores the plain-text rather than the binary form of data in certain formats, it is often advantageous to separate the filters into separate scripts. However, as the $PWD where content filters are executed is unspecified (at least, unspecified in the git documentation I could find), so the path to scripts needs to be specified as an absolute path. That means that the guide for setting up a repository which uses scripts to filter content cannot simply consist of "copy-paste the following lines to your .git/config file", and it means that the otherwise safe operation of moving a git repository from one folder to another is decidedly unsafe.

To fix this, I propose the addition of a "%r" sequence, similar to the existing "%f", which expands to the repository root (as opposed to the path of the file undergoing filtering). This would enable calls to content filter scripts to be (for instance) stored in a root /scripts folder, and the git-config value to be "sh %r/scripts/erase-all-secret- plots". If backwards compatibility is a serious concern, the sequence could only be expanded if it occurs at the beginning of the first two words.

I believe that would be simple to implement, and would be willing to do so myself, but wanted to get your views first.

Another useful addition, but one that would be less simple to implement would be the creation of a way for a set of default keys to be added to all repositories that clone from a certain remote. This could take the form of a .gitconfig-defaultkeys file in the root of the repository, which is appended to .git/config on clone, if there are core structural reasons that prevent a configuration file (even one with a restricted set of permitted keys) from being included in the tracked repository itself.

This is my first message to the git mailing list, so apologies if I did/said something wrong/stupid/obvious! Please give me feedback.

Thank you, Calum McConnell

Message 1 of 1 in “gitattributes filter: add new %r that expands to repository root”
  1. Calum McConnellJan 22, 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.