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
115
git_helpers
115
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
|
||||||
|
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir -p "./$WORKSPACE_DIR"
|
mkdir -p "./$WORKSPACE_DIR"
|
||||||
# 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_DIR -mindepth 1 -maxdepth 1 | read; then
|
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
|
||||||
log_debug "$func:${LINENO} cloning ${1} ..."
|
log_info "$func:${LINENO} cloning ${1} ..."
|
||||||
if cd "./$WORKSPACE_DIR"
|
if ! cd "./$WORKSPACE_DIR"; then
|
||||||
then
|
update_psa_clone_error # message to ISMAS
|
||||||
exec_git_command git clone "$1"
|
log_fatal "$func:${LINENO} can not change to $WORKSPACE_DIR"
|
||||||
if [ $? -eq 0 ]; then
|
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"
|
log_debug "$func:${LINENO} cloning ${1} done"
|
||||||
GIT_CLONE_EXECUTED=1
|
|
||||||
# after cloning, cd into repository, and re-initialize,
|
# after cloning, cd into repository, and re-initialize,
|
||||||
# setting the work-tree as "/". This has the effect that
|
# setting the work-tree as "/". This has the effect that
|
||||||
# a "git pull" will automatically fetched files in the
|
# a "git pull" will automatically fetched files in the
|
||||||
# corresponding sytem-folders.
|
# corresponding sytem-folders.
|
||||||
if cd ${CUSTOMER_ID_BASE_DIR}; then
|
####################### CD INTO REPOSITORY ##########################
|
||||||
# configure hooks directory
|
if ! cd ${CUSTOMER_ID_BASE_DIR}; then
|
||||||
exec_git_command git config core.hooksPath .githooks
|
update_psa_clone_error # message to ISMAS
|
||||||
exec_git_command git checkout "$LOCAL_BRANCH"
|
log_fatal "$func:${LINENO} can not change to $CUSTOMER_ID_BASE_DIR"
|
||||||
if [[ $? -eq 0 ]]; then
|
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"
|
log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
|
||||||
exec_git_command git config core.worktree "/"
|
######################## CONFIGURE WORKTREE ##########################
|
||||||
if [[ $? -eq 0 ]]; then
|
if ! exec_git_command git config core.worktree "/"; then
|
||||||
log_debug "$func:${LINENO} configured worktree"
|
update_psa_clone_error # message to ISMAS
|
||||||
exec_git_command git fetch --all
|
log_fatal "$func:${LINENO} can not configure worktree '/'"
|
||||||
if [[ $? -eq 0 ]]; then
|
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"
|
log_debug "$func:${LINENO} fetch repository"
|
||||||
exec_git_command git reset --hard "$LOCAL_BRANCH"
|
########################## RE-INIT REPOSITORY ########################
|
||||||
if [[ $? -eq 0 ]]; then
|
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"
|
log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
|
||||||
CLONE_CUSTOMER_REPOSITORY=true
|
INITIAL_CLONE=true
|
||||||
log_debug "$func:${LINENO} re-init of ${1} done"
|
log_debug "$func:${LINENO} re-init of ${1} done"
|
||||||
cd_home; return 0
|
update_psa_clone_customer_repository
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
cd_home; return 1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# the directory is not empty, so we assume the
|
# the directory is not empty, so we assume the
|
||||||
# customer-repository has been cloned already
|
# customer-repository has been cloned already
|
||||||
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
|
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
|
||||||
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
|
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
|
||||||
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
|
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
|
||||||
else
|
fi
|
||||||
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
|
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
|
||||||
log_debug "$func:${LINENO} $__m"
|
log_info "$func:${LINENO} $__m, no clone necessary"
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
update_psa_clone_error # message to ISMAS
|
cd_home
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
# 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
|
||||||
if [ "$PWD" = "${WORKING_DIRECTORY}" ]; then
|
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
|
||||||
repository_dir="./$WORKSPACE_DIR/$CUSTOMER_ID"
|
|
||||||
if ! [[ -d "$repository_dir" ]]; then
|
|
||||||
log_crit "$func:${LINENO}: $repository_dir does not exist!"
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! { cd $repository_dir; } ; then
|
if ! [[ -d "$CUSTOMER_ID_BASE_DIR" ]]; then
|
||||||
log_crit "$func:${LINENO}: cannot cd to $repository_dir!"
|
log_fatal "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR does not exist!"
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: cd to $repository_dir!"
|
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
|
return 0
|
||||||
fi
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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