this scripts applies keyword expansions to git cache with minimum lines.
a bash script to patch keywords expansions with git apply
.
you can save this into your .bashrc and use as bash functions.
function gitapplykw_one() {
if [[ "$1" == -f ]] ; then
shift 1
elif [[ "$(file $1)" != *text ]] ; then
return
fi
kw_date=$(date --rfc-3339=seconds)
kw_rev=$(git count HEAD)-$(git rev-parse --short=10 HEAD)
#tmp=".tmp/$(echo $1 | sed 's/\////g').$(date '+%Y%m%d-%H%M%S')"
tmp=".tmp/$(echo $1 | sed 's/\////g')"
mkdir -p .tmp
git show ":$1" > "$tmp"
sed -i "s/\\\$Date:[-_+ :A-Za-z0-9]*\\\$/\$Date: ${kw_date} \$/" "$tmp"
sed -i "s/\\\$Rev:[-_+ :A-Za-z0-9]*\\\$/\$Rev: ${kw_rev} \$/" "$tmp"
git show ":$1" | diff -u /dev/stdin "$tmp" \
| (echo diff --git a/$1 b/$1
echo "index 0000..0000 100644"
echo "--- a/$1"
echo "+++ b/$1"
tail -n +3
) | tee $tmp.patch | git apply --index # --cached
}
search staged files and patch keywords expansions to them.
function gitapplykw() {
git st -s --ignore-submodules | sed -n 's/^M \+//p' \
| while read line; do
gitapplykw_one "$line"
done
}
function gitcommit() {
gitapplykw
git commit $*
}