Restructered clone_customer_repository() and cd_customer_repository().
Fixed cd_home() to return explicitly to the customer repository, not only to -.
This commit is contained in:
parent
8f50f62a52
commit
bcc96a388f
161
git_helpers
161
git_helpers
@ -82,92 +82,104 @@ git_customer_branch () {
|
|||||||
#
|
#
|
||||||
clone_customer_repository () {
|
clone_customer_repository () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
if [ "$PWD" = "$WORKING_DIRECTORY" ]; then
|
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
|
||||||
mkdir -p "./$WORKSPACE_DIR"
|
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
|
||||||
# check if the directory is empty. If so, clone the
|
|
||||||
# customer repository
|
|
||||||
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
|
|
||||||
log_debug "$func:${LINENO} cloning ${1} ..."
|
|
||||||
if cd "./$WORKSPACE_DIR"
|
|
||||||
then
|
|
||||||
exec_git_command git clone "$1"
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
log_debug "$func:${LINENO} cloning ${1} done"
|
|
||||||
GIT_CLONE_EXECUTED=1
|
|
||||||
# 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
|
|
||||||
# configure hooks directory
|
|
||||||
exec_git_command git config core.hooksPath .githooks
|
|
||||||
exec_git_command git checkout "$LOCAL_BRANCH"
|
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
|
|
||||||
exec_git_command git config core.worktree "/"
|
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
log_debug "$func:${LINENO} configured worktree"
|
|
||||||
exec_git_command git fetch --all
|
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
log_debug "$func:${LINENO} fetch repository"
|
|
||||||
exec_git_command git reset --hard "$LOCAL_BRANCH"
|
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
|
|
||||||
CLONE_CUSTOMER_REPOSITORY=true
|
|
||||||
log_debug "$func:${LINENO} re-init of ${1} done"
|
|
||||||
cd_home; return 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
cd_home; return 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# the directory is not empty, so we assume the
|
|
||||||
# customer-repository has been cloned already
|
|
||||||
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
|
|
||||||
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
|
|
||||||
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
|
|
||||||
else
|
|
||||||
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
|
|
||||||
log_debug "$func:${LINENO} $__m"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
update_psa_clone_error # message to ISMAS
|
mkdir -p "./$WORKSPACE_DIR"
|
||||||
return $?
|
# check if the directory is empty. If so, clone the
|
||||||
|
# customer repository
|
||||||
|
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
|
||||||
|
log_info "$func:${LINENO} cloning ${1} ..."
|
||||||
|
if ! cd "./$WORKSPACE_DIR"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not change to $WORKSPACE_DIR"
|
||||||
|
fi
|
||||||
|
if ! exec_git_command git clone "$1"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not clone $1"
|
||||||
|
fi
|
||||||
|
########################## CLONING DONE ############################
|
||||||
|
log_debug "$func:${LINENO} cloning ${1} done"
|
||||||
|
# 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.
|
||||||
|
####################### CD INTO REPOSITORY ##########################
|
||||||
|
if ! cd ${CUSTOMER_ID_BASE_DIR}; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not change to $CUSTOMER_ID_BASE_DIR"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} cd into $CUSTOMER_ID_BASE_DIR"
|
||||||
|
##################### CONFIGURE HOOKS DIRECTORY ######################
|
||||||
|
if ! exec_git_command git config core.hooksPath .githooks; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not configure hooks directory"
|
||||||
|
fi
|
||||||
|
###################### CHECKOUT LOCAL BRANCH #########################
|
||||||
|
if ! exec_git_command git checkout "$LOCAL_BRANCH"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not checkout $LOCAL_BRANCH"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
|
||||||
|
######################## CONFIGURE WORKTREE ##########################
|
||||||
|
if ! exec_git_command git config core.worktree "/"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not configure worktree '/'"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} configured worktree '/'"
|
||||||
|
########################### FETCH ALL #################################
|
||||||
|
if ! exec_git_command git fetch --all; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not fetch --all for $LOCAL_BRANCH"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} fetch repository"
|
||||||
|
########################## RE-INIT REPOSITORY ########################
|
||||||
|
if ! exec_git_command git reset --hard "$LOCAL_BRANCH"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} re-init of $LOCAL_BRANCH failed"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
|
||||||
|
INITIAL_CLONE=true
|
||||||
|
log_debug "$func:${LINENO} re-init of ${1} done"
|
||||||
|
update_psa_clone_customer_repository
|
||||||
|
else
|
||||||
|
# the directory is not empty, so we assume the
|
||||||
|
# customer-repository has been cloned already
|
||||||
|
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
|
||||||
|
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
|
||||||
|
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
|
||||||
|
fi
|
||||||
|
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
|
||||||
|
log_info "$func:${LINENO} $__m, no clone necessary"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd_home
|
||||||
}
|
}
|
||||||
# clone_customer_repository ->
|
# clone_customer_repository ->
|
||||||
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git
|
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git
|
||||||
|
|
||||||
cd_customer_repository () {
|
cd_customer_repository () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
# has to be called in WORKING_DIRECTORY
|
|
||||||
cd "$WORKING_DIRECTORY"
|
|
||||||
if [ "$PWD" = "${WORKING_DIRECTORY}" ]; then
|
|
||||||
repository_dir="./$WORKSPACE_DIR/$CUSTOMER_ID"
|
|
||||||
if ! [[ -d "$repository_dir" ]]; then
|
|
||||||
log_crit "$func:${LINENO}: $repository_dir does not exist!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! { cd $repository_dir; } ; then
|
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
|
||||||
log_crit "$func:${LINENO}: cannot cd to $repository_dir!"
|
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: cd to $repository_dir!"
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
return 1
|
|
||||||
|
if ! [[ -d "$CUSTOMER_ID_BASE_DIR" ]]; then
|
||||||
|
log_fatal "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR does not exist!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! cd "$CUSTOMER_ID_BASE_DIR"; then
|
||||||
|
log_fatal "$func:${LINENO}: cannot cd to $CUSTOMER_ID_BASE_DIR !!!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_debug "$func:${LINENO}: cd to $CUSTOMER_ID_BASE_DIR"
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
cd_home () {
|
cd_home () {
|
||||||
if cd - &>/dev/null ; then
|
if cd "$WORKING_DIRECTORY" &>/dev/null ; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
@ -187,8 +199,7 @@ pull_customer_repository () {
|
|||||||
# changed files or opkg-commands to execute.
|
# changed files or opkg-commands to execute.
|
||||||
# If 'git pull' has fetched new data, then there are lines starting with
|
# If 'git pull' has fetched new data, then there are lines starting with
|
||||||
# DOWNLOAD or EXECUTE.
|
# DOWNLOAD or EXECUTE.
|
||||||
grep -E -q "^[[:space:]]*(DOWNLOAD|EXECUTE)" "$GIT_UPDATE_LOG"
|
if grep -qE "^[[:space:]]*(DOWNLOAD|EXECUTE)" "$GIT_UPDATE_LOG"; then
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
log_info "$func:${LINENO}: new data fetched from repository"
|
log_info "$func:${LINENO}: new data fetched from repository"
|
||||||
cd_home; return 0
|
cd_home; return 0
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user