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__