refactor: use apps_exists helper where appropriate
This centralizes the logic around checking if an application exists.
This commit is contained in:
@@ -8,7 +8,7 @@ apps_create() {
|
|||||||
declare APP="$1"
|
declare APP="$1"
|
||||||
is_valid_app_name "$APP"
|
is_valid_app_name "$APP"
|
||||||
|
|
||||||
[[ -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "Name is already taken"
|
apps_exists "$APP" > /dev/null 2>&1 && dokku_log_fail "Name is already taken"
|
||||||
|
|
||||||
mkdir -p "$DOKKU_ROOT/$APP"
|
mkdir -p "$DOKKU_ROOT/$APP"
|
||||||
dokku_log_info1_quiet "Creating $APP... done"
|
dokku_log_info1_quiet "Creating $APP... done"
|
||||||
@@ -45,15 +45,14 @@ apps_exists() {
|
|||||||
declare APP="$1"
|
declare APP="$1"
|
||||||
is_valid_app_name "$APP"
|
is_valid_app_name "$APP"
|
||||||
|
|
||||||
[[ -d "$DOKKU_ROOT/$APP" ]] || dokku_log_fail "App does not exist"
|
[[ -d "$DOKKU_ROOT/$APP" ]] || return 1
|
||||||
dokku_log_info1 "App already exists"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apps_maybe_create() {
|
apps_maybe_create() {
|
||||||
declare desc="creates an app dir if allowed"
|
declare desc="creates an app dir if allowed"
|
||||||
declare APP="$1"
|
declare APP="$1"
|
||||||
|
|
||||||
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
|
if ! apps_exists "$APP" > /dev/null 2>&1; then
|
||||||
DOKKU_GLOBAL_DISABLE_AUTOCREATE="$(config_get --global DOKKU_DISABLE_APP_AUTOCREATION || true)"
|
DOKKU_GLOBAL_DISABLE_AUTOCREATE="$(config_get --global DOKKU_DISABLE_APP_AUTOCREATION || true)"
|
||||||
if [[ "$DOKKU_GLOBAL_DISABLE_AUTOCREATE" == "true" ]]; then
|
if [[ "$DOKKU_GLOBAL_DISABLE_AUTOCREATE" == "true" ]]; then
|
||||||
dokku_log_warn "App auto-creation disabled."
|
dokku_log_warn "App auto-creation disabled."
|
||||||
|
|||||||
@@ -5,7 +5,13 @@ source "$PLUGIN_AVAILABLE_PATH/apps/functions"
|
|||||||
apps_exists_cmd() {
|
apps_exists_cmd() {
|
||||||
declare desc="checks if an app exists"
|
declare desc="checks if an app exists"
|
||||||
local cmd="apps:exists"
|
local cmd="apps:exists"
|
||||||
apps_exists "$2"
|
[[ "$1" == "$cmd" ]] && shift 1
|
||||||
|
declare APP="$1"
|
||||||
|
|
||||||
|
if ! apps_exists "$APP"; then
|
||||||
|
dokku_log_fail "App does not exist"
|
||||||
|
fi
|
||||||
|
dokku_log_info1 "App already exists"
|
||||||
}
|
}
|
||||||
|
|
||||||
apps_exists_cmd "$@"
|
apps_exists_cmd "$@"
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ git_build_app_repo() {
|
|||||||
chmod 755 "$GIT_BUILD_APP_REPO_TMP_WORK_DIR"
|
chmod 755 "$GIT_BUILD_APP_REPO_TMP_WORK_DIR"
|
||||||
unset GIT_DIR GIT_WORK_TREE
|
unset GIT_DIR GIT_WORK_TREE
|
||||||
|
|
||||||
[[ ! -d "$DOKKU_ROOT/$APP" ]] && apps_maybe_create "$APP"
|
! apps_exists "$APP" > /dev/null 2>&1 && apps_maybe_create "$APP"
|
||||||
|
|
||||||
if use_git_worktree; then
|
if use_git_worktree; then
|
||||||
# git worktree - this method uses git worktree which was introduced in git 2.5
|
# git worktree - this method uses git worktree which was introduced in git 2.5
|
||||||
@@ -194,7 +194,7 @@ git_upload_pack_cmd() {
|
|||||||
declare APP="$2"
|
declare APP="$2"
|
||||||
APP="$(echo "$APP" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g' | sed 's/^\///g')"
|
APP="$(echo "$APP" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g' | sed 's/^\///g')"
|
||||||
is_valid_app_name "$APP"
|
is_valid_app_name "$APP"
|
||||||
[[ ! -d "$DOKKU_ROOT/$APP" ]] && apps_maybe_create "$APP"
|
! apps_exists "$APP" > /dev/null 2>&1 && apps_maybe_create "$APP"
|
||||||
|
|
||||||
plugn trigger git-pre-pull "$APP"
|
plugn trigger git-pre-pull "$APP"
|
||||||
cat | git-upload-pack "$DOKKU_ROOT/$APP"
|
cat | git-upload-pack "$DOKKU_ROOT/$APP"
|
||||||
@@ -209,7 +209,7 @@ git_glob_cmd() {
|
|||||||
is_valid_app_name "$APP"
|
is_valid_app_name "$APP"
|
||||||
|
|
||||||
if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then
|
if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then
|
||||||
[[ ! -d "$DOKKU_ROOT/$APP" ]] && apps_maybe_create "$APP"
|
! apps_exists "$APP" > /dev/null 2>&1 && apps_maybe_create "$APP"
|
||||||
|
|
||||||
fn-git-create-hook "$APP"
|
fn-git-create-hook "$APP"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user