Commit 1b1b1c91 authored by Emeric Verschuur's avatar Emeric Verschuur

Improve git worktree support and preserve the working directory on shell mode

parent 5d70810f
......@@ -627,21 +627,21 @@ if [ "$GIT_SUBMODULE_STRATEGY" != "none" ]; then
;;
esac
print_info "Fetching git submodules..."
git submodule sync "${GIT_SUBMODULE_ARGS[@]}" > /dev/null
git submodule --quiet sync "${GIT_SUBMODULE_ARGS[@]}"
git submodule update --init "${GIT_SUBMODULE_ARGS[@]}"
fi
if [ "$CITBX_GIT_CLEAN" == "true" ]; then
git clean -fdx
if [ "$GIT_SUBMODULE_STRATEGY" != "none" ]; then
git submodule foreach "${GIT_SUBMODULE_ARGS[@]}" git clean -fdx
git submodule --quiet foreach "${GIT_SUBMODULE_ARGS[@]}" git clean -fdx
fi
fi
if [ "$CITBX_GIT_LFS_ENABLED" == "true" ]; then
git lfs pull
if [ "$GIT_SUBMODULE_STRATEGY" != "none" ]; then
git submodule foreach "${GIT_SUBMODULE_ARGS[@]}" git lfs pull
git submodule --quiet foreach "${GIT_SUBMODULE_ARGS[@]}" git lfs pull
fi
fi
......@@ -805,13 +805,26 @@ case "$CITBX_JOB_EXECUTOR" in
sleep $wait_before_run_job
fi
print_info "Running the job $CI_JOB_NAME into the $CITBX_DOCKER_IMAGE docker container..."
# Add project dir mount
CITBX_JOB_DOCKER_RUN_ARGS+=(-v "$CI_PROJECT_DIR:$CI_PROJECT_DIR:rw")
GIRDIR_PATH=$(readlink -f $(git rev-parse --git-common-dir))
if [ "${GIRDIR_PATH#$CI_PROJECT_DIR}" == "$GIRDIR_PATH" ]; then
# If the git dir is ouside the project dir
CITBX_JOB_DOCKER_RUN_ARGS+=(-v "$GIRDIR_PATH:$GIRDIR_PATH:rw")
fi
if [ "$CITBX_RUN_SHELL" == "true" ]; then
print_info "Running a shell into the $CITBX_DOCKER_IMAGE docker container..."
CITBX_JOB_DOCKER_RUN_ARGS+=(-w "$PWD")
else
print_info "Running the job $CI_JOB_NAME into the $CITBX_DOCKER_IMAGE docker container..."
CITBX_JOB_DOCKER_RUN_ARGS+=(-w "$CI_PROJECT_DIR")
fi
# Run the docker
docker run --rm -ti --name="$CITBX_DOCKER_PREFIX-build" --hostname="$CITBX_DOCKER_PREFIX-build" \
-e CI=true -e GITLAB_CI=true -v /var/run/docker.sock:/var/run/docker.sock \
-v "$CI_PROJECT_DIR:$CI_PROJECT_DIR:rw" -w "$CI_PROJECT_DIR" "${CITBX_DOCKER_RUN_ARGS[@]}" \
--label "$CITBX_DOCKER_PREFIX" "${CITBX_JOB_DOCKER_RUN_ARGS[@]}" \
"${CITBX_DOCKER_RUN_ARGS[@]}" --label "$CITBX_DOCKER_PREFIX" "${CITBX_JOB_DOCKER_RUN_ARGS[@]}" \
-e DOCKER_RUN_EXTRA_ARGS="$(bashopts_get_def bashopts_extra_args)" \
"${bashopts_extra_args[@]}" $CITBX_DOCKER_IMAGE "${CITBX_PRE_COMMANDS[@]}" sh -c "$CITBX_COMMANDS"
;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment