Fixed exec_git_command(), clone_customer_repository(), pull_customer_repository()
This commit is contained in:
parent
086a2c1585
commit
89ef5c69b6
91
git_helpers
91
git_helpers
@ -1,17 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# set -x
|
# set -x
|
||||||
|
|
||||||
source ./log_helpers.sh
|
# if [ ${git_helpers_sourced:-1} = "1" ]; then
|
||||||
|
# readonly git_helpers_sourced=${BASH_SOURCE[0]}
|
||||||
|
#else
|
||||||
|
# return 0
|
||||||
|
#fi
|
||||||
|
|
||||||
GIT_SSL_NO_VERIFY=true
|
|
||||||
|
# source ./log_helpers
|
||||||
|
|
||||||
|
readonly GIT_SSL_NO_VERIFY=true
|
||||||
|
readonly repository_already_up_to_date=2
|
||||||
|
|
||||||
#
|
#
|
||||||
exec_git_command () {
|
exec_git_command () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
log_debug "$func:${LINENO} exec-ing $1"
|
log_debug "$func:${LINENO} exec-ing [$*]"
|
||||||
|
|
||||||
exec {fd}< <($1)
|
exec {fd}< <($@)
|
||||||
local ps_pid=$! # remember pid of process substitution
|
local ps_pid=$! # remember pid of process substitution
|
||||||
|
|
||||||
local git_result=""
|
local git_result=""
|
||||||
@ -35,15 +43,13 @@ latest_commit () {
|
|||||||
local c=$(git reflog | grep "HEAD@{0}" | cut -d" " -f1)
|
local c=$(git reflog | grep "HEAD@{0}" | cut -d" " -f1)
|
||||||
if ! [ -z "$c" ]; then
|
if ! [ -z "$c" ]; then
|
||||||
if grep -qE "^[[:xdigit:]]{6,}$" <<< $c; then
|
if grep -qE "^[[:xdigit:]]{6,}$" <<< $c; then
|
||||||
log_debug "$func: commit -> $c"
|
log_debug "$func:${LINENO} commit -> $c"
|
||||||
printf "%s\n" $c
|
printf "%s\n" $c
|
||||||
else
|
else
|
||||||
log_crit "$func: wrong format for commit c=$c"
|
log_crit "$func:${LINENO} wrong format for commit c=$c"
|
||||||
printf ""
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
log_crit "$func: 'git reflog' result empty"
|
log_crit "$func:${LINENO} 'git reflog' result empty"
|
||||||
printf ""
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,10 +85,22 @@ clone_customer_repository () {
|
|||||||
# check if the directory is empty. If so, clone the
|
# check if the directory is empty. If so, clone the
|
||||||
# customer repository
|
# customer repository
|
||||||
if ! find ./workspace -mindepth 1 -maxdepth 1 | read; then
|
if ! find ./workspace -mindepth 1 -maxdepth 1 | read; then
|
||||||
log_debug "$func: cloning ${1} ..."
|
log_debug "$func:${LINENO} cloning ${1} ..."
|
||||||
( cd ./workspace && git clone "$1" ; )
|
if { cd ./workspace ; }; then
|
||||||
if [ $? -eq 0 ]; then
|
$(exec_git_command git clone "$1")
|
||||||
log_debug "$func: cloning ${1} done"
|
if [ $? -eq 0 ]; then
|
||||||
|
log_debug "$func:${LINENO} cloning ${1} done"
|
||||||
|
cd - ; return 0
|
||||||
|
fi
|
||||||
|
cd -
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# the directory is not empty, so we assume the customer-repository
|
||||||
|
# has been cloned alread
|
||||||
|
if ! [[ -d ./workspace/$customer_id ]]; then
|
||||||
|
local m="wrong repository: $(ls -d './workspace/*')"
|
||||||
|
log_fatal "$func:${LINENO} $m"
|
||||||
|
else
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -104,7 +122,7 @@ cd_customer_repository () {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! cd $repository_dir; then
|
if ! { cd $repository_dir; } ; then
|
||||||
log_crit "$func:${LINENO}: cannot change to $repository_dir!"
|
log_crit "$func:${LINENO}: cannot change to $repository_dir!"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -136,29 +154,22 @@ pull_customer_repository () {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
|
log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
|
||||||
|
|
||||||
exec {fd}< <(git pull)
|
local git_result=$(exec_git_command 'git pull')
|
||||||
local ps_pid=$! # remember pid of process substitution
|
|
||||||
|
|
||||||
local git_result=""
|
|
||||||
while read t <&$fd; do
|
|
||||||
if ! [ -z "$t" ]; then
|
|
||||||
git_result="${git_result}$t"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
exec {fd}>&- # close fd (i.e. process substitution)
|
|
||||||
wait $ps_pid # wait for the subshell to finish
|
|
||||||
|
|
||||||
if [ -z "$git_result" ]; then
|
if [ -z "$git_result" ]; then
|
||||||
log_warn "$func:${LINENO}: git result empty" ; cd_home;
|
log_warn "$func:${LINENO}: git result empty" ; cd_home;
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# see 'man -Pless\ +/parameter/pattern/string/bash'
|
||||||
|
git_result=${git_result//[$'\r\n\t']/ }
|
||||||
|
|
||||||
log_debug "$func:${LINENO} git-pull-result=${git_result}"
|
log_debug "$func:${LINENO} git-pull-result=${git_result}"
|
||||||
|
|
||||||
if [ "$git_result" = "Already up to date." ]; then
|
if grep -qE "^Already\s+\up\s+\to\s+date.*$" <<< $git_result; then
|
||||||
log_warn "$func:${LINENO}: $PWD already up to date."
|
log_warn "$func:${LINENO}: repository $PWD already up to date."
|
||||||
|
read $1 <<< 'yes'
|
||||||
cd_home ; return 1
|
cd_home ; return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -166,7 +177,7 @@ pull_customer_repository () {
|
|||||||
if [ -z $commit_after_pull ]; then
|
if [ -z $commit_after_pull ]; then
|
||||||
cd_home ; return 1
|
cd_home ; return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: commit_after_pull=$commit_after_pull"
|
log_debug "$func:${LINENO}: commit_after_pull=$commit_after_pull"
|
||||||
|
|
||||||
# Note: # 'git pull' is a 'git fetch' followed by a 'git merge'.
|
# Note: # 'git pull' is a 'git fetch' followed by a 'git merge'.
|
||||||
@ -228,14 +239,26 @@ pull_customer_repository () {
|
|||||||
cd_home ; return 1
|
cd_home ; return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
cd_home ; return 0
|
||||||
}
|
}
|
||||||
# pull_customer_repository customer_281
|
# pull_customer_repository customer_281
|
||||||
|
|
||||||
changed_files () {
|
changed_file_names () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
if cd_customer_repository ; then
|
if cd_customer_repository ; then
|
||||||
printf "%s\n" $(exec_git_command 'git diff --stat master@{1} master')
|
local git_res=$(exec_git_command 'git diff --stat master@{1} master')
|
||||||
cd_home
|
git_res=${git_res//[$'\r\n\t']/ }
|
||||||
|
log_debug "$func:${LINENO}: git_res=$git_res"
|
||||||
|
local file_names=""
|
||||||
|
for f in 'update.conf' 'opkg_commands' ; do
|
||||||
|
if grep -qE ".*${f}.*?" <<< $git_res; then
|
||||||
|
file_names="$f $file_names"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
cd_home ; printf "$file_names"
|
||||||
|
else
|
||||||
|
log_crit "$func:${LINENO}: cannot cd to $customer_repository "\
|
||||||
|
"while in $PWD"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user