Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly disambiguate between branch or file checkout #199

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ _switch_to_branch() {
else
# Switch to branch from current Workflow run
# shellcheck disable=SC2086
git checkout $INPUT_BRANCH;
git checkout $INPUT_BRANCH --;
fi
}

Expand Down
26 changes: 26 additions & 0 deletions tests/git-auto-commit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,29 @@ git_auto_commit() {
run git status
assert_output --partial 'nothing to commit, working tree clean'
}

@test "It does not throw an error if branch is checked out with same name as a file or folder in the repo" {

# Add File called dev and commit/push
echo "Create dev file";
cd "${FAKE_LOCAL_REPOSITORY}";
echo this is a file named dev > dev
git add dev
git commit -m 'add file named dev'
git update-ref refs/remotes/origin/master master
git update-ref refs/remotes/origin/dev master

# ---

INPUT_BRANCH=dev

touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{4,5,6}.txt

run git_auto_commit

assert_success

assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line "::debug::Push commit to remote branch dev"
}