diff --git a/plugins/certs/post-app-clone-setup b/plugins/certs/post-app-clone-setup index a0b5918a5..f9e302a9d 100755 --- a/plugins/certs/post-app-clone-setup +++ b/plugins/certs/post-app-clone-setup @@ -6,9 +6,9 @@ trigger-certs-post-app-clone-setup() { declare desc="removes cert file when setting up a clone" declare trigger="post-app-clone-setup" declare OLD_APP="$1" NEW_APP="$2" - local APP_DIR="$DOKKU_ROOT/$NEW_APP" + local APP_ROOT="$DOKKU_ROOT/$NEW_APP" - rm -rf "$APP_DIR/tls" + rm -rf "$APP_ROOT/tls" plugn trigger post-certs-remove "$NEW_APP" } diff --git a/plugins/domains/post-app-clone-setup b/plugins/domains/post-app-clone-setup index a8ff2bcc5..6b3968e21 100755 --- a/plugins/domains/post-app-clone-setup +++ b/plugins/domains/post-app-clone-setup @@ -6,9 +6,9 @@ trigger-domains-post-app-clone-setup() { declare desc="removes domain files when setting up a clone" declare trigger="post-app-clone-setup" declare OLD_APP="$1" NEW_APP="$2" - local APP_DIR="$DOKKU_ROOT/$NEW_APP" + local APP_ROOT="$DOKKU_ROOT/$NEW_APP" - rm -rf "$APP_DIR/URLS" "$APP_DIR/VHOST" + rm -rf "$APP_ROOT/URLS" "$APP_ROOT/VHOST" } trigger-domains-post-app-clone-setup "$@" diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index e0c567e49..5dd4d5a27 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -43,7 +43,7 @@ cmd-git-sync() { fi local APP_ROOT="$DOKKU_ROOT/$APP" - if [[ "$(git -C "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then + if [[ "$(fn-git-cmd "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF" else fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF" @@ -51,7 +51,7 @@ cmd-git-sync() { if [[ "$FLAG" == "--build" ]]; then if [[ -n "$GIT_REF" ]]; then - GIT_REF="$(git -C "/home/dokku/$APP" rev-parse "$GIT_REF")" + GIT_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$GIT_REF")" plugn trigger receive-app "$APP" "$GIT_REF" else plugn trigger receive-app "$APP" @@ -97,7 +97,7 @@ cmd-git-report() { cmd-git-report-single() { declare APP="$1" INFO_FLAG="$2" - local APP_DIR="$DOKKU_ROOT/$APP" + local APP_ROOT="$DOKKU_ROOT/$APP" if [[ "$INFO_FLAG" == "true" ]]; then INFO_FLAG="" fi @@ -107,7 +107,7 @@ cmd-git-report-single() { "--git-global-deploy-branch: $(fn-plugin-property-get "git" "--global" "deploy-branch" "master")" "--git-keep-git-dir: $(fn-plugin-property-get "git" "$APP" "keep-git-dir" "false")" "--git-rev-env-var: $(fn-plugin-property-get "git" "$APP" "rev-env-var" "GIT_REV")" - "--git-sha: $(git -C "$APP_DIR" rev-parse --short HEAD 2>/dev/null || false)" + "--git-sha: $(fn-git-cmd "$APP_ROOT" rev-parse --short HEAD 2>/dev/null || false)" "--git-last-updated-at: $(fn-git-last-updated-at "$APP")" ) @@ -143,7 +143,7 @@ fn-git-create-hook() { local PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" if [[ ! -d "$APP_PATH/refs" ]]; then - git init -q --bare "$APP_PATH" >/dev/null + suppress_output git init -q --bare "$APP_PATH" fi cat >"$PRERECEIVE_HOOK" </dev/null - git -C "$APP_CLONE_ROOT" checkout -qq "$GIT_REF" + suppress_output git clone -n -qq "$GIT_REMOTE" "$APP_CLONE_ROOT" + fn-git-cmd "$APP_CLONE_ROOT" checkout -qq "$GIT_REF" else - git clone -n -qq --branch "$GIT_REF" "$GIT_REMOTE" "$APP_CLONE_ROOT" 2>/dev/null - if git -C "$APP_CLONE_ROOT" show-ref --verify "refs/heads/$GIT_REF" >/dev/null 2>&1; then + suppress_output git clone -n -qq --branch "$GIT_REF" "$GIT_REMOTE" "$APP_CLONE_ROOT" + if fn-git-cmd "$APP_CLONE_ROOT" show-ref --verify "refs/heads/$GIT_REF" >/dev/null 2>&1; then dokku_log_verbose "Detected branch, setting deploy-branch to $GIT_REF" fn-plugin-property-write "git" "$APP" "deploy-branch" "$GIT_REF" fi @@ -196,38 +196,51 @@ fn-git-clone() { DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" if [[ "$GIT_REF" != "$DOKKU_DEPLOY_BRANCH" ]]; then if [[ "$is_ref" == "true" ]]; then - git -C "$APP_CLONE_ROOT" branch -qq -D "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true + fn-git-cmd "$APP_CLONE_ROOT" branch -qq -D "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true fi - git -C "$APP_CLONE_ROOT" checkout -qq -b "$DOKKU_DEPLOY_BRANCH" + + fn-git-cmd "$APP_CLONE_ROOT" checkout -qq -b "$DOKKU_DEPLOY_BRANCH" fi rsync -a "$APP_CLONE_ROOT/.git/" "$APP_ROOT" fn-git-create-hook "$APP" } +fn-git-cmd() { + declare GIT_DIR="$1" + local exit_code="1" + shift 1 + + pushd "$GIT_DIR" >/dev/null + git "$@" + exit_code="$?" + popd >/dev/null 2>&1 || pushd "/tmp" >/dev/null + return $exit_code +} + fn-git-fetch() { declare APP="$1" GIT_REMOTE="$2" GIT_REF="$3" local DOKKU_DEPLOY_BRANCH local APP_ROOT="$DOKKU_ROOT/$APP" - if [[ "$(git -C "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then + if [[ "$(fn-git-cmd "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then dokku_log_fail "The fetch subcommand can only be executed for existing applications" fi DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" - if ! git -C "$APP_ROOT" check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then + if ! fn-git-cmd "$APP_ROOT" check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then echo $'\e[1G\e[K'"-----> WARNING: Invalid branch name '$DOKKU_DEPLOY_BRANCH' specified via DOKKU_DEPLOY_BRANCH." echo $'\e[1G\e[K'"-----> For more details, please see the man page for 'git-check-ref-format.'" return fi - git -C "$APP_ROOT" remote rm remote >/dev/null 2>&1 || true - git -C "$APP_ROOT" remote add --mirror=fetch --no-tags remote "$GIT_REMOTE" + fn-git-cmd "$APP_ROOT" remote rm remote >/dev/null 2>&1 || true + fn-git-cmd "$APP_ROOT" remote add --mirror=fetch --no-tags remote "$GIT_REMOTE" if [[ -z "$GIT_REF" ]]; then - git -C "$APP_ROOT" fetch --update-head-ok remote "$DOKKU_DEPLOY_BRANCH" + fn-git-cmd "$APP_ROOT" fetch --update-head-ok remote "$DOKKU_DEPLOY_BRANCH" else - git -C "$APP_ROOT" fetch --update-head-ok remote - git -C "$APP_ROOT" update-ref "refs/heads/$DOKKU_DEPLOY_BRANCH" "$GIT_REF" + fn-git-cmd "$APP_ROOT" fetch --update-head-ok remote + fn-git-cmd "$APP_ROOT" update-ref "refs/heads/$DOKKU_DEPLOY_BRANCH" "$GIT_REF" fi } @@ -276,51 +289,66 @@ fn-git-setup-build-dir() { fn-git-setup-build-dir-new() { declare APP="$1" GIT_WORKDIR="$2" REV="$3" + local APP_ROOT="$DOKKU_ROOT/$APP" local DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" + # unset the git quarantine path to allow us to use 2.13.0+ + # See this issue for more information: https://github.com/dokku/dokku/issues/2796 + unset GIT_QUARANTINE_PATH + # repo workaround from https://gitlab.com/gitlab-org/gitlab-foss/-/issues/52249 # and https://docs.gitlab.com/ee/user/project/repository/repository_mirroring.html#preventing-conflicts-using-a-pre-receive-hook - env -u GIT_QUARANTINE_PATH git -C "$DOKKU_ROOT/$APP" archive "$REV" | tar x --warning=none -C "${GIT_WORKDIR}" - suppress_output env -u GIT_QUARANTINE_PATH git -C "$GIT_WORKDIR" clone --bare "$DOKKU_ROOT/$APP" .git - suppress_output env -u GIT_QUARANTINE_PATH git -C "$GIT_WORKDIR" config --local gc.auto 0 - suppress_output env -u GIT_QUARANTINE_PATH git -C "$GIT_WORKDIR" config --local --bool core.bare false - suppress_output env -u GIT_QUARANTINE_PATH git -C "$GIT_WORKDIR" config --local receive.denyCurrentBranch ignore - suppress_output env -u GIT_QUARANTINE_PATH git -C "$GIT_WORKDIR" symbolic-ref HEAD "refs/heads/$DOKKU_DEPLOY_BRANCH" - suppress_output env -u GIT_QUARANTINE_PATH git -C "$GIT_WORKDIR" reset "$REV" -- . - suppress_output env -u GIT_QUARANTINE_PATH git -C "$GIT_WORKDIR" push $GIT_WORKDIR $REV:refs/heads/$DOKKU_DEPLOY_BRANCH + fn-git-cmd "$APP_ROOT" archive "$REV" | tar x --warning=none -C "${GIT_WORKDIR}" + suppress_output fn-git-cmd "$GIT_WORKDIR" clone --bare "$DOKKU_ROOT/$APP" .git + suppress_output fn-git-cmd "$GIT_WORKDIR" config --local gc.auto 0 + suppress_output fn-git-cmd "$GIT_WORKDIR" config --local --bool core.bare false + suppress_output fn-git-cmd "$GIT_WORKDIR" config --local receive.denyCurrentBranch ignore + suppress_output fn-git-cmd "$GIT_WORKDIR" symbolic-ref HEAD "refs/heads/$DOKKU_DEPLOY_BRANCH" + suppress_output fn-git-cmd "$GIT_WORKDIR" reset "$REV" -- . + suppress_output fn-git-cmd "$GIT_WORKDIR" push $GIT_WORKDIR $REV:refs/heads/$DOKKU_DEPLOY_BRANCH + fn-git-setup-build-dir-submodules "$APP" "$GIT_WORKDIR" } fn-git-setup-build-dir-old() { declare APP="$1" GIT_WORKDIR="$2" REV="$3" + local APP_ROOT="$DOKKU_ROOT/$APP" local TMP_TAG="dokku/$REV" - suppress_output git -C "$DOKKU_ROOT/$APP" tag -d "$TMP_TAG" &>/dev/null || true - suppress_output git -C "$DOKKU_ROOT/$APP" tag "$TMP_TAG" "$REV" - suppress_output git -C "$GIT_WORKDIR" init - suppress_output git -C "$GIT_WORKDIR" config advice.detachedHead false - suppress_output git -C "$GIT_WORKDIR" remote add origin "$DOKKU_ROOT/$APP" - suppress_output git -C "$GIT_WORKDIR" fetch --depth=1 origin "refs/tags/$TMP_TAG" - suppress_output git -C "$GIT_WORKDIR" reset --hard FETCH_HEAD - suppress_output git -C "$DOKKU_ROOT/$APP" git tag -d "$TMP_TAG" &>/dev/null || true + suppress_output fn-git-cmd "$APP_ROOT" tag -d "$TMP_TAG" &>/dev/null || true + suppress_output fn-git-cmd "$APP_ROOT" tag "$TMP_TAG" "$REV" + suppress_output fn-git-cmd "$GIT_WORKDIR" init + suppress_output fn-git-cmd "$GIT_WORKDIR" config advice.detachedHead false + suppress_output fn-git-cmd "$GIT_WORKDIR" remote add origin "$DOKKU_ROOT/$APP" + suppress_output fn-git-cmd "$GIT_WORKDIR" fetch --depth=1 origin "refs/tags/$TMP_TAG" + suppress_output fn-git-cmd "$GIT_WORKDIR" reset --hard FETCH_HEAD + suppress_output fn-git-cmd "$APP_ROOT" tag -d "$TMP_TAG" &>/dev/null || true + fn-git-setup-build-dir-submodules "$APP" "$GIT_WORKDIR" } fn-git-setup-build-dir-worktree() { declare APP="$1" GIT_WORKDIR="$2" REV="$3" + local APP_ROOT="$DOKKU_ROOT/$APP" # unset the git quarantine path to allow us to use 2.13.0+ # See this issue for more information: https://github.com/dokku/dokku/issues/2796 - suppress_output env -u GIT_QUARANTINE_PATH git -C "$DOKKU_ROOT/$APP" worktree add "$GIT_WORKDIR" "$REV" + unset GIT_QUARANTINE_PATH + + suppress_output fn-git-cmd "$APP_ROOT" worktree add "$GIT_WORKDIR" "$REV" fn-git-setup-build-dir-submodules "$APP" "$GIT_WORKDIR" - suppress_output git -C "$DOKKU_ROOT/$APP" worktree prune + suppress_output fn-git-cmd "$APP_ROOT" worktree prune } fn-git-setup-build-dir-submodules() { declare APP="$1" GIT_WORKDIR="$2" local DOKKU_KEEP_GIT_DIR="$(fn-plugin-property-get "git" "$APP" "keep-git-dir" "")" - suppress_output env -u GIT_QUARANTINE_PATH git -C "$GIT_WORKDIR" submodule update --init --recursive + # unset the git quarantine path to allow us to use 2.13.0+ + # See this issue for more information: https://github.com/dokku/dokku/issues/2796 + unset GIT_QUARANTINE_PATH + suppress_output fn-git-cmd "$GIT_WORKDIR" submodule update --init --recursive + if [[ "$DOKKU_KEEP_GIT_DIR" != "true" ]]; then pushd "$GIT_WORKDIR" >/dev/null find "$GIT_WORKDIR" -name .git -prune -exec rm -rf {} \; >/dev/null diff --git a/plugins/nginx-vhosts/post-app-clone-setup b/plugins/nginx-vhosts/post-app-clone-setup index 181bb2a0a..0a4e02a4c 100755 --- a/plugins/nginx-vhosts/post-app-clone-setup +++ b/plugins/nginx-vhosts/post-app-clone-setup @@ -7,10 +7,10 @@ trigger-nginx-vhosts-post-app-clone-setup() { declare desc="removes nginx files when setting up a clone" declare trigger="post-app-clone-setup" declare OLD_APP="$1" NEW_APP="$2" - local APP_DIR="$DOKKU_ROOT/$NEW_APP" + local APP_ROOT="$DOKKU_ROOT/$NEW_APP" fn-plugin-property-clone "nginx" "$OLD_APP" "$NEW_APP" - rm -rf "$APP_DIR/nginx.conf" + rm -rf "$APP_ROOT/nginx.conf" } trigger-nginx-vhosts-post-app-clone-setup "$@" diff --git a/plugins/scheduler-docker-local/post-app-clone-setup b/plugins/scheduler-docker-local/post-app-clone-setup index 1b3aa0e15..51161f337 100755 --- a/plugins/scheduler-docker-local/post-app-clone-setup +++ b/plugins/scheduler-docker-local/post-app-clone-setup @@ -7,10 +7,10 @@ trigger-scheduler-docker-local-post-app-clone-setup() { declare desc="removes docker-local files when setting up a clone" declare trigger="post-app-clone-setup" declare OLD_APP="$1" NEW_APP="$2" - local APP_DIR="$DOKKU_ROOT/$NEW_APP" + local APP_ROOT="$DOKKU_ROOT/$NEW_APP" fn-plugin-property-clone "scheduler-docker-local" "$OLD_APP" "$NEW_APP" - find "$APP_DIR" -type f -name 'CONTAINER.*' -exec rm {} \; + find "$APP_ROOT" -type f -name 'CONTAINER.*' -exec rm {} \; } trigger-scheduler-docker-local-post-app-clone-setup "$@" diff --git a/plugins/scheduler-docker-local/post-app-rename-setup b/plugins/scheduler-docker-local/post-app-rename-setup index 7ce9297f9..b443dac4d 100755 --- a/plugins/scheduler-docker-local/post-app-rename-setup +++ b/plugins/scheduler-docker-local/post-app-rename-setup @@ -7,7 +7,6 @@ trigger-scheduler-docker-local-post-app-rename-setup() { declare desc="updates settings when renaming an app" declare trigger="post-app-rename-setup" declare OLD_APP="$1" NEW_APP="$2" - local APP_DIR="$DOKKU_ROOT/$NEW_APP" fn-plugin-property-clone "scheduler-docker-local" "$OLD_APP" "$NEW_APP" fn-plugin-property-destroy "scheduler-docker-local" "$OLD_APP"