diff --git a/plugins/git/functions b/plugins/git/functions index c19c8397e..6f6c82299 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -89,17 +89,21 @@ cmd-git-hook() { while read -r oldrev newrev refname; do # Only run this script for the master branch. You can remove this # if block if you wish to run it for others as well. - if [[ $refname == "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]]; then - # broken out into plugin so we might support other methods to receive an app + echo $'\e[1G\e[K'"-----> $oldrev | $newrev | $refname | ${DOKKU_DEPLOY_BRANCH}" + if [[ $refname == "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]] || [[ $refname == "refs/tags/${DOKKU_DEPLOY_BRANCH}" ]]; then git_receive_app "$APP" "$newrev" plugn trigger deploy-source-set "$APP" "git-push" "$newrev" else + # broken out into plugin so we might support other methods to receive an app if [[ $(find "$PLUGIN_PATH"/enabled/*/receive-branch 2>/dev/null | wc -l) != 1 ]]; then plugn trigger receive-branch "$APP" "$newrev" "$refname" plugn trigger deploy-source-set "$APP" "git-push" "$newrev" elif [[ -z "$(fn-git-deploy-branch "$APP" "")" ]]; then - echo $'\e[1G\e[K'"-----> Set ${refname/refs\/heads\//} to DOKKU_DEPLOY_BRANCH." - fn-plugin-property-write "git" "$APP" "deploy-branch" "${refname/refs\/heads\//}" + local deploy_branch="${refname/refs\/heads\//}" + deploy_branch="${deploy_branch/refs\/tags\//}" + + echo $'\e[1G\e[K'"-----> Set ${deploy_branch} as deploy-branch" + fn-plugin-property-write "git" "$APP" "deploy-branch" "${deploy_branch}" git_receive_app "$APP" "$newrev" plugn trigger deploy-source-set "$APP" "git-push" "$newrev" else diff --git a/tests/unit/git_8.bats b/tests/unit/git_8.bats new file mode 100644 index 000000000..be9ae8888 --- /dev/null +++ b/tests/unit/git_8.bats @@ -0,0 +1,51 @@ +#!/usr/bin/env bats + +load test_helper + +TEST_PLUGIN_APP=smoke-test-app +TEST_PLUGIN_GIT_REPO=https://github.com/dokku/${TEST_PLUGIN_APP}.git +TEST_PLUGIN_LOCAL_REPO="$(mktemp -d)/$TEST_PLUGIN_APP" + +clone_test_app() { + git clone "$TEST_PLUGIN_GIT_REPO" "$TEST_PLUGIN_LOCAL_REPO" +} + +remove_test_app() { + rm -rf $TEST_PLUGIN_LOCAL_REPO +} + +setup() { + global_setup + create_app + clone_test_app +} + +teardown() { + remove_test_app || true + destroy_app + global_teardown +} + +@test "(git) push tags and branches" { + # https://github.com/dokku/dokku/issues/5188 + local GIT_REMOTE=${GIT_REMOTE:="dokku@${DOKKU_DOMAIN}:$TEST_APP"} + run git -C "$TEST_PLUGIN_LOCAL_REPO" remote add target "$GIT_REMOTE" + echo "output: $output" + echo "status: $status" + assert_success + + run git -C "$TEST_PLUGIN_LOCAL_REPO" push target 1.0.0:master + echo "output: $output" + echo "status: $status" + assert_success + + run git -C "$TEST_PLUGIN_LOCAL_REPO" push target 2.0.0:master -f + echo "output: $output" + echo "status: $status" + assert_success + + run git -C "$TEST_PLUGIN_LOCAL_REPO" push target master -f + echo "output: $output" + echo "status: $status" + assert_success +}