From f248f3f85f3dc388192cec09ceeb1310ed0f6d3e Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 25 Apr 2023 10:50:10 +0200 Subject: [PATCH] try to use blob and commit for changed file --- .githooks/post-merge | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.githooks/post-merge b/.githooks/post-merge index 52b4ebb..3dbb445 100755 --- a/.githooks/post-merge +++ b/.githooks/post-merge @@ -23,28 +23,34 @@ get_blob () { # get the blob of the file(name) passed as $1 } get_commit_for_blob () { - blob=$(get_blob $1) - if [ ! -z $blob ]; then + if [ ! -z $1 ]; then # search for the blob in all commits for the file(name) $1 echo $(echo $(git log --all --pretty=format:%H -- $1) | xargs -I{} bash -c "git ls-tree {} -- $1 | - grep -q $blob && echo {}") + grep -q $1 && echo {}") fi } 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 } for fn in $(git diff-tree -r HEAD@{1} HEAD --name-only); do if grep -E -q "(DC.*json|dc.*hex|dc.*bin|tariff.*json)" <<< $fn; then - fsize=0 + # called in repository: $fn is e.g. etc/psa_tariff/tariff01.json + # add '/' prefix + fn=$(echo $fn | awk '{ printf "/"$0 }') if [[ -f "$fn" ]]; then + blob=$(get_blob "$fn") + commit=$(get_commit_for_blob $blob) fsize=$(ls -l "$fn" | awk '{ print $5 }') + echo "$fn $fsize $blob $commit" >> $GIT_PULL_TMP fi - echo "$fn $fsize" >> $GIT_PULL_TMP fi if grep -E -q ".*opkg_commands" <<< $fn; then readarray opkg_commands < <(cat $fn)