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:
@@ -17,10 +17,9 @@ trigger-git-git-from-directory() {
|
|||||||
local TMP_WORK_DIR_2=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
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
|
trap "rm -rf '$TMP_WORK_DIR' '$TMP_WORK_DIR_2' >/dev/null" RETURN INT TERM EXIT
|
||||||
|
|
||||||
local has_code=true
|
local has_code=false
|
||||||
local git_objects="$(fn-git-cmd "$APP_ROOT" count-objects 2>/dev/null || true)"
|
if fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then
|
||||||
if [[ -z "$git_objects" ]] || [[ "$git_objects" == "0 objects, 0 kilobytes" ]]; then
|
has_code=true
|
||||||
local has_code=false
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dokku_log_info1 "Updating git repository with specified build context"
|
dokku_log_info1 "Updating git repository with specified build context"
|
||||||
|
|||||||
@@ -208,14 +208,14 @@ cmd-git-sync() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local APP_ROOT="$DOKKU_ROOT/$APP"
|
local APP_ROOT="$DOKKU_ROOT/$APP"
|
||||||
|
|
||||||
DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$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)"
|
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"
|
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"
|
||||||
else
|
else
|
||||||
|
dokku_log_verbose "Fetching remote code for $APP from $GIT_REMOTE#$GIT_REF"
|
||||||
fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF"
|
fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -376,7 +376,8 @@ fn-git-clone() {
|
|||||||
local APP_ROOT="$DOKKU_ROOT/$APP"
|
local APP_ROOT="$DOKKU_ROOT/$APP"
|
||||||
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
[[ -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"
|
dokku_log_fail "The clone subcommand can only be executed for new applications"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -438,7 +439,8 @@ fn-git-fetch() {
|
|||||||
local DOKKU_DEPLOY_BRANCH
|
local DOKKU_DEPLOY_BRANCH
|
||||||
local APP_ROOT="$DOKKU_ROOT/$APP"
|
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"
|
dokku_log_fail "The fetch subcommand can only be executed for existing applications"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ teardown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "(git) git:sync existing [--no-build noarg]" {
|
@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 "output: $output"
|
||||||
echo "status: $status"
|
echo "status: $status"
|
||||||
assert_success
|
assert_success
|
||||||
@@ -317,10 +317,11 @@ teardown() {
|
|||||||
assert_success
|
assert_success
|
||||||
assert_output_contains "$SMOKE_TEST_APP_1_0_0_SHA"
|
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 "output: $output"
|
||||||
echo "status: $status"
|
echo "status: $status"
|
||||||
assert_success
|
assert_success
|
||||||
|
assert_output_contains "Fetching remote code for"
|
||||||
|
|
||||||
run /bin/bash -c "cat /home/dokku/$TEST_APP/refs/heads/master"
|
run /bin/bash -c "cat /home/dokku/$TEST_APP/refs/heads/master"
|
||||||
echo "output: $output"
|
echo "output: $output"
|
||||||
|
|||||||
Reference in New Issue
Block a user