From 23c25a44ec1e49b2d3dd0410736f578b7e5a2bcc Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 31 Mar 2018 04:30:15 -0400 Subject: [PATCH] fix: ensure we can disable setting the rev-env-var --- plugins/common/property-functions | 14 ++++++++++++++ plugins/git/functions | 10 +++++++--- plugins/git/subcommands/set | 10 +++++++--- tests/unit/10_git.bats | 2 +- tests/unit/test_helper.bash | 6 ------ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/plugins/common/property-functions b/plugins/common/property-functions index 44be12f36..f995ce6ef 100755 --- a/plugins/common/property-functions +++ b/plugins/common/property-functions @@ -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" diff --git a/plugins/git/functions b/plugins/git/functions index 389b5989e..03545f311 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -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") diff --git a/plugins/git/subcommands/set b/plugins/git/subcommands/set index f4f83c70c..09c31d7ee 100755 --- a/plugins/git/subcommands/set +++ b/plugins/git/subcommands/set @@ -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 } diff --git a/tests/unit/10_git.bats b/tests/unit/10_git.bats index 41b8e45e7..70385105a 100644 --- a/tests/unit/10_git.bats +++ b/tests/unit/10_git.bats @@ -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" { diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 9e7449122..ed62dfd52 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -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() {