Skip to content

Commit bf0575d

Browse files
Throw error if repo is in detached state
1 parent 8601493 commit bf0575d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/git-auto-commit.bats

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,26 @@ END
10891089
run git_auto_commit
10901090

10911091
assert_failure;
1092-
assert_line "::error::git-status failed with:<fatal: not a git repository (or any of the parent directories): .git>"
1092+
assert_line "::error::Not a git repository. Please make sure to run this action in a git repository. Adjust the `repository` input if necessary."
1093+
}
1094+
1095+
@test "It detects if the repository is in a detached state and exits with an error" {
1096+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
1097+
1098+
run git_auto_commit
1099+
1100+
assert_success
1101+
1102+
# Bring local repository into a detached state
1103+
prev_commit=$(git rev-parse HEAD~1);
1104+
git checkout "$prev_commit";
1105+
1106+
touch "${FAKE_TEMP_LOCAL_REPOSITORY}"/remote-files{4,5,6}.txt
1107+
1108+
run git_auto_commit
1109+
1110+
assert_failure;
1111+
assert_line "::error::Repository is in detached HEAD state. Please checkout a branch before committing."
10931112
}
10941113

10951114
@test "it creates a tag if create_git_tag_only is set to true and a message has been supplied" {

0 commit comments

Comments
 (0)