1

I am trying to setup a filter so that on checkout it will inject some git related information to my file and on commit it will remove this information. I have verified that when I commit the file it is properly cleaned. Also if I delete the file and then do a checkout the file is properly smudged.

My problem is the following. If I make a change to the file and I commit the change, the smudge filter does not run. Is this the expected behavior? Is there a way to have the smudge filter run on commit? (perhaps by having a commit followed immediately by a checkout?)

2
  • "when I commit the file it is properly cleaned": so the filter does work on commit, yes?. But maybe he does not take into account what has been added to the index... Commented Sep 25, 2009 at 12:25
  • The clean filter works on commit and the smudge filter works on checkout. I was wondering if there is a way to have the smudge filter run after I commit so that information in the file that is related to the commit hash etc. is automatically updated. Commented Sep 25, 2009 at 13:01

1 Answer 1

9

A clean/smudge filter is definitely not the place for reliably adding commit based information into a work tree file. The reason - as you've discovered - is that the file won't be touched in operations that don't have to write a new version of the file into the work tree. You can merge or fast-forward many commits without the filter being applied if the given file hasn't been touched by those commits.

You would probably be better off with a template file that can be transformed to an ignored real file with embedded commit information by a build step which uses something like git rev-parse HEAD or git describe to retrieve the current commit information.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.