customer_281/.githooks/post-merge

62 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-03-27 16:10:41 +02:00
#!/bin/bash -
# FILE="/tmp/post-merge$(date +%FT%H-%M-%S)"
# commit=$(git rev-parse --verify HEAD)
# echo "$commit $(git cat-file commit $commit)" >> /tmp/post-merge
# Redirect output to stderr.
exec 1>&2
if [ -z $IFS ]; then
IFS=$'\n'
fi
GIT_PULL_TMP=/tmp/git_pull
OPKG_CMDS_TMP=/tmp/opkg_commands
2023-03-31 09:01:13 +02:00
rm -f $GIT_PULL_TMP
2023-03-27 16:10:41 +02:00
rm -f $OPKG_CMDS_TMP
get_blob () { # get the blob of the file(name) passed as $1
# note: this can be used for any file in the filesystem
echo $(git hash-object $1)
}
get_commit_for_blob () {
2023-04-25 11:01:22 +02:00
# search for the blob in all commits for the file(name) $1
2023-04-25 11:09:17 +02:00
echo $(git log --all --pretty=format:%H -- $1 | xargs -I{} bash -c "git ls-tree {} -- $1 | grep -q $1 && echo {}")
}
changed_file_names () {
for fn in $(git diff-tree -r HEAD@{1} HEAD --name-only); do
# called in repository: $fn is e.g. etc/psa_tariff/tariff01.json
# add '/' prefix
fn=$(echo $fn | awk '{ printf "/"$0 }')
CHANGED_FILE_NAMES+=($fn)
done
}
2023-03-27 16:10:41 +02:00
for fn in $(git diff-tree -r HEAD@{1} HEAD --name-only); do
2023-03-30 12:46:04 +02:00
if grep -E -q "(DC.*json|dc.*hex|dc.*bin|tariff.*json)" <<< $fn; then
# called in repository: $fn is e.g. etc/psa_tariff/tariff01.json
# add '/' prefix
fn=$(echo $fn | awk '{ printf "/"$0 }')
2023-03-31 10:13:16 +02:00
if [[ -f "$fn" ]]; then
blob=$(get_blob "$fn")
commit=$(get_commit_for_blob $blob)
2023-03-31 10:13:16 +02:00
fsize=$(ls -l "$fn" | awk '{ print $5 }')
2023-04-25 11:01:22 +02:00
echo "$fn $fsize b=$blob c=$commit" >> $GIT_PULL_TMP
2023-03-31 10:13:16 +02:00
fi
2023-03-27 16:10:41 +02:00
fi
if grep -E -q ".*opkg_commands" <<< $fn; then
readarray opkg_commands < <(cat $fn)
for opkg_c in "${opkg_commands[@]}"; do
test -z $opkg_c && continue;
test ! -z $(grep -E "^\s*[#]+.*$" <<< $opkg_c) && continue
echo -n "$opkg_c" | tr -d '\n\r' >> $OPKG_CMDS_TMP 2>&1
echo "" >> $OPKG_CMDS_TMP 2>&1
done
source "$fn"
fi
done