diff --git a/plugins/apps/functions b/plugins/apps/functions index 2ce635700..3fdc9ef0c 100755 --- a/plugins/apps/functions +++ b/plugins/apps/functions @@ -8,7 +8,7 @@ apps_create() { declare APP="$1" 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" dokku_log_info1_quiet "Creating $APP... done" @@ -45,15 +45,14 @@ apps_exists() { declare APP="$1" is_valid_app_name "$APP" - [[ -d "$DOKKU_ROOT/$APP" ]] || dokku_log_fail "App does not exist" - dokku_log_info1 "App already exists" + [[ -d "$DOKKU_ROOT/$APP" ]] || return 1 } apps_maybe_create() { declare desc="creates an app dir if allowed" 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)" if [[ "$DOKKU_GLOBAL_DISABLE_AUTOCREATE" == "true" ]]; then dokku_log_warn "App auto-creation disabled." diff --git a/plugins/apps/subcommands/exists b/plugins/apps/subcommands/exists index 792590fa7..084334eb4 100755 --- a/plugins/apps/subcommands/exists +++ b/plugins/apps/subcommands/exists @@ -5,7 +5,13 @@ source "$PLUGIN_AVAILABLE_PATH/apps/functions" apps_exists_cmd() { declare desc="checks if an app 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 "$@" diff --git a/plugins/git/functions b/plugins/git/functions index 7fef5d1f7..aa3089fd5 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -37,7 +37,7 @@ git_build_app_repo() { chmod 755 "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" 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 # 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" APP="$(echo "$APP" | perl -pe 's/(? /dev/null 2>&1 && apps_maybe_create "$APP" plugn trigger git-pre-pull "$APP" cat | git-upload-pack "$DOKKU_ROOT/$APP" @@ -209,7 +209,7 @@ git_glob_cmd() { is_valid_app_name "$APP" 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" fi