From 106f79399a3824e2dae82a46018cdb0bb9b4cb25 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 9 Jul 2025 14:17:54 +0900 Subject: [PATCH] Update clone new to write to log file, also write more information post clone --- src/bin/new_clone.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/bin/new_clone.sh b/src/bin/new_clone.sh index 333cc37..600fc65 100755 --- a/src/bin/new_clone.sh +++ b/src/bin/new_clone.sh @@ -58,11 +58,23 @@ if [ $error -eq 1 ]; then exit; fi; -# from the repository get the last path without the .git so we have the target folder -GIT_REPOSITORY_FOLDER=$(basename "${REPOSITORY}" .git); +unique_id=$(uuidgen | tr -d '-' | head -c 8); -echo "* New clone from ${REMOTE_HOST}:${REPOSITORY}::${BRANCH} into ${GIT_REPOSITORY_FOLDER}"; -GIT_COMMAND=("${GIT_COMMAND_BASE[@]}" "clone" "-b" "${BRANCH}" "--single-branch" "--depth" "1" "--origin" "${REMOTE_NAME}" "${REMOTE_HOST}:${REPOSITORY}" "${GIT_WEBHOOK_BASE_FOLDER}${CLONE_BASE}${GIT_REPOSITORY_FOLDER}") -"${GIT_COMMAND[@]}"; +LOG_FILE="${GIT_WEBHOOK_BASE_FOLDER}${LOG_FOLDER}${REPOSITORY}.log"; +# from the repository get the last path without the .git so we have the target folder +GIT_REPOSITORY_NAME=$(basename "${REPOSITORY}" .git); +echo "[$(date +"%Y-%m-%d %H:%M:%S")] [${unique_id}] [START] New clone from ${REMOTE_HOST}:${REPOSITORY}::${BRANCH} into ${GIT_REPOSITORY_NAME}" | tee -a "$LOG_FILE"; +# clone everything +GIT_COMMAND=("${GIT_COMMAND_BASE[@]}" "clone" "-b" "${BRANCH}" "--single-branch" "--depth" "1" "--origin" "${REMOTE_NAME}" "${REMOTE_HOST}:${REPOSITORY}" "${GIT_WEBHOOK_BASE_FOLDER}${CLONE_BASE}${GIT_REPOSITORY_NAME}") +"${GIT_COMMAND[@]}" 2>&1 | tee -a "$LOG_FILE"; +# set the repository folder +GIT_REPOSITORY_FOLDER="${GIT_WEBHOOK_BASE_FOLDER}${CLONE_BASE}${GIT_REPOSITORY_NAME}"; +# show origin info +GIT_COMMAND=("${GIT_COMMAND_BASE[@]}" "-C" "${GIT_REPOSITORY_FOLDER}" remote show "${REMOTE_NAME}" ); +"${GIT_COMMAND[@]}" 2>&1 | tee -a "$LOG_FILE"; +# get last log entry +GIT_COMMAND=("${GIT_COMMAND_BASE[@]}" "-C" "${GIT_REPOSITORY_FOLDER}" log -n 1 --pretty=short --no-color); +"${GIT_COMMAND[@]}" 2>&1 | tee -a "$LOG_FILE"; +echo "[$(date +"%Y-%m-%d %H:%M:%S")] [${unique_id}] [FINISH] clone completed" | tee -a "$LOG_FILE"; # __END__