From efd25cfb458c618ce79be5d1dbc7d3f2777d6a52 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 19 Oct 2025 22:12:34 -0400 Subject: [PATCH 1/3] fix: ensure the pre-receive hook and URLS files are correct when cloning or renaming apps Closes #8035 --- plugins/git/post-app-clone-setup | 10 +++++----- plugins/git/post-app-rename-setup | 10 +++++----- tests/unit/apps_1.bats | 6 ++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/git/post-app-clone-setup b/plugins/git/post-app-clone-setup index 04d9c5855..89396095e 100755 --- a/plugins/git/post-app-clone-setup +++ b/plugins/git/post-app-clone-setup @@ -8,15 +8,15 @@ trigger-git-post-app-clone-setup() { declare trigger="post-app-clone-setup" declare OLD_APP="$1" NEW_APP="$2" - if [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]]; then - sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" - fi - fn-plugin-property-clone "git" "$OLD_APP" "$NEW_APP" pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null - find ./* \( -name ".cache" -o -name "cache" -o -name "VHOST" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" + find ./* \( -name ".cache" -o -name "cache" -o -name "VHOST" -o -name "URLS" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" popd &>/dev/null || pushd "/tmp" >/dev/null + + if [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]]; then + sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" + fi } trigger-git-post-app-clone-setup "$@" diff --git a/plugins/git/post-app-rename-setup b/plugins/git/post-app-rename-setup index 0482d58e2..2948823ad 100755 --- a/plugins/git/post-app-rename-setup +++ b/plugins/git/post-app-rename-setup @@ -8,16 +8,16 @@ trigger-git-post-app-rename-setup() { declare trigger="post-app-rename-setup" declare OLD_APP="$1" NEW_APP="$2" - if [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]]; then - sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" - fi - fn-plugin-property-clone "git" "$OLD_APP" "$NEW_APP" fn-plugin-property-destroy "git" "$OLD_APP" pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null - find ./* \( -name ".cache" -o -name "cache" -o -name "VHOST" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" + find ./* \( -name ".cache" -o -name "cache" -o -name "VHOST" -o -name "URLS" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" popd &>/dev/null || pushd "/tmp" >/dev/null + + if [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]]; then + sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" + fi } trigger-git-post-app-rename-setup "$@" diff --git a/tests/unit/apps_1.bats b/tests/unit/apps_1.bats index 5b85ffacd..ec0742092 100644 --- a/tests/unit/apps_1.bats +++ b/tests/unit/apps_1.bats @@ -152,10 +152,16 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + assert_output_contains "git-hook $TEST_APP" run /bin/bash -c "dokku apps:rename $TEST_APP great-test-name" echo "output: $output" echo "status: $status" assert_success + run /bin/bash -c "cat $DOKKU_ROOT/$TEST_APP/hooks/pre-receive" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "git-hook great-test-name" run /bin/bash -c "dokku apps:list | grep $TEST_APP" echo "output: $output" echo "status: $status" From 8afe8d5f13f84ab4738977e4a21b2c6a1aca183a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 25 Oct 2025 07:20:17 -0400 Subject: [PATCH 2/3] refactor: use fn-git-create-hook --- plugins/git/post-app-clone-setup | 5 ++--- plugins/git/post-app-rename-setup | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/git/post-app-clone-setup b/plugins/git/post-app-clone-setup index 89396095e..8d9939d5c 100755 --- a/plugins/git/post-app-clone-setup +++ b/plugins/git/post-app-clone-setup @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -14,9 +15,7 @@ trigger-git-post-app-clone-setup() { find ./* \( -name ".cache" -o -name "cache" -o -name "VHOST" -o -name "URLS" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" popd &>/dev/null || pushd "/tmp" >/dev/null - if [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]]; then - sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" - fi + fn-git-create-hook "$NEW_APP" } trigger-git-post-app-clone-setup "$@" diff --git a/plugins/git/post-app-rename-setup b/plugins/git/post-app-rename-setup index 2948823ad..1398cabd1 100755 --- a/plugins/git/post-app-rename-setup +++ b/plugins/git/post-app-rename-setup @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -15,9 +16,7 @@ trigger-git-post-app-rename-setup() { find ./* \( -name ".cache" -o -name "cache" -o -name "VHOST" -o -name "URLS" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" popd &>/dev/null || pushd "/tmp" >/dev/null - if [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]]; then - sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" - fi + fn-git-create-hook "$NEW_APP" } trigger-git-post-app-rename-setup "$@" From 416222b20a110edbf93e87ee67f38b86ef3bdd00 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 27 Oct 2025 00:07:19 -0400 Subject: [PATCH 3/3] fix: correctly check the git-hook --- tests/unit/apps_1.bats | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/apps_1.bats b/tests/unit/apps_1.bats index ec0742092..9d6d3f425 100644 --- a/tests/unit/apps_1.bats +++ b/tests/unit/apps_1.bats @@ -152,12 +152,16 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + run /bin/bash -c "cat $DOKKU_ROOT/$TEST_APP/hooks/pre-receive" + echo "output: $output" + echo "status: $status" + assert_success assert_output_contains "git-hook $TEST_APP" run /bin/bash -c "dokku apps:rename $TEST_APP great-test-name" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "cat $DOKKU_ROOT/$TEST_APP/hooks/pre-receive" + run /bin/bash -c "cat $DOKKU_ROOT/great-test-name/hooks/pre-receive" echo "output: $output" echo "status: $status" assert_success