clone_customer_repository: re-initailize repository after cloning. Copy

.githhoks/post-merge hook into .git/hooks/. post-merge will list the
names of changed files and write them to /tmp/git-pull.
The existence of /tmp/git-pull shows that there have been received changed files.
This commit is contained in:
Gerhard Hoffmann 2022-06-09 18:34:31 +02:00
parent cfce4ae53c
commit 83aa2dbd5c

View File

@ -83,14 +83,26 @@ clone_customer_repository () {
$(exec_git_command git clone "$1")
if [ $? -eq 0 ]; then
log_debug "$func:${LINENO} cloning ${1} done"
local res=$(exec_git_command git --git-dir="${CUSTOMER_ID_BASE_DIR}/.git" --work-tree="/" init)
if ! [[ -z $res ]]; then
CLONE_CUSTOMER_REPOSITORY=true
log_debug "$func:${LINENO} re-init of ${1} done"
cd -; return 0
# after cloning, cd into repository, and re-initialize,
# setting the work-tree as "/". This has the effect that
# a "git pull" will automatically fetched files in the
# corresponding sytem-folders.
if cd ${CUSTOMER_ID_BASE_DIR}; then
local res=$(exec_git_command git --git-dir=.git --work-tree=/ init)
if ! [[ -z $res ]]; then
# re-initialized. copy post-merge (a hook called
# when 'git pull' is executed and changed data
# are received).
if cp ".githooks/post-merge" ".git/hooks"; then
log_debug "$func:${LINENO} copied post-merge to .git/hooks"
CLONE_CUSTOMER_REPOSITORY=true
log_debug "$func:${LINENO} re-init of ${1} done"
cd_home; return 0
fi
fi
fi
fi
cd -
cd_home; return 1
fi
else
# the directory is not empty, so we assume the
@ -148,109 +160,27 @@ pull_customer_repository () {
return 1
fi
local commit_before_pull=$(latest_commit)
if [ -z $commit_before_pull ]; then
log_warn "$func:${LINENO}: commit_before_pull empty"
cd_home ; return 1
fi
log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
#local commit_before_pull=$(latest_commit)
#if [ -z $commit_before_pull ]; then
# log_warn "$func:${LINENO}: commit_before_pull empty"
# cd_home ; return 1
#fi
#log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
rm -f "$OPKG_CMDS_TMP"
rm -f "$GIT_PULL_TMP"
log_debug "$func:${LINENO}: executing 'git pull'..."
local git_result=$(exec_git_command 'git pull')
exec_git_command 'git pull'
if [ -z "$git_result" ]; then
log_warn "$func:${LINENO}: git result empty" ; cd_home;
return 1
# GIT_PULL_TMP created by hook post-merge. it contains the names of the
# changed files.
if [[ -f $GIT_PULL_TMP ]]; then
cd_home; return 0
fi
# see https://www.gnu.org/
# software/bash/manual/html_node/Shell-Parameter-Expansion.html
# [...]
#
# ${parameter//pattern/string}
#
# If there are two slashes separating parameter and pattern (...),
# all matches of pattern are replaced with string.
#
# If the expansion of string is null, matches of pattern are deleted.
# [...]
git_result=${git_result//[$'\r\n\t']/ }
log_debug "$func:${LINENO} git-pull-result=${git_result}"
if grep -qE "^.*?Already\s+\up\s+\to\s+date.*$" <<< "$git_result"; then
log_warn "$func:${LINENO}: repository $PWD already up to date."
read $1 <<< 'yes'
cd_home ; return 1
fi
local commit_after_pull=$(latest_commit)
if [ -z $commit_after_pull ]; then
cd_home ; return 1
fi
log_debug "$func:${LINENO}: commit_after_pull=$commit_after_pull"
# Note: # 'git pull' is a 'git fetch' followed by a 'git merge'.
# Here's the fetch portion:
#
# remote: Counting objects: 11, done.
# remote: Compressing objects: 100% (5/5), done.
# remote: Total 7 (delta 2), reused 0 (delta 0)
#
# At this point, you've told the remote what you want.
# It finds all the objects it needs to give you,
# compresses them for faster transfer over the network,
# and then reports what it's sending you.
#
# Unpacking objects: 100% (7/7), done.
#
# You receive the pack (set of compressed objects) and unpack it.
#
# From ssh://my.remote.host.com/~/git/myproject
# * branch master -> FETCH_HEAD
# You've fetched the branch 'master' from the given remote;
# the ref FETCH_HEAD now points to it.
# Now we move on to the merge - precisely, git will merge
# FETCH_HEAD (the remote's master branch) into your current branch
# (presumably master).
#
#######################################################################
# here starts "message"
#
# Updating 9d447d2..f74fb21
# Fast forward
#
# It turns out that you haven't diverged from the remote's master branch,
# so the merge is a fast-forward (a trivial merge where it simply moves
# you forward in the history).
#
# Git notes the original position of your master branch (9d447d2)
# and the new position (f74fb21) it's been fast-forwarded to.
# If you had diverged from the remote's master branch,
# you'd see the output of a recursive merge here - Merge made
# by recursive, possibly along with some Auto-merged <file>
# and (oh no!) merge conflicts!
#
# szeged/1/1/etc/psa_config/device.conf | 13 +++++++------
# szeged/update.conf | 2 +-
# 2 files changed, 8 insertions(+), 7 deletions(-)
#
# Finally, it shows you the diffstat between the original and post-merge
# position of your master branch;
# this is basically what you'd get from
#
# git diff --stat master@{1} master.
#
update_commit="${commit_before_pull}..${commit_after_pull}"
if ! grep -qE ".*Updating\s+${update_commit}.*?" <<< $git_result; then
log_crit "$func:${LINENO}: no $update_commit in [ $git_result ]"
cd_home ; return 1
fi
cd_home ; return 0
log_warn "$func:${LINENO}: no data fetched form repository"
cd_home; return 1
}
# pull_customer_repository customer_281