Merge pull request #3141 from dokku/use-apps-exists

Use apps_exists helper where appropriate
This commit is contained in:
Jose Diaz-Gonzalez
2018-04-07 16:31:29 -04:00
committed by GitHub
3 changed files with 13 additions and 8 deletions

View File

@@ -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."

View File

@@ -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 "$@"

View File

@@ -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/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g' | sed 's/^\///g')"
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"
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