diff --git a/docs/appendices/0.21.0-migration-guide.md b/docs/appendices/0.21.0-migration-guide.md new file mode 100644 index 000000000..3ba39c84f --- /dev/null +++ b/docs/appendices/0.21.0-migration-guide.md @@ -0,0 +1,5 @@ +# 0.21.0 Migration Guide + +## Deprecations + +- `git#git_deploy_branch()` is deprecated in favor of `plugn trigger git-deploy-branch`. diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index cadea183e..d73ba8438 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -531,6 +531,21 @@ verify_app_name "$APP" # TODO ``` +### `git-deploy-branch` + +- Description: Outputs the deploy branch for an app, inherited or not +- Invoked by: +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `git-post-pull` - Description: diff --git a/plugins/git/functions b/plugins/git/functions index d85f80387..91fc4464a 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -3,6 +3,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/apps/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -109,18 +110,11 @@ git_trigger_build() { git_deploy_branch() { declare desc="retrieve the deploy branch for a given application" - declare cmd="git-hook" - local APP="$1" + declare APP="$1" + declare deprecated=true + dokku_log_warn "Deprecated: plugn#git-deploy-branch" - local DOKKU_DEPLOY_BRANCH="$(fn-plugin-property-get "git" "$APP" "deploy-branch" "")" - local DOKKU_GLOBAL_DEPLOY_BRANCH="$(fn-plugin-property-get "git" "--global" "deploy-branch" "")" - if [[ -n "$DOKKU_DEPLOY_BRANCH" ]]; then - echo "$DOKKU_DEPLOY_BRANCH" - elif [[ -n "$DOKKU_GLOBAL_DEPLOY_BRANCH" ]]; then - echo "$DOKKU_GLOBAL_DEPLOY_BRANCH" - else - echo "master" - fi + fn-git-deploy-branch "$APP" } cmd-git-hook() { @@ -132,7 +126,7 @@ cmd-git-hook() { is_valid_app_name "$APP" - DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")" + DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" if ! git check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then echo $'\e[1G\e[K'"-----> WARNING: Invalid branch name '$DOKKU_DEPLOY_BRANCH' specified via DOKKU_DEPLOY_BRANCH." echo $'\e[1G\e[K'"-----> For more details, please see the man page for 'git-check-ref-format.'" @@ -174,7 +168,7 @@ git_build() { fi local REF="$REV" else - DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")" + DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" REF=$(<"$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH") fi diff --git a/plugins/git/git-deploy-branch b/plugins/git/git-deploy-branch new file mode 100755 index 000000000..3ec00749b --- /dev/null +++ b/plugins/git/git-deploy-branch @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-git-git-deploy-branch() { + declare desc="git deploy-branch plugin trigger" + declare trigger="git-deploy-branch" + declare APP="$1" + + fn-git-deploy-branch "$APP" +} + +trigger-git-git-deploy-branch "$@" diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index e1ec4189d..6002d82eb 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -69,3 +69,18 @@ cmd-git-report-single() { [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" fi } + +fn-git-deploy-branch() { + declare desc="retrieve the deploy branch for a given application" + local APP="$1" + + local DOKKU_DEPLOY_BRANCH="$(fn-plugin-property-get "git" "$APP" "deploy-branch" "")" + local DOKKU_GLOBAL_DEPLOY_BRANCH="$(fn-plugin-property-get "git" "--global" "deploy-branch" "")" + if [[ -n "$DOKKU_DEPLOY_BRANCH" ]]; then + echo "$DOKKU_DEPLOY_BRANCH" + elif [[ -n "$DOKKU_GLOBAL_DEPLOY_BRANCH" ]]; then + echo "$DOKKU_GLOBAL_DEPLOY_BRANCH" + else + echo "master" + fi +}