diff --git a/docs/community/plugins.md b/docs/community/plugins.md
index 53a74570f..60c59e634 100644
--- a/docs/community/plugins.md
+++ b/docs/community/plugins.md
@@ -181,7 +181,6 @@ The following plugins are available and provided by Dokku maintainers. Where not
| [Dockerfile custom path](https://github.com/mimischi/dokku-dockerfile) | [mimischi][] | 0.8.0+ |
| [Dokku Registry](https://github.com/agco-adm/dokku-registry)1 | [agco-adm][] | 0.4.0+ |
| [Dokku Require](https://github.com/crisward/dokku-require)2 | [crisward][] | 0.4.0+ |
-| [git rev-parse HEAD in env](https://github.com/dokku-community/dokku-git-rev) | [cjblomqvist][] | 0.4.0+ |
| [Global Certificates](https://github.com/josegonzalez/dokku-global-cert) | [josegonzalez][] | 0.5.0+ |
| [Graduate (Environment Management)](https://github.com/glassechidna/dokku-graduate) | [Benjamin-Dobell][] | 0.4.0+ |
| [Haproxy tcp load balancer](https://github.com/256dpi/dokku-haproxy) | [256dpi][] | 0.4.0+ |
@@ -250,6 +249,7 @@ The following plugins have been removed as their functionality is now in Dokku C
| [Docker Options](https://github.com/dyson/dokku-docker-options) | [dyson][] | v0.3.17 (docker-options plugin) |
| [Dokku Name](https://github.com/alex-sherwin/dokku-name) | [alex-sherwin][] | v0.4.2 (named containers plugin) |
| [Events Logger](https://github.com/alessio/dokku-events) | [alessio][] | v0.3.21 (events plugin) |
+| [git rev-parse HEAD in env](https://github.com/dokku-community/dokku-git-rev) | [cjblomqvist][] | v0.12.0 (enhanced core git plugin) |
| [Host Port binding](https://github.com/stuartpb/dokku-bind-port) | [stuartpb][] | v0.3.17 (docker-options plugin) |
| [Link Containers](https://github.com/rlaneve/dokku-link) | [rlaneve][] | v0.3.17 (docker-options plugin) |
| [List Containers](https://github.com/josegonzalez/dokku-list) | [josegonzalez][] | v0.3.14 (ps plugin) |
diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md
index 65191546a..77136e82d 100644
--- a/docs/configuration/environment-variables.md
+++ b/docs/configuration/environment-variables.md
@@ -101,7 +101,6 @@ The following list config variables have special meaning and can be set in a var
| `DOKKU_CHECKS_TIMEOUT` | `30` | `dokku config:set` | Wait this many seconds for each response before marking it as a failure.
| `DOKKU_CHECKS_ATTEMPTS` | `5` | `dokku config:set` | Number of retries for to run for a specific check before marking it as a failure
| `DOKKU_DEFAULT_CHECKS_WAIT` | `10` | `dokku config:set` | If no user-defined checks are specified - or if the process being checked is not a `web` process - this is the period of time Dokku will wait before checking that a container is still running. |
-| `DOKKU_DEPLOY_BRANCH` | `master` | `dokku config:set` | Branch to deploy by default. |
| `DOKKU_DISABLE_PROXY` | none | `dokku proxy:disable`
`dokku proxy:enable` | Disables the proxy in front of your application, resulting in publicly routing the docker container. |
| `DOKKU_DISABLE_ANSI_PREFIX_REMOVAL` | none | `dokku config:set`
`/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | Disables removal of the ANSI prefix during deploys. Can be used in cases where the client deployer does not understand ansi escape codes. |
| `DOKKU_DISABLE_APP_AUTOCREATION` | none | `dokku config:set` | Disables automatic creation of a non-existent app on deploy. |
diff --git a/docs/deployment/application-deployment.md b/docs/deployment/application-deployment.md
index 3ba25e1c8..144478833 100644
--- a/docs/deployment/application-deployment.md
+++ b/docs/deployment/application-deployment.md
@@ -15,7 +15,7 @@ git clone git@github.com:heroku/ruby-rails-sample.git
Create the application on the Dokku host. You will need to ssh onto the host to run this command.
```shell
-# on your Dokku host
+# on the Dokku host
dokku apps:create ruby-rails-sample
```
@@ -24,7 +24,7 @@ dokku apps:create ruby-rails-sample
When you create a new app, Dokku by default *does not* provide any datastores such as MySQL or PostgreSQL. You will need to install plugins to handle that, but fortunately [Dokku has official plugins](/docs/community/plugins.md#official-plugins-beta) for common datastores. Our sample app requires a PostgreSQL service:
```shell
-# on your Dokku host
+# on the Dokku host
# install the postgres plugin
# plugin installation requires root, hence the user change
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
@@ -40,7 +40,7 @@ dokku postgres:create rails-database
Once the service creation is complete, set the `POSTGRES_URL` environment variable by linking the service.
```shell
-# on your Dokku host
+# on the Dokku host
# each official datastore offers a `link` method to link a service to any application
dokku postgres:link rails-database ruby-rails-sample
```
@@ -93,30 +93,12 @@ When the deploy finishes, the application's URL will be shown as seen above.
Dokku supports deploying applications via [Heroku buildpacks](https://devcenter.heroku.com/articles/buildpacks) with [Herokuish](https://github.com/gliderlabs/herokuish#buildpacks) or using a project's [dockerfile](https://docs.docker.com/reference/builder/).
-### Deploying non-master branch
-
-Dokku only supports deploying from its master branch, so if you'd like to deploy a different local branch use: ```git push dokku :master```
-
-An alternative is to use the `DOKKU_DEPLOY_BRANCH` application config value to specify a branch that should be deployed. The implicit default is master, and this can be modified both at the app and global level:
-
-```shell
-# on your Dokku host
-
-# set it globally
-dokku config:set --global DOKKU_DEPLOY_BRANCH=some-branch
-
-# override for a specific app
-dokku config:set ruby-rails-sample DOKKU_DEPLOY_BRANCH=some-branch
-```
-
-You can also support pushing multiple branches using the [receive-branch](/docs/development/plugin-triggers.md#receive-branch) plugin trigger in a custom plugin.
-
### Skipping deployment
If you only want to rebuild and tag a container, you can skip the deployment phase by setting `$DOKKU_SKIP_DEPLOY` to `true` by running:
``` shell
-# on your Dokku host
+# on the Dokku host
dokku config:set ruby-rails-sample DOKKU_SKIP_DEPLOY=true
```
@@ -125,7 +107,7 @@ dokku config:set ruby-rails-sample DOKKU_SKIP_DEPLOY=true
If you need to re-deploy (or restart) your app:
```shell
-# on your Dokku host
+# on the Dokku host
dokku ps:rebuild ruby-rails-sample
```
@@ -136,7 +118,7 @@ See the [process scaling documentation](/docs/deployment/process-management.md)
Dokku uses git locally (i.e. not a docker image) to build its own copy of your app repo, including submodules. This is done as the `dokku` user. Therefore, in order to deploy private git submodules, you'll need to drop your deploy key in `/home/dokku/.ssh/` and potentially add github.com (or your VCS host key) into `/home/dokku/.ssh/known_hosts`. The following test should help confirm you've done it correctly.
```shell
-# on your Dokku host
+# on the Dokku host
su - dokku
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
ssh -T git@github.com
@@ -202,18 +184,22 @@ See the [user management documentation](/docs/deployment/user-management.md).
See the [nginx documentation](/docs/configuration/nginx.md#default-site).
+## Deploying non-master branch
+
+See the [git documentation](/docs/deployment/methods/git.md#changing-the-deploy-branch).
+
## Dockerfile deployment
See the [dockerfile documentation](/docs/deployment/methods/dockerfiles.md).
-## Specifying a custom buildpack
-
-See the [buildpack documentation](/docs/deployment/methods/buildpacks.md).
-
## Image tagging
See the [image tagging documentation](/docs/deployment/methods/images.md).
+## Specifying a custom buildpack
+
+See the [buildpack documentation](/docs/deployment/methods/buildpacks.md).
+
## Removing a deployed app
See the [application management documentation](/docs/deployment/application-management.md#removing-a-deployed-app).
diff --git a/docs/deployment/methods/git.md b/docs/deployment/methods/git.md
new file mode 100644
index 000000000..001140135
--- /dev/null
+++ b/docs/deployment/methods/git.md
@@ -0,0 +1,62 @@
+# GIT Deployment
+
+> Subcommands new as of 0.12.0
+
+```
+git:report [] [] # Displays a git report for one or more apps
+git:set () # Set or clear a git property for an app
+```
+
+GIT-based deployment has been the traditional method of deploying applications in Dokku. As of v0.12.0, Dokku introduces a few ways to customize the experience of deploying via `git push`.
+
+## Usage
+
+### Changing the Deploy Branch
+
+By default, Dokku will deploy code pushed to the `master` branch. In order to quickly deploy a different local branch, the following GIT command can be used:
+
+```shell
+# on the local machine
+
+# where `SOME_BRANCH_NAME` is the name of the branch
+git push dokku SOME_BRANCH_NAME:master
+```
+
+In `0.12.0`, the correct way to change the deploy branch is to use the `git:set` Dokku subcommand.
+
+```shell
+# on the Dokku host
+
+# override for all applications
+dokku git:set --global deploy-branch SOME_BRANCH_NAME
+
+# override for a specific app
+# where `SOME_BRANCH_NAME` is the name of the branch
+dokku git:set node-js-app deploy-branch SOME_BRANCH_NAME
+```
+
+Pushing multiple branches can also be supportec by creating a [receive-branch](/docs/development/plugin-triggers.md#receive-branch) plugin trigger in a custom plugin.
+
+### Configuring the GIT_REV Environment Variable
+
+> New as of 0.12.0
+
+Application deployments will include a special `GIT_REV` environment variable containing the current deployment sha being deployed. For rebuilds, this sha will remain the same.
+
+To configure the name of the `GIT_REV` environment variable, run the `git:set` subcommand as follows:
+
+```shell
+# on the Dokku host
+
+# override for a specific app
+dokku git:set node-js-app rev-env-var DOKKU_GIT_REV
+```
+
+This behavior can be disabled entirely on a per-app basis by setting the `rev-env-var` value to an empty string:
+
+```shell
+# on the Dokku host
+
+# override for a specific app
+dokku git:set node-js-app rev-env-var ""
+```
diff --git a/plugins/common/property-functions b/plugins/common/property-functions
new file mode 100755
index 000000000..44be12f36
--- /dev/null
+++ b/plugins/common/property-functions
@@ -0,0 +1,94 @@
+#!/usr/bin/env bash
+set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
+
+fn-plugin-property-delete() {
+ declare desc="delete a key from the property store for an app"
+ declare PLUGIN="$1" APP="$2" KEY="$3"
+
+ if [[ -z "$PLUGIN" ]] || [[ -z "$APP" ]] || [[ -z "$KEY" ]]; then
+ return 1
+ fi
+
+ rm -f "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}/${KEY}"
+}
+
+fn-plugin-property-destroy() {
+ declare desc="destroy the properties for an app"
+ declare PLUGIN="$1" APP="$2"
+
+ if [[ -z "$PLUGIN" ]] || [[ -z "$APP" ]]; then
+ return 1
+ fi
+
+ if [[ "$APP" == "_all_" ]]; then
+ rm -rf "${DOKKU_LIB_ROOT}/config/${PLUGIN}"
+ else
+ rm -rf "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}"
+ fi
+}
+
+fn-plugin-property-get() {
+ declare desc="returns the property store 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
+
+ CONFIG_VALUE="$(fn-plugin-property-read "$PLUGIN" "$APP" "$KEY" || true)"
+ if [[ -z "$CONFIG_VALUE" ]]; then
+ CONFIG_VALUE="$DEFAULT"
+ fi
+ echo "$CONFIG_VALUE"
+}
+
+fn-plugin-property-setup() {
+ declare desc="creates the plugin config root"
+ declare PLUGIN="$1"
+
+ if [[ -z "$PLUGIN" ]]; then
+ return 1
+ fi
+
+ mkdir -p "${DOKKU_LIB_ROOT}/config/${PLUGIN}"
+ chmod 0755 "${DOKKU_LIB_ROOT}/config/${PLUGIN}"
+
+ if [[ -z "$DOKKU_SYSTEM_GROUP" ]]; then
+ export DOKKU_SYSTEM_GROUP=dokku
+ fi
+
+ if [[ -z "$DOKKU_SYSTEM_USER" ]]; then
+ export DOKKU_SYSTEM_USER=dokku
+ fi
+
+ chown "${DOKKU_SYSTEM_USER}:${DOKKU_SYSTEM_GROUP}" "${DOKKU_LIB_ROOT}/config/${PLUGIN}"
+}
+
+fn-plugin-property-read() {
+ declare desc="read a key from the property store for an app"
+ declare PLUGIN="$1" APP="$2" KEY="$3"
+
+ if [[ -z "$PLUGIN" ]] || [[ -z "$APP" ]] || [[ -z "$KEY" ]]; then
+ return 1
+ fi
+
+ if [[ ! -f "${DOKKU_LIB_ROOT:?}/config/${PLUGIN}/${APP}/${KEY}" ]]; then
+ return 1
+ fi
+
+ cat "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}/${KEY}"
+}
+
+fn-plugin-property-write() {
+ declare desc="read a key from the property store for an app"
+ declare PLUGIN="$1" APP="$2" KEY="$3" VALUE="$4"
+
+ if [[ -z "$PLUGIN" ]] || [[ -z "$APP" ]] || [[ -z "$KEY" ]]; then
+ return 1
+ fi
+
+ mkdir -p "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}"
+ echo "$VALUE" > "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}/${KEY}"
+ chmod 600 "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}/${KEY}"
+}
diff --git a/plugins/git/functions b/plugins/git/functions
index e1189448e..389b5989e 100755
--- a/plugins/git/functions
+++ b/plugins/git/functions
@@ -1,29 +1,30 @@
#!/usr/bin/env bash
-set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
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"
+set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
use_git_worktree() {
- declare desc="detects whether to use git worktree"
- local GIT_VERSION MAJOR_VERSION MINOR_VERSION
+ declare desc="detects whether to use git worktree"
+ local GIT_VERSION MAJOR_VERSION MINOR_VERSION
- GIT_VERSION=$(git --version | awk '{split($0,a," "); print a[3]}')
- MAJOR_VERSION=$(echo "$GIT_VERSION" | awk '{split($0,a,"."); print a[1]}')
- MINOR_VERSION=$(echo "$GIT_VERSION" | awk '{split($0,a,"."); print a[2]}')
+ GIT_VERSION=$(git --version | awk '{split($0,a," "); print a[3]}')
+ MAJOR_VERSION=$(echo "$GIT_VERSION" | awk '{split($0,a,"."); print a[1]}')
+ MINOR_VERSION=$(echo "$GIT_VERSION" | awk '{split($0,a,"."); print a[2]}')
- if [[ "$MAJOR_VERSION" -ge "3" ]]; then
- return 0
- elif [[ "$MAJOR_VERSION" -eq "2" ]] && [[ "$MINOR_VERSION" -ge "11" ]]; then
- return 0
- else
- return 1
- fi
+ if [[ "$MAJOR_VERSION" -ge "3" ]]; then
+ return 0
+ elif [[ "$MAJOR_VERSION" -eq "2" ]] && [[ "$MINOR_VERSION" -ge "11" ]]; then
+ return 0
+ else
+ return 1
+ fi
}
git_build_app_repo() {
declare desc="builds local git app repo for app"
- declare APP="$1"; local REV="$2"
+ declare APP="$1" REV="$2"
local DOKKU_GLOBAL_DISABLE_AUTOCREATE
verify_app_name "$APP"
@@ -104,8 +105,8 @@ git_deploy_branch() {
local cmd="git-hook"
local APP="$1"
- local DOKKU_DEPLOY_BRANCH="$(config_get "$APP" DOKKU_DEPLOY_BRANCH || true)"
- local DOKKU_GLOBAL_DEPLOY_BRANCH="$(config_get --global DOKKU_DEPLOY_BRANCH || true)"
+ 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
@@ -152,8 +153,12 @@ git_hook_cmd() {
git_build() {
declare desc="setup and call git_build_app_repo"
local APP="$1"
- local DOKKU_DEPLOY_BRANCH REF
+ 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")"
+ if [[ -n "$ENV_VAR_NAME" ]]; then
+ config_set --no-restart "$APP" "${ENV_VAR_NAME}=${REV}" > /dev/null
+ fi
local REF="$2"
else
DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")"
diff --git a/plugins/git/install b/plugins/git/install
new file mode 100755
index 000000000..92e6d4852
--- /dev/null
+++ b/plugins/git/install
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
+source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
+source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
+source "$PLUGIN_AVAILABLE_PATH/config/functions"
+
+trigger-git-install() {
+ declare desc="installs the git plugin"
+ fn-plugin-property-setup "git"
+}
+
+migrate_git_vars_0_12_0() {
+ declare desc="migrates git config variables from 0.11.x"
+ local APPS="$(dokku_apps)"
+ local DOKKU_DEPLOY_BRANCH app
+
+ DOKKU_DEPLOY_BRANCH=$(config_get --global DOKKU_DEPLOY_BRANCH || true)
+ if [[ -n "$DOKKU_DEPLOY_BRANCH" ]]; then
+ fn-plugin-property-write "git" --global "deploy-branch" "$DOKKU_DEPLOY_BRANCH"
+ config_unset --global DOKKU_DEPLOY_BRANCH || true
+ fi
+
+ for app in $APPS; do
+ DOKKU_DEPLOY_BRANCH=$(config_get "$app" DOKKU_DEPLOY_BRANCH || true)
+ if [[ -n "$DOKKU_DEPLOY_BRANCH" ]]; then
+ fn-plugin-property-write "git" "$APP" "deploy-branch" "$DOKKU_DEPLOY_BRANCH"
+ config_unset --no-restart "$app" DOKKU_DEPLOY_BRANCH || true
+ fi
+ done
+}
+
+trigger-git-install "$@"
+migrate_git_vars_0_12_0 "$@"
diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions
new file mode 100755
index 000000000..d25cd3317
--- /dev/null
+++ b/plugins/git/internal-functions
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
+set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
+
+cmd-git-report() {
+ declare desc="Display the configured git status for an application"
+ declare cmd="git:report" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
+ declare APP="$1" INFO_FLAG="$2"
+ local flag flag_map key match valid_flags value_exists
+ [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
+ verify_app_name "$APP"
+
+ flag_map=(
+ "--git-rev-env-var: $(fn-plugin-property-get "$APP" "rev-env-var" "GIT_REV")"
+ "--git-deploy-branch: $(fn-plugin-property-get "$APP" "deploy-branch" "master")"
+ "--git-global-deploy-branch: $(fn-plugin-property-get "--global" "deploy-branch" "master")"
+ )
+ if [[ -z "$INFO_FLAG" ]]; then
+ dokku_log_info2_quiet "${APP} Git Information"
+ for flag in "${flag_map[@]}"; do
+ key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')"
+ dokku_log_verbose "$(printf "%-20s %-25s" "${key^}" "${flag#*: }")"
+ done
+ else
+ match=false
+ value_exists=false
+ for flag in "${flag_map[@]}"; do
+ valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)"
+ if [[ "$flag" == "${INFO_FLAG}:"* ]]; then
+ value=${flag#*: }
+ size="${#value}"
+ if [[ "$size" -ne 0 ]]; then
+ echo "$value" && match=true && value_exists=true
+ else
+ match=true
+ fi
+ fi
+ done
+ [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}"
+ [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed"
+ fi
+}
diff --git a/plugins/git/post-delete b/plugins/git/post-delete
new file mode 100755
index 000000000..548982617
--- /dev/null
+++ b/plugins/git/post-delete
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
+source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
+
+trigger-git-post-delete() {
+ declare desc="destroys the git properties for a given app"
+ declare APP="$1"
+ fn-plugin-property-destroy "git" "$APP"
+}
+
+trigger-git-post-delete "$@"
diff --git a/plugins/git/subcommands/report b/plugins/git/subcommands/report
new file mode 100755
index 000000000..1c223a9dd
--- /dev/null
+++ b/plugins/git/subcommands/report
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+source "$PLUGIN_AVAILABLE_PATH/git/internal-functions"
+set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
+
+cmd-git-report "$@"
diff --git a/plugins/git/subcommands/set b/plugins/git/subcommands/set
new file mode 100755
index 000000000..f4f83c70c
--- /dev/null
+++ b/plugins/git/subcommands/set
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
+source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
+set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
+
+fn-in-array() {
+ declare desc="return true if value ($1) is in list (all other arguments)"
+
+ local e
+ for e in "${@:2}"; do
+ [[ "$e" == "$1" ]] && return 0
+ done
+ return 1
+}
+
+git-set-cmd() {
+ declare desc="sets a git configuration value for an app"
+ local cmd="git:set" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
+ declare APP="$1" KEY="$2" VALUE="$3"
+ local VALID_KEYS=("deploy-branch" "rev-env-var")
+ [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
+ [[ -z "$KEY" ]] && dokku_log_fail "No key specified"
+
+ if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
+ dokku_log_fail "Invalid key specified, valid keys include: deploy-branch, rev-env-var"
+ fi
+
+ if [[ -n "$VALUE" ]]; then
+ dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}"
+ 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"
+ fi
+ fi
+}
+
+git-set-cmd "$@"
diff --git a/tests/unit/10_git.bats b/tests/unit/10_git.bats
new file mode 100644
index 000000000..41b8e45e7
--- /dev/null
+++ b/tests/unit/10_git.bats
@@ -0,0 +1,89 @@
+#!/usr/bin/env bats
+
+load test_helper
+
+setup() {
+ global_setup
+ create_app
+}
+
+teardown() {
+ destroy_app
+ global_teardown
+}
+
+@test "(git) deploy specific branch" {
+ run bash -c "dokku git:set --global deploy-branch global-branch"
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ GIT_REMOTE_BRANCH=global-branch deploy_app
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ run bash -c "dokku ps:rebuild $TEST_APP"
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ run bash -c "dokku git:set $TEST_APP deploy-branch app-branch"
+ GIT_REMOTE_BRANCH=app-branch deploy_app
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ run bash -c "dokku ps:rebuild $TEST_APP"
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ run bash -c "dokku git:set --global deploy-branch"
+}
+
+@test "(git) ensure GIT_REV env var is set" {
+ deploy_app
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ run bash -c "dokku config:get $TEST_APP GIT_REV"
+ echo "output: "$output
+ echo "status: "$status
+ assert_output_exists
+}
+
+@test "(git) disable GIT_REV" {
+ run bash -c "dokku git:set $TEST_APP rev-env-var"
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ deploy_app
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ run bash -c "dokku config:get $TEST_APP GIT_REV"
+ echo "output: "$output
+ echo "status: "$status
+ assert_output_empty
+}
+
+@test "(git) customize the GIT_REV environment variable" {
+ run bash -c "dokku git:set $TEST_APP rev-env-var GIT_REV_ALT"
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ deploy_app
+ echo "output: "$output
+ echo "status: "$status
+ assert_success
+
+ run bash -c "dokku config:get $TEST_APP GIT_REV_ALT"
+ echo "output: "$output
+ echo "status: "$status
+ assert_output_exists
+}
\ No newline at end of file
diff --git a/tests/unit/20_config.bats b/tests/unit/20_config.bats
index 511b72e7c..a5894372c 100644
--- a/tests/unit/20_config.bats
+++ b/tests/unit/20_config.bats
@@ -145,27 +145,3 @@ teardown() {
echo "status: "$status
assert_success
}
-
-@test "(config) deploy specific DOKKU_DEPLOY_BRANCH" {
- run ssh dokku@dokku.me config:set --global DOKKU_DEPLOY_BRANCH=global-branch
- GIT_REMOTE_BRANCH=global-branch deploy_app
- echo "output: "$output
- echo "status: "$status
- assert_success
-
- run ssh dokku@dokku.me ps:rebuild $TEST_APP
- echo "output: "$output
- echo "status: "$status
- assert_success
-
- run ssh dokku@dokku.me config:set $TEST_APP DOKKU_DEPLOY_BRANCH=app-branch
- GIT_REMOTE_BRANCH=app-branch deploy_app
- echo "output: "$output
- echo "status: "$status
- assert_success
-
- run ssh dokku@dokku.me ps:rebuild $TEST_APP
- echo "output: "$output
- echo "status: "$status
- assert_success
-}
diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash
index 2583d5d75..9e7449122 100644
--- a/tests/unit/test_helper.bash
+++ b/tests/unit/test_helper.bash
@@ -71,6 +71,18 @@ assert_output() {
assert_equal "$expected" "$output"
}
+# ShellCheck doesn't know about $output from Bats
+# shellcheck disable=SC2154
+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() {