Merge pull request #6724 from dokku/git-fix-empty-repo-check

Correctly check if a repository has code or not in git plugin
This commit is contained in:
Jose Diaz-Gonzalez
2024-03-14 10:52:17 -04:00
committed by GitHub
3 changed files with 12 additions and 10 deletions

View File

@@ -17,10 +17,9 @@ trigger-git-git-from-directory() {
local TMP_WORK_DIR_2=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_WORK_DIR' '$TMP_WORK_DIR_2' >/dev/null" RETURN INT TERM EXIT
local has_code=true
local git_objects="$(fn-git-cmd "$APP_ROOT" count-objects 2>/dev/null || true)"
if [[ -z "$git_objects" ]] || [[ "$git_objects" == "0 objects, 0 kilobytes" ]]; then
local has_code=false
local has_code=false
if fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then
has_code=true
fi
dokku_log_info1 "Updating git repository with specified build context"

View File

@@ -208,14 +208,14 @@ cmd-git-sync() {
fi
local APP_ROOT="$DOKKU_ROOT/$APP"
DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")"
CURRENT_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true)"
if [[ "$(fn-git-cmd "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then
if ! fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then
dokku_log_info1_quiet "Cloning $APP from $GIT_REMOTE#$GIT_REF"
fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF"
else
dokku_log_verbose "Fetching remote code for $APP from $GIT_REMOTE#$GIT_REF"
fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF"
fi
@@ -376,7 +376,8 @@ fn-git-clone() {
local APP_ROOT="$DOKKU_ROOT/$APP"
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
if [[ "$(fn-git-cmd "$APP_ROOT" count-objects)" != "0 objects, 0 kilobytes" ]]; then
local DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")"
if fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then
dokku_log_fail "The clone subcommand can only be executed for new applications"
fi
@@ -438,7 +439,8 @@ fn-git-fetch() {
local DOKKU_DEPLOY_BRANCH
local APP_ROOT="$DOKKU_ROOT/$APP"
if [[ "$(fn-git-cmd "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then
local DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")"
if ! fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then
dokku_log_fail "The fetch subcommand can only be executed for existing applications"
fi

View File

@@ -306,7 +306,7 @@ teardown() {
}
@test "(git) git:sync existing [--no-build noarg]" {
run /bin/bash -c "dokku --trace git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
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
@@ -317,10 +317,11 @@ teardown() {
assert_success
assert_output_contains "$SMOKE_TEST_APP_1_0_0_SHA"
run /bin/bash -c "dokku --trace git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git"
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
assert_output_contains "Fetching remote code for"
run /bin/bash -c "cat /home/dokku/$TEST_APP/refs/heads/master"
echo "output: $output"