fix: ensure we can disable setting the rev-env-var

This commit is contained in:
Jose Diaz-Gonzalez
2018-03-31 04:30:15 -04:00
parent 0d5a77fcd6
commit 23c25a44ec
5 changed files with 29 additions and 13 deletions

View File

@@ -27,6 +27,20 @@ fn-plugin-property-destroy() {
fi
}
fn-plugin-property-exists() {
declare desc="returns whether the property store has a value for an app"
declare PLUGIN="$1" APP="$2" KEY="$3" DEFAULT="$4"
local CONFIG_VALUE
if [[ -z "$PLUGIN" ]] || [[ -z "$APP" ]] || [[ -z "$KEY" ]]; then
return 1
fi
if [[ ! -f "${DOKKU_LIB_ROOT:?}/config/${PLUGIN}/${APP}/${KEY}" ]]; then
return 1
fi
}
fn-plugin-property-get() {
declare desc="returns the property store value for an app"
declare PLUGIN="$1" APP="$2" KEY="$3" DEFAULT="$4"

View File

@@ -152,14 +152,18 @@ git_hook_cmd() {
git_build() {
declare desc="setup and call git_build_app_repo"
local APP="$1"
local APP="$1" REV="$2"
local DOKKU_DEPLOY_BRANCH ENV_VAR_NAME REF
if [[ $# -ge 2 ]]; then
ENV_VAR_NAME="$(fn-plugin-property-get "git" "$APP" "rev-env-var" "GIT_REV")"
ENV_VAR_NAME="$(fn-plugin-property-get "git" "$APP" "rev-env-var")"
if [[ -z "$ENV_VAR_NAME" ]] && ! fn-plugin-property-exists "git" "$APP" "rev-env-var"; then
ENV_VAR_NAME="GIT_REV"
fi
if [[ -n "$ENV_VAR_NAME" ]]; then
config_set --no-restart "$APP" "${ENV_VAR_NAME}=${REV}" > /dev/null
fi
local REF="$2"
local REF="$REV"
else
DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")"
REF=$(< "$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH")

View File

@@ -30,9 +30,13 @@ git-set-cmd() {
fn-plugin-property-write "git" "$APP" "$KEY" "$VALUE"
else
dokku_log_info2_quiet "Unsetting ${KEY}"
fn-plugin-property-delete "git" "$APP" "$KEY"
if [[ "$KEY" == "enabled" ]]; then
fn-plugin-property-destroy "git" "$APP"
if [[ "$KEY" == "rev-env-var" ]]; then
fn-plugin-property-write "git" "$APP" "$KEY" "$VALUE"
else
fn-plugin-property-delete "git" "$APP" "$KEY"
if [[ "$KEY" == "enabled" ]]; then
fn-plugin-property-destroy "git" "$APP"
fi
fi
fi
}

View File

@@ -68,7 +68,7 @@ teardown() {
run bash -c "dokku config:get $TEST_APP GIT_REV"
echo "output: "$output
echo "status: "$status
assert_output_empty
assert_output ""
}
@test "(git) customize the GIT_REV environment variable" {

View File

@@ -77,12 +77,6 @@ assert_output_exists() {
[[ -n "$output" ]] || flunk "expected output, found none"
}
# ShellCheck doesn't know about $output from Bats
# shellcheck disable=SC2154
assert_output_empty() {
[[ -z "$output" ]] || flunk "expected no output, found $output"
}
# ShellCheck doesn't know about $output from Bats
# shellcheck disable=SC2154
assert_output_contains() {