Issue
I'm trying to increment a value within a file when it gets staged. I'm using clean filter with:
*.txt filter=increv
in .gitattributes
and the following in my .git/config
[filter "increv"]
clean = sh 'inc_rev'
inc_rev
has
#!/bin/sh
STDIN=$(cat)
[[ $STDIN =~ (MyRev_)([0-9]{12}) ]]
i=${BASH_REMATCH[1]} #group i'd like to keep to put back in
j=${BASH_REMATCH[2]} #part i need to increment
[[ $j =~ ^0*([^0]+.*$) ]]
k=${BASH_REMATCH[1]} #trim away the 0's
m=$((k+1)) #increments
printf -v n "%012d" $m #repads the 0's into $n
echo STDIN | sed 's|MyRev_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|$i$n|g'
And the line I'm trying to increment in *.txt files:
TEXT "MyRev_000000000019"
My problem is the substitution is not happening and I'm not sure how to debug.
When I run git status
I can see that my script inc_rev
is getting called becuase if there's any problem with the script it will return an error in the git status
message.
UPDATE1: shell is bash
UPDATE2: here's the result of the following commands:
issuing git config filter.increv.clean
yields bash inc_rev
issuing git check-attr -a *.txt
yields test.txt: filter: increv
Solution
I suspect the filter is running just fine. Clean filters produce the content that will be added to the repo, they don't touch what's in your work tree. Say git cat-file blob :test.txt
to check what's indexed there.
If your build system's make
, add a makefile bump
target that bumps the version number and adds it, otherwise whatever recipe system you're using it'll have some equivalent, use that.
Answered By - jthill Answer Checked By - Gilberto Lyons (WPSolving Admin)