Why is my clean filter running instead of my smudge filter when I checkout a branch?

70 Views Asked by At

Background: I'm working on a repository that houses files needed for another program to run. Due to the nature of the other program, files that need to call other files have to do so with full file paths. All these files are stored in the repository, so I made a smudge/clean filter to change the file paths from a generic one to the path to repository location. This solution is required since multiple people may be cloning the repository to different locations to make modifications and test them.

Problem: The filter is working correctly, but the problem I'm encountering now is that whenever I checkout a new branch the clean filter is running instead of the smudge filter. From my understanding, the smudge filter should be the running at checkout, not the clean filter. Does anyone know why the clean filter is running when the smudge filter should and how to fix that?

Observations: No filters are used jumping from branches set up to use the filter and ones not setup to use the filter.

The smudge filter is used when jumping from a branch not setup to use filters to one setup yo use them.

The clean filter is used when switching between two branches that are setup to use the filter.

The smudge filter is run when a file is deleted and checkout again.

The clean filter is run seemingly at random when is run git status.

Confirmed which filters are being used on each file by setting GIT_TRACE=1 and looking at the line git is running as well as piping some updates from stdout to stderr in the filter script so that they appear in the command window.

1

There are 1 best solutions below

0
On

First, don't forget to consider alternative options which would avoid the need for content filters (smudge/clean) entirely.
If your program includes "files that need to call other files have to do so with full file paths", said files could use an environment variable in order to reference those other files (with an absolute path).
No need to "change the file paths from a generic one to the path to repository location" then.

Second, check if the issue persists when using git switch instead of the old and confusing git checkout command. This assumes you are using Git 2.23+ (Q3 2019)

Third, using a recent enough Git would also allow for the use of trace2 API.

export GIT_TRACE2=~/log.normal
git switch another Branch

# or

export GIT_TRACE2_EVENT=~/log.event
git switch another Branch

Those would include more details than just GIT_TRACE.