feat: add the ability to skip setting the deploy-branch when running git:sync

Closes #8212
This commit is contained in:
Jose Diaz-Gonzalez
2026-01-08 02:19:22 -05:00
parent 924d010330
commit dd70fb823d
4 changed files with 124 additions and 7 deletions

View File

@@ -10,7 +10,7 @@ git:from-archive [--archive-type ARCHIVE_TYPE] <app> <archive-url> [<git-usernam
git:from-image [--build-dir DIRECTORY] <app> <docker-image> [<git-username> <git-email>] # Updates an app's git repository with a given docker image
git:generate-deploy-key # Generates a deploy ssh key
git:load-image [--build-dir DIRECTORY] <app> <docker-image> [<git-username> <git-email>] # Updates an app's git repository with a docker image loaded from stdin
git:sync [--build|build-if-changes] <app> <repository> [<git-ref>] # Clone or fetch an app from remote git repo
git:sync [--build|--build-if-changes] [--skip-deploy-branch] <app> <repository> [<git-ref>] # Clone or fetch an app from remote git repo
git:initialize <app> # Initialize a git repository for an app
git:public-key # Outputs the dokku public deploy key
git:report [<app>] [<flag>] # Displays a git report for one or more apps
@@ -163,6 +163,12 @@ When running `git:sync` without a reference, it may be useful to only build when
dokku git:sync --build-if-changes node-js-app https://github.com/heroku/node-js-getting-started.git
```
By default, when running `git:sync` with a git branch reference, Dokku will automatically set the `deploy-branch` property to the specified branch. To skip setting the deploy branch, specify the `--skip-deploy-branch` flag.
```shell
dokku git:sync --skip-deploy-branch node-js-app https://github.com/heroku/node-js-getting-started.git main
```
### Initializing from private repositories
> [!IMPORTANT]

View File

@@ -32,7 +32,7 @@ fn-help-content() {
git:from-archive <app> <archive-url> [<git-username> <git-email>], Updates an app's git repository with a given archive file
git:from-image <app> <docker-image> [<git-username> <git-email>], Updates an app's git repository with a given docker image
git:load-image <app> <docker-image> [<git-username> <git-email>], Updates an app's git repository with a docker image loaded from stdin
git:sync [--build] <app> <repository> [<git-ref>], Clone or fetch an app from remote git repo
git:sync [--build|--build-if-changes] [--skip-deploy-branch] <app> <repository> [<git-ref>], Clone or fetch an app from remote git repo
git:initialize <app>, Initialize a git repository for an app
git:generate-deploy-key, Generates a deploy ssh key
git:public-key, Outputs the dokku public deploy key

View File

@@ -179,7 +179,7 @@ cmd-git-sync() {
local cmd="git:sync"
[[ "$1" == "$cmd" ]] && shift 1
declare APP GIT_REMOTE GIT_REF FLAG
local CURRENT_REF DOKKU_DEPLOY_BRANCH SHOULD_BUILD UPDATED_REF
local CURRENT_REF DOKKU_DEPLOY_BRANCH SHOULD_BUILD SKIP_DEPLOY_BRANCH UPDATED_REF
ARGS=()
for arg in "$@"; do
@@ -193,6 +193,11 @@ cmd-git-sync() {
continue
fi
if [[ "$arg" == "--skip-deploy-branch" ]]; then
SKIP_DEPLOY_BRANCH="true"
continue
fi
ARGS+=("$arg")
done
@@ -213,7 +218,7 @@ cmd-git-sync() {
if ! fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" &>/dev/null; then
dokku_log_info1_quiet "Cloning $APP from $GIT_REMOTE#$GIT_REF"
fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF"
fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF" "$SKIP_DEPLOY_BRANCH"
else
dokku_log_verbose "Fetching remote code for $APP from $GIT_REMOTE#$GIT_REF"
fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF"
@@ -373,7 +378,7 @@ EOF
fn-git-clone() {
declare desc="creates an app from remote git repo"
declare APP="$1" GIT_REMOTE="$2" GIT_REF="$3"
declare APP="$1" GIT_REMOTE="$2" GIT_REF="$3" SKIP_DEPLOY_BRANCH="$4"
local APP_ROOT="$DOKKU_ROOT/$APP"
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
@@ -404,8 +409,12 @@ fn-git-clone() {
else
GIT_TERMINAL_PROMPT=0 suppress_output git clone -n --branch "$GIT_REF" "$GIT_REMOTE" "$TMP_CLONE_DIR"
if fn-git-cmd "$TMP_CLONE_DIR" show-ref --verify "refs/heads/$GIT_REF" &>/dev/null; then
dokku_log_verbose "Detected branch, setting deploy-branch to $GIT_REF"
fn-plugin-property-write "git" "$APP" "deploy-branch" "$GIT_REF"
if [[ "$SKIP_DEPLOY_BRANCH" != "true" ]]; then
dokku_log_verbose "Detected branch, setting deploy-branch to $GIT_REF"
fn-plugin-property-write "git" "$APP" "deploy-branch" "$GIT_REF"
else
dokku_log_verbose "Detected branch $GIT_REF, skipping deploy-branch setting"
fi
fi
fi

View File

@@ -629,3 +629,105 @@ teardown() {
echo "status: $status"
assert_success
}
@test "(git:sync) --skip-deploy-branch" {
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "master"
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
assert_output_contains "Detected branch, setting deploy-branch to another-branch"
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "another-branch"
run destroy_app
echo "output: $output"
echo "status: $status"
assert_success
run create_app
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "master"
run /bin/bash -c "dokku git:sync --skip-deploy-branch $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "skipping deploy-branch setting"
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "master"
}
@test "(git:sync) --build --skip-deploy-branch" {
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "master"
run /bin/bash -c "dokku git:sync --build --skip-deploy-branch $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "skipping deploy-branch setting"
assert_output_contains "Application deployed"
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "master"
}
@test "(git:sync) --build-if-changes --skip-deploy-branch" {
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "master"
run /bin/bash -c "dokku git:sync --build-if-changes --skip-deploy-branch $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "skipping deploy-branch setting"
assert_output_contains "Application deployed"
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "master"
run /bin/bash -c "dokku git:sync --build-if-changes --skip-deploy-branch $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Skipping build as no changes were detected"
run /bin/bash -c "dokku git:report $TEST_APP --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "master"
}