From 7c71bd3dcf97cfdffdbb676195d4572c4430e96f Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 23 Feb 2022 20:59:07 +0100 Subject: [PATCH] Assert script fails if branch does not exist --- tests/git-auto-commit.bats | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 61b8deb..98018a9 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -535,8 +535,35 @@ git_auto_commit() { assert_line "::debug::Push commit to remote branch dev" } -@test "It creates new local branch and pushes the new branch to remote" { +@test "script fails to push commit to new branch that does not exist yet" { + INPUT_BRANCH="not-existend-branch" + INPUT_CREATE_BRANCH=false + run git branch + refute_line --partial "not-existend-branch" + + run git branch -r + refute_line --partial "origin/not-existend-branch" + + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt + + run git_auto_commit + + assert_failure + + assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" + assert_line "::set-output name=changes_detected::true" + assert_line "INPUT_BRANCH value: not-existend-branch" + assert_line "fatal: invalid reference: not-existend-branch" + + run git branch + refute_line --partial "not-existend-branch" + + run git branch -r + refute_line --partial "origin/not-existend-branch" +} + +@test "It creates new local branch and pushes the new branch to remote" { INPUT_BRANCH="not-existend-branch" INPUT_CREATE_BRANCH=true