diff --git a/docs/deployment/methods/git.md b/docs/deployment/methods/git.md index 4bc071ef6..061c3c926 100644 --- a/docs/deployment/methods/git.md +++ b/docs/deployment/methods/git.md @@ -3,9 +3,12 @@ > Subcommands new as of 0.12.0 ``` -git:initialize # Initialize a git repository for an app -git:report [] [] # Displays a git report for one or more apps -git:set () # Set or clear a git property for an app +git:allow-host # Adds a host to known_hosts +git:sync [--build] [] # Clone or fetch an app from remote git repo +git:initialize # Initialize a git repository for an app +git:public-key # Outputs the dokku public deploy key +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`. A Git-based deployment currently supports building applications via: @@ -105,3 +108,50 @@ dokku git:set node-js-app keep-git-dir false # delete the .git directory during builds (default) dokku git:set node-js-app keep-git-dir "" ``` + +### Initializing an app repository from a remote repository + +> The application must exist before the repository can be initialized + +A Dokku app repository can be initialized or updated from a remote git repository via the `git:sync` command. This command will either clone or fetch updates from a remote repository and has undefined behavior if the history cannot be fast-fowarded to the referenced repository reference. Any repository that can be cloned by the `dokku` user can be specified. + +```shell +dokku git:sync node-js-app https://github.com/heroku/node-js-getting-started.git +``` + +The `git:sync` command optionally takes an optional third parameter containing a git reference, which may be a branch, tag, or specific commit. + +```shell +# specify a branch +dokku git:sync node-js-app https://github.com/heroku/node-js-getting-started.git main + +# specify a tag +dokku git:sync node-js-app https://github.com/heroku/node-js-getting-started.git 1 + +# specify a commit +dokku git:sync node-js-app https://github.com/heroku/node-js-getting-started.git 97e6c72491c7531507bfc5413903e0e00e31e1b0 +``` + +By default, this command does not trigger an application build. To do so during a `git:sync`, specify the `--build` flag. + +```shell +dokku git:sync --build node-js-app https://github.com/heroku/node-js-getting-started.git +``` + +### Allowing remote repository hosts + +By default, the Dokku host may not have access to a server containing the remote repository. This can be initialized via the `git:allow-host` command. + +```shell +dokku git:allow-host github.com +``` + +Note that this command is currently not idempotent and may add duplicate entries to the `~dokku/.ssh/known_hosts` file. + +### Verifying the cloning public key + +In order to clone a remote repository, the remote server should have the Dokku host's public key configured. This plugin does not currently create this key, but if there is one available, it can be shown via the `git:public-key` command. + +```shell +dokku git:public-key +``` diff --git a/plugins/git/functions b/plugins/git/functions index f5316de5d..450685c1a 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -234,22 +234,3 @@ cmd-git-glob() { fi git-shell -c "$args" } - -fn-git-create-hook() { - declare APP="$1" - local APP_PATH="$DOKKU_ROOT/$APP" - local PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" - - if [[ ! -d "$APP_PATH/refs" ]]; then - git init --bare "$APP_PATH" >/dev/null - fi - - cat >"$PRERECEIVE_HOOK" <, Adds a host to known_hosts + git:sync [--build] [], Clone or fetch an app from remote git repo git:initialize , Initialize a git repository for an app + git:public-key, Outputs the dokku public deploy key git:report [] [], Displays a git report for one or more apps git:set (), Set or clear a git property for an app help_content diff --git a/plugins/git/install b/plugins/git/install index bb13e8ef7..8e6cdbc1c 100755 --- a/plugins/git/install +++ b/plugins/git/install @@ -9,6 +9,9 @@ trigger-git-install() { declare desc="installs the git plugin" declare trigger="install" + mkdir -p "${DOKKU_LIB_ROOT}/data/git" + chown -R "${DOKKU_SYSTEM_USER}:${DOKKU_SYSTEM_GROUP}" "${DOKKU_LIB_ROOT}/data/git" + fn-plugin-property-setup "git" migrate_git_vars_0_12_0 "$@" } diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 525ad122e..95af4eeca 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -4,6 +4,72 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x +cmd-git-allow-host() { + declare desc="adds a host to known_hosts" + local cmd="git:allow-host" + [[ "$1" == "$cmd" ]] && shift 1 + declare HOST="$1" + [[ -z "$HOST" ]] && dokku_log_fail "Please supply a git host" + + ssh-keyscan -t rsa "$HOST" >> "$DOKKU_ROOT/.ssh/known_hosts" + dokku_log_info1 "$HOST added to known hosts" +} + +cmd-git-sync() { + declare desc="clone or fetch an app from remote git repo" + local cmd="git:sync" + [[ "$1" == "$cmd" ]] && shift 1 + declare APP GIT_REMOTE GIT_REF FLAG + + ARGS=() + for arg in "$@"; do + if [[ "$arg" == "--build" ]]; then + FLAG="--build" + continue + fi + + ARGS+=("$arg") + done + + APP="${ARGS[0]}" + GIT_REMOTE="${ARGS[1]}" + GIT_REF="${ARGS[2]}" + + verify_app_name "$APP" + + if [[ -z "$GIT_REMOTE" ]]; then + dokku_log_fail "Missing GIT_REMOTE parameter" + return + fi + + local APP_ROOT="$DOKKU_ROOT/$APP" + if [[ "$(git -C "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then + fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF" + else + fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF" + fi + + if [[ "$FLAG" == "--build" ]]; then + if [[ -n "$GIT_REF" ]]; then + GIT_REF="$(git -C "/home/dokku/$APP" rev-parse "$GIT_REF")" + plugn trigger receive-app "$APP" "$GIT_REF" + else + plugn trigger receive-app "$APP" + fi + fi +} + +cmd-git-public-key() { + declare desc="outputs the dokku public deploy key" + local cmd="git:public-key" + [[ "$1" == "$cmd" ]] && shift 1 + + if [[ ! -f "$DOKKU_ROOT/.ssh/id_rsa.pub" ]]; then + dokku_log_fail "There is no deploy key" + fi + cat "$DOKKU_ROOT/.ssh/id_rsa.pub" +} + cmd-git-report() { declare desc="displays a git report for one or more apps" declare cmd="git:report" @@ -41,7 +107,7 @@ cmd-git-report-single() { "--git-global-deploy-branch: $(fn-plugin-property-get "git" "--global" "deploy-branch" "master")" "--git-keep-git-dir: $(fn-plugin-property-get "git" "$APP" "keep-git-dir" "false")" "--git-rev-env-var: $(fn-plugin-property-get "git" "$APP" "rev-env-var" "GIT_REV")" - "--git-sha: $(GIT_DIR="$APP_DIR" git rev-parse --short HEAD 2>/dev/null || false)" + "--git-sha: $(git -C "$APP_DIR" rev-parse --short HEAD 2>/dev/null || false)" "--git-last-updated-at: $(fn-git-last-updated-at "$APP")" ) @@ -71,11 +137,105 @@ cmd-git-report-single() { fi } +fn-git-create-hook() { + declare APP="$1" + local APP_PATH="$DOKKU_ROOT/$APP" + local PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" + + if [[ ! -d "$APP_PATH/refs" ]]; then + git init -q --bare "$APP_PATH" >/dev/null + fi + + cat >"$PRERECEIVE_HOOK" < /dev/null' RETURN INT TERM EXIT + + is_ref=true + git clone --depth 1 -n -qq --branch "$GIT_REF" "$GIT_REMOTE" "$APP_CLONE_ROOT" 2>/dev/null && is_ref=false + rm -rf "$APP_CLONE_ROOT" + + if [[ "$is_ref" == "true" ]]; then + git clone -n -qq "$GIT_REMOTE" "$APP_CLONE_ROOT" 2>/dev/null + git -C "$APP_CLONE_ROOT" checkout -qq "$GIT_REF" + else + git clone -n -qq --branch "$GIT_REF" "$GIT_REMOTE" "$APP_CLONE_ROOT" 2>/dev/null + if git -C "$APP_CLONE_ROOT" show-ref --verify "refs/heads/$GIT_REF" >/dev/null 2>&1; then + dokku_log_verbose "Detected branch, setting deploy-branch to $GIT_REF" + fn-plugin-property-write "git" "$APP" "deploy-branch" "$GIT_REF" + fi + fi + + DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" + if [[ "$GIT_REF" != "$DOKKU_DEPLOY_BRANCH" ]]; then + if [[ "$is_ref" == "true" ]]; then + git -C "$APP_CLONE_ROOT" branch -qq -D "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true + fi + git -C "$APP_CLONE_ROOT" checkout -qq -b "$DOKKU_DEPLOY_BRANCH" + fi + + rsync -a "$APP_CLONE_ROOT/.git/" "$APP_ROOT" + fn-git-create-hook "$APP" +} + +fn-git-fetch() { + declare APP="$1" GIT_REMOTE="$2" GIT_REF="$3" + local DOKKU_DEPLOY_BRANCH + local APP_ROOT="$DOKKU_ROOT/$APP" + + if [[ "$(git -C "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then + dokku_log_fail "The fetch subcommand can only be executed for existing applications" + fi + + DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" + if ! git -C "$APP_ROOT" 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.'" + return + fi + + git -C "$APP_ROOT" remote rm remote > /dev/null 2>&1 || true + git -C "$APP_ROOT" remote add --mirror=fetch --no-tags remote "$GIT_REMOTE" + if [[ -z "$GIT_REF" ]]; then + git -C "$APP_ROOT" fetch --update-head-ok remote "$DOKKU_DEPLOY_BRANCH" + else + git -C "$APP_ROOT" fetch --update-head-ok remote + git -C "$APP_ROOT" update-ref "refs/heads/$DOKKU_DEPLOY_BRANCH" "$GIT_REF" + fi +} + fn-git-last-updated-at() { declare desc="retrieve the deploy branch for a given application" declare APP="$1" local DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" - local HEAD_FILE="/home/dokku/test/refs/heads/$DOKKU_DEPLOY_BRANCH" + local HEAD_FILE="/home/dokku/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH" if [[ -f "$HEAD_FILE" ]]; then stat -c %Y "$HEAD_FILE" diff --git a/plugins/git/post-app-clone-setup b/plugins/git/post-app-clone-setup index b0d6a21c0..9faa302bb 100755 --- a/plugins/git/post-app-clone-setup +++ b/plugins/git/post-app-clone-setup @@ -1,7 +1,7 @@ #!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" trigger-git-post-app-clone-setup() { declare desc="modifies git-hook" diff --git a/plugins/git/post-app-rename-setup b/plugins/git/post-app-rename-setup index 5ecec4cdb..937c39c76 100755 --- a/plugins/git/post-app-rename-setup +++ b/plugins/git/post-app-rename-setup @@ -1,7 +1,7 @@ #!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" trigger-git-post-app-rename-setup() { declare desc="modifies git-hook" diff --git a/plugins/git/post-create b/plugins/git/post-create index 0f6215836..d259475da 100755 --- a/plugins/git/post-create +++ b/plugins/git/post-create @@ -1,7 +1,7 @@ #!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_AVAILABLE_PATH/git/functions" trigger-git-post-create() { declare desc="initializes an app with the correct git repository structure" diff --git a/plugins/git/post-delete b/plugins/git/post-delete index 9caa12790..dad74439a 100755 --- a/plugins/git/post-delete +++ b/plugins/git/post-delete @@ -1,7 +1,7 @@ #!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" 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" diff --git a/plugins/git/receive-app b/plugins/git/receive-app index 9a2f2de6e..1c09982b4 100755 --- a/plugins/git/receive-app +++ b/plugins/git/receive-app @@ -1,6 +1,6 @@ #!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/git/functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_AVAILABLE_PATH/git/functions" git_receive_app "$@" diff --git a/plugins/git/subcommands/allow-host b/plugins/git/subcommands/allow-host new file mode 100755 index 000000000..e24ce7ffb --- /dev/null +++ b/plugins/git/subcommands/allow-host @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-git-allow-host "$@" diff --git a/plugins/git/subcommands/initialize b/plugins/git/subcommands/initialize index fc2d85dbf..92c833709 100755 --- a/plugins/git/subcommands/initialize +++ b/plugins/git/subcommands/initialize @@ -1,6 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/git/functions" +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x diff --git a/plugins/git/subcommands/public-key b/plugins/git/subcommands/public-key new file mode 100755 index 000000000..11c04bb5e --- /dev/null +++ b/plugins/git/subcommands/public-key @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-git-public-key "$@" diff --git a/plugins/git/subcommands/sync b/plugins/git/subcommands/sync new file mode 100755 index 000000000..3bc9c92c3 --- /dev/null +++ b/plugins/git/subcommands/sync @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-git-sync "$@" diff --git a/tests/unit/git_1.bats b/tests/unit/git_1.bats index 63bf3714b..cb49ea9a1 100644 --- a/tests/unit/git_1.bats +++ b/tests/unit/git_1.bats @@ -27,7 +27,7 @@ teardown() { } @test "(git) ensure GIT_REV env var is set" { - deploy_app + run deploy_app echo "output: $output" echo "status: $status" assert_success @@ -44,7 +44,7 @@ teardown() { echo "status: $status" assert_success - deploy_app + run deploy_app echo "output: $output" echo "status: $status" assert_success @@ -61,7 +61,7 @@ teardown() { echo "status: $status" assert_success - deploy_app + run deploy_app echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/git_3.bats b/tests/unit/git_3.bats new file mode 100644 index 000000000..7586b0b5a --- /dev/null +++ b/tests/unit/git_3.bats @@ -0,0 +1,292 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app + touch /home/dokku/.ssh/known_hosts + chown dokku:dokku /home/dokku/.ssh/known_hosts +} + +teardown() { + rm -f /home/dokku/.ssh/id_rsa.pub || true + destroy_app + global_teardown +} + +@test "(git) git:allow-host" { + run /bin/bash -c "dokku git:allow-host" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "cat /home/dokku/.ssh/known_hosts | wc -l" + echo "output: $output" + echo "status: $status" + assert_success + start_lines=$output + + run /bin/bash -c "dokku git:allow-host github.com" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "cat /home/dokku/.ssh/known_hosts | wc -l" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "test -f /home/dokku/.ssh/known_hosts" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "cat /home/dokku/.ssh/known_hosts | wc -l" + echo "output: $output" + echo "status: $status" + assert_success + assert_equal "$output" "$((start_lines + 1))" + + run /bin/bash -c "dokku git:allow-host github.com" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "cat /home/dokku/.ssh/known_hosts | wc -l" + echo "output: $output" + echo "status: $status" + assert_success + assert_equal "$output" "$((start_lines + 2))" +} + +@test "(git) git:sync new [errors]" { + run /bin/bash -c "dokku git:sync" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku git:sync $TEST_APP-non-existent" + echo "output: $output" + echo "status: $status" + assert_failure + + run create_app "$TEST_APP-non-existent" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync $TEST_APP-non-existent" + echo "output: $output" + echo "status: $status" + assert_failure + + run destroy_app 0 "$TEST_APP-non-existent" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync new [--no-build noarg]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync new [--no-build branch]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync new [--no-build tag]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync new [--no-build commit]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync new [--build noarg]" { + run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Application deployed" +} + +@test "(git) git:sync new [--build branch]" { + run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Application deployed" +} + +@test "(git) git:sync new [--build tag]" { + run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Application deployed" +} + +@test "(git) git:sync new [--build commit]" { + run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Application deployed" +} + +@test "(git) git:sync existing [errors]" { + run /bin/bash -c "dokku git:sync" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku git:sync $TEST_APP-non-existent" + echo "output: $output" + echo "status: $status" + assert_failure + + run create_app "$TEST_APP-non-existent" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync $TEST_APP-non-existent" + echo "output: $output" + echo "status: $status" + assert_failure + + run destroy_app 0 "$TEST_APP-non-existent" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync existing [--no-build noarg]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync existing [--no-build branch]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync existing [--no-build tag]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync existing [--no-build commit]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:sync existing [--build noarg]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Application deployed" +} + +@test "(git) git:sync existing [--build branch]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Application deployed" +} + +@test "(git) git:sync existing [--build tag]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Application deployed" +} + +@test "(git) git:sync existing [--build commit]" { + run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Application deployed" +} + +@test "(git) git:public-key" { + run /bin/bash -c "dokku git:public-key" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "cp /root/.ssh/dokku_test_rsa.pub /home/dokku/.ssh/id_rsa.pub" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:public-key" + echo "output: $output" + echo "status: $status" + assert_success +}