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):
Anyway, smudge/clean does not give the immediate solution to the problem because of smaller technical shortcomings:
smudge filter is not passed a name of file being checked out, so it is not possible to exactly find the commit identifier.
However, this is alleviated by the fact that 'smudge' is only being run for the changed files, so the last commit is the needed one.
smudge filter is not passed a commit identifier. This is a bit more serious, as this information is nowhere to get from otherwise.
I tried to use 'HEAD' value, but apparently it is not yet updated at the moment 'smudge' is being run, so the files end up with the date of the "previous" commit rather than the commit being checked out.
"Previous" means the commit that was checked out before. The problem gets worse if different branch is checkout out, as the files get the timestamp of a previous branch.
AFAIR, lack of information in smudge filter was intentional, to discourage this particular use of smudge/clean mechanism. However, I think this can be reconsidered given the Peter's use case: "checkout-only" workspace for immediate publishing to webserver.
Alternatively, anyone interested in this use case could implement additional smudge arguments as a site-local patch.
And then, there are small annoyances, which seems to be inevitable: if you change 'clean' filter and check out earlier revision, it will be reported as having modifications (due to changed 'clean' definition).