diff --git a/plugins/git/git-from-directory b/plugins/git/git-from-directory index 03e7058de..771a7bba9 100755 --- a/plugins/git/git-from-directory +++ b/plugins/git/git-from-directory @@ -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" diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 9675cb1e6..f5fb38507 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -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 diff --git a/tests/unit/git_3.bats b/tests/unit/git_3.bats index 042431ff6..1361181f0 100644 --- a/tests/unit/git_3.bats +++ b/tests/unit/git_3.bats @@ -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"