I am considering migrating from subversion to git. One of the things we use subversion for our sysadmins to manage things like configuration files. To that end, we put $URL$
into each file, which expands to the file's location in the subversion tree. This lets the admins look at a file on some arbitrary host and figure out where in the tree it came from.
The closest analog I could find is gitattributes. There is the filter=
directive, but it seems that git doesn't communicate to the filter what filename it's filtering, which would be necessary to turn $URL$
into a path.
There is also the ident
directive, which would turn $Id$
into the blob hash. This might be usable if one could map that back into a pathname, but my git-fu isn't strong enough.
Any suggestions?
The workflow is as follows:
- Admin commits changes to the VCS repo
- Admin updates a central location that has checked out the repo
- Admin pulls the changes to the host using cfengine
Since there is nowadays the
%f
option, scripts like git-rcs-keywords can do the task.It is already mentioned in this answer.
gitattributes(5) manpage:
Coming at the problem from a completely different angle, how do the files in question end up on the end hosts? I guess today it is either checked out there directly, or copied somehow from an already checked out repository on another host?
If so, could you modify your process so that files are checked out to a git repository, and a script does the
$URL$
or other keyword expansion after checkout. That way you can do whatever substitutions you like, and only be limited by what can be figured out by a script in a checked out repository.As mentioned in "Does git have anything like
svn propset svn:keywords
or pre-/post-commit hooks?", Git does not support keyword expansion."Dealing with SVN keyword expansion with git-sv" provides a solution based on
git config filter
(which is not exactly what you want) and/or gitattributes.The closest example if file information expansion I have found it still based on the smudge/clean approach, with this git Hash filter, but the clean part removes it from the file, and no path can be found.
This thread actually spells it out (as well as mentioning some git-fu commands which might contain what you are looking for, I have not tested them):
We use a "canonical path" solution in our deployments (they are all internal, FWIW).
All software goes in e.g. /d/sw/xyz/a.c or D:\SW\xyz\a.c
All URLs to the deployed files reflect that e.g. http://host/d/sw/xyz/a.c.
URLs to the repository files start at "sw" e.g. git://githost/gitrepo/xyz/a.c
We encode these canonical paths in the configuration (should it ever need to change), and we have scripts/APIs that generate/reference the URLs on the fly for dynamic linking among components.