From 8faa338bd42551d62213b6da377b1607782ca04d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Mar 2023 01:24:12 -0400 Subject: [PATCH 1/4] fix: ensure users can push from an image-deploy repository and respect deploy-branch Previously, we created this weird bare repo that didn't do set all the normal git config. This change switches to cloning the local temp directory, fixing the `receive.denyCurrentBranch` property that blocked pushing to this weird bare repo after calling git:from-image or git:from-archive. Additionally, since we now use a git clone, we set the default branch correctly, ensuring git pushes later on that branch work as expected (and not on master if it was customized prior to app creation). Closes #5601 Closes #5662 --- plugins/git/git-from-directory | 5 +++-- plugins/git/internal-functions | 2 +- tests/unit/git_4.bats | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/plugins/git/git-from-directory b/plugins/git/git-from-directory index 3958f4566..8ab471880 100755 --- a/plugins/git/git-from-directory +++ b/plugins/git/git-from-directory @@ -27,16 +27,17 @@ trigger-git-git-from-directory() { dokku_log_info1 "Updating git repository with specified build context" if [[ "$has_code" == "false" ]]; then # setup new repo + local DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" cp -rT "$SOURCECODE_WORK_DIR" "$TMP_WORK_DIR" suppress_output fn-git-cmd "$TMP_WORK_DIR" init + suppress_output fn-git-cmd "$TMP_WORK_DIR" config init.defaultBranch "$DEPLOY_BRANCH" suppress_output fn-git-cmd "$TMP_WORK_DIR" config user.name "$USER_NAME" suppress_output fn-git-cmd "$TMP_WORK_DIR" config user.email "$USER_EMAIL" suppress_output fn-git-cmd "$TMP_WORK_DIR" add --all suppress_output fn-git-cmd "$TMP_WORK_DIR" commit -m "Initial commit" REV="$(fn-git-cmd "$TMP_WORK_DIR" rev-parse HEAD)" - rsync -a "$TMP_WORK_DIR/.git/" "$APP_ROOT" - fn-git-create-hook "$APP" + fn-git-clone "$APP" "$TMP_WORK_DIR" "$DEPLOY_BRANCH" else # update existing repo GIT_TERMINAL_PROMPT=0 suppress_output git clone "$APP_ROOT" "$TMP_WORK_DIR_2" diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index bb58a2111..531eb66dd 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -202,6 +202,7 @@ cmd-git-sync() { local APP_ROOT="$DOKKU_ROOT/$APP" if [[ "$(fn-git-cmd "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then + dokku_log_info1_quiet "Cloning $APP from $GIT_REMOTE#$GIT_REF" fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF" else fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF" @@ -394,7 +395,6 @@ fn-git-clone() { GIT_REF="$(fn-git-deploy-branch "$APP")" fi - dokku_log_info1_quiet "Cloning $APP from $GIT_REMOTE#$GIT_REF" trap "rm -rf '$APP_CLONE_ROOT' > /dev/null" RETURN INT TERM EXIT is_ref=true diff --git a/tests/unit/git_4.bats b/tests/unit/git_4.bats index 05bcb7853..f6441333b 100644 --- a/tests/unit/git_4.bats +++ b/tests/unit/git_4.bats @@ -27,6 +27,30 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + + run /bin/bash -c "cat /home/dokku/$TEST_APP/HEAD" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "ref: refs/heads/master" +} + +@test "(git) git:from-image [normal-custom-branch]" { + run /bin/bash -c "dokku git:set $TEST_APP deploy-branch main" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku git:from-image $TEST_APP linuxserver/foldingathome:7.5.1-ls1" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "cat /home/dokku/$TEST_APP/HEAD" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "ref: refs/heads/main" } @test "(git) git:from-image [normal-git-init]" { From 1a320eafadc8763826c50933dae33909f078cafd Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 28 May 2023 03:07:54 -0400 Subject: [PATCH 2/4] fix: add missing hook creation before clone In the case where a repository is new, the check to see if it is an empty repo during clone fails. We therefore create the initial repo via the fn-git-create-hook call when initializing the repo. --- plugins/git/git-from-directory | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/git/git-from-directory b/plugins/git/git-from-directory index 8ab471880..980d663e5 100755 --- a/plugins/git/git-from-directory +++ b/plugins/git/git-from-directory @@ -37,6 +37,7 @@ trigger-git-git-from-directory() { suppress_output fn-git-cmd "$TMP_WORK_DIR" commit -m "Initial commit" REV="$(fn-git-cmd "$TMP_WORK_DIR" rev-parse HEAD)" + fn-git-create-hook "$APP" fn-git-clone "$APP" "$TMP_WORK_DIR" "$DEPLOY_BRANCH" else # update existing repo From 9f3879b22552a8db03b9e8aa8ee92ce88bb0af94 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 28 May 2023 05:38:02 -0400 Subject: [PATCH 3/4] chore: update the image being used for the test --- tests/unit/git_4.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/git_4.bats b/tests/unit/git_4.bats index f6441333b..601df2b64 100644 --- a/tests/unit/git_4.bats +++ b/tests/unit/git_4.bats @@ -41,7 +41,7 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "dokku git:from-image $TEST_APP linuxserver/foldingathome:7.5.1-ls1" + run /bin/bash -c "dokku git:from-image $TEST_APP linuxserver/foldingathome:7.6.21" echo "output: $output" echo "status: $status" assert_success From 70a1b6a86341a2d73785ec7acfa19eb11e40390a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 28 May 2023 05:38:57 -0400 Subject: [PATCH 4/4] fix: checkout the deploy branch when initializing a new repo The initial-branch flag only works on newer versions of git - 2.28.0+ - and the init.defaultBranch config is otherwise also ignored until then. --- plugins/git/git-from-directory | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/git/git-from-directory b/plugins/git/git-from-directory index 980d663e5..9f94568c5 100755 --- a/plugins/git/git-from-directory +++ b/plugins/git/git-from-directory @@ -30,6 +30,7 @@ trigger-git-git-from-directory() { local DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" cp -rT "$SOURCECODE_WORK_DIR" "$TMP_WORK_DIR" suppress_output fn-git-cmd "$TMP_WORK_DIR" init + suppress_output fn-git-cmd "$TMP_WORK_DIR" checkout -b "$DEPLOY_BRANCH" suppress_output fn-git-cmd "$TMP_WORK_DIR" config init.defaultBranch "$DEPLOY_BRANCH" suppress_output fn-git-cmd "$TMP_WORK_DIR" config user.name "$USER_NAME" suppress_output fn-git-cmd "$TMP_WORK_DIR" config user.email "$USER_EMAIL"