Git Extensions: rcs-keywords, smudge and clean filters

740 Views Asked by At

First of all, I must say that I'm quite new with Git. So I don't know all the tips&tricks yet... I have a following problem:

In a file I have certain rcs-keywords (for example $Date$, $Author$ and $Commit$). These keywords are supposed to be updated by using a smudge filter. The filter itself works as planned and requested information is updated into the file. But the issue is that it seems that when taking a pull (using Git Extensions) and the files are filtered through the smudge filter the data updated into the files is not the latest one (it's from the 2nd newest/latest commit). After the pull if I execute the commands that are doing the magic in the filter manually, the data is correct.

The question is: is there any way to get this latest/newest data updated into the files in a way I'm doing now?

And the way I'm doing it right now goes pretty much as instructed in https://github.com/kimmormh/git-rcs-keywords (some small changes related OS, I'm using Windows, and file paths including spaces).

Thanks in advance!

1

There are 1 best solutions below

0
On

When you pull, the smudge filter is run before the head is fast-forwarded. Many of the git commands operate on HEAD by default. In particular, the rcs-smudge filter that you are using, or basing you work on, does the following:

$rev = `git log -- $path | head -n 3`;

that's equivalent to,

$rev = `git log HEAD -- $path | head -n 3`;

while in your case it might have been more correct to do:

$rev = `git log FETCH_HEAD -- $path | head -n 3`;

to account for the commits that you are pulling from the remote.

However, note that in the case of a merge conflict the FETCH_HEAD will not become HEAD, rather a special merge commit will be created to join the FETCH_HEAD with the branch. In that case you might want to use the pre-commit hook (maybe together with a post-merge hook) to determine if you need to re-smudge the file again. Further while running the smudge filter you cannot know yet that there will be a merge conflict, so in a pre-commit hook you will have to undo the changes first.