diff --git a/tests/integration/app_new.bats b/tests/integration/app_new.bats index 4ef94aac..366d21e5 100644 --- a/tests/integration/app_new.bats +++ b/tests/integration/app_new.bats @@ -122,6 +122,39 @@ teardown(){ assert_failure } +@test "create new app with commit from another branch" { + branchHash=$(_get_other_branch_hash) + if [[ -z "$branchHash" ]]; then + skip "$TEST_RECIPE has no branch besides main" + fi + + # re-clone the recipe the way an older abra did, with a single-branch refspec. --no-local + # forces a real transfer, a local clone would hardlink the whole object database and leave + # the commit reachable + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE" + assert_success + + run git clone -q --no-local --single-branch --branch main \ + "$ABRA_DIR/origin-recipes/$TEST_RECIPE.git" "$ABRA_DIR/recipes/$TEST_RECIPE" + assert_success + + # the commit has to be genuinely missing, otherwise this test passes for the wrong reason + run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --verify "$branchHash^{commit}" + assert_failure + + run $ABRA app new "$TEST_RECIPE" "$branchHash" \ + --no-input \ + --server "$TEST_SERVER" \ + --domain "$TEST_APP_DOMAIN" + assert_success + assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + + # the recipe names itself in TYPE, which differs per branch, so only the version is checked + run grep -q "TYPE=.*:${branchHash}$" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + @test "does not overwrite existing env files" { run $ABRA app new "$TEST_RECIPE" \ --no-input \ diff --git a/tests/integration/helpers/git.bash b/tests/integration/helpers/git.bash index cad782a8..01f6b034 100644 --- a/tests/integration/helpers/git.bash +++ b/tests/integration/helpers/git.bash @@ -56,6 +56,13 @@ _get_tag_hash() { echo $(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-list -n 1 "$1") } +_get_other_branch_hash() { + # asked from the origin mirror, not from the recipe checkout, so that the result does not + # depend on what has been fetched. empty when the recipe only has a default branch + echo $(git ls-remote "$ABRA_DIR/origin-recipes/$TEST_RECIPE.git" \ + | grep 'refs/heads/' | grep -v 'refs/heads/main$' | head -1 | cut -f1) +} + _get_head_hash() { echo $(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" show -s --format="%H" HEAD) }