The first problem here is that the --msg-filter
is run with no index in place:
if test -n "$filter_index" ||
test -n "$filter_tree" ||
test -n "$filter_subdir"
then
need_index=t
else
need_index=
fi
Since you have only a $filter_msg
—in fact, git filter-branch
always has one, it's just that it's cat
by default—this leaves need_index
set to the empty string, so then later, as filter-branch
is iterating through every commit to be copied (this, like the above, is snipped from git-filter-branch.sh
):
while read commit parents; do
[snip]
if test -n "$need_index"
then
GIT_ALLOW_NULL_SHA1=1 git read-tree -i -m $commit
fi
[snip]
Since the tree for the commit has not been read into the index, git ls-files
(which reads the index) finds nothing.
The simplest method is to use git ls-tree -r $GIT_COMMIT_ID
instead of git ls-files
.
This gets us to the second problem:
value=$(git ls-files -s | grep -v "folderX" | grep -q .)
I am not sure what you are trying to test here, but grep -q
never produces any output, only an exit status. Thus, value
will always be set to the empty string.
Also, there seems to be no reason to inspect the stage numbers and hashes (-s
). The stage number would always be zero if we had an index, since, despite the -m
option, we're not actually merging any trees here. You said:
... [flag] all the commits affecting a given part of my repository
and "affecting" usually means "modifying", which means "modifying with respect to something" (since each commit is a snapshot, it must be compared against some other commit in order to see what changed).
The choice for what to compare against is easy for most ordinary, single-parent commits: we just compare it against its (single) parent. It's less obvious for root commits, but we usually want to compare them against the empty tree (see Is git's semi-secret empty tree object reliable, and why is there not a symbolic name for it?). It's least obvious for merges: do we compare against first parent, or all parents? If all parents, do we consider a file modified if it's changed against any of them, or only if it is changed against all of them?
In any case, you will probably want to do something more complex here than just test whether some file(s) exist in the snapshot. Whatever that test turns out to be, you probably want your message filter to be simpler once the test completes:
--msg-filter 'some-test-here && echo -n "[flag] "; cat'