mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-04-20 00:39:45 +08:00
Merge pull request #357 from stefanzweifel/v6-detect-detached-state
This commit is contained in:
commit
ed295bd35a
2
.github/workflows/git-auto-commit.yml
vendored
2
.github/workflows/git-auto-commit.yml
vendored
@ -17,6 +17,8 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.head_ref }}
|
||||||
|
|
||||||
- name: Use git-auto-commit-action
|
- name: Use git-auto-commit-action
|
||||||
id: "auto-commit-action"
|
id: "auto-commit-action"
|
||||||
|
@ -31,6 +31,10 @@ _main() {
|
|||||||
|
|
||||||
_switch_to_repository
|
_switch_to_repository
|
||||||
|
|
||||||
|
_check_if_is_git_repository
|
||||||
|
|
||||||
|
_check_if_repository_is_in_detached_state
|
||||||
|
|
||||||
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
|
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
|
||||||
|
|
||||||
_set_github_output "changes_detected" "true"
|
_set_github_output "changes_detected" "true"
|
||||||
@ -84,11 +88,26 @@ _git_is_dirty() {
|
|||||||
gitStatusMessage="$((git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}} >/dev/null ) 2>&1)";
|
gitStatusMessage="$((git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}} >/dev/null ) 2>&1)";
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
gitStatus="$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})";
|
gitStatus="$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})";
|
||||||
if [ $? -ne 0 ]; then
|
[ -n "$gitStatus" ]
|
||||||
_log "error" "git-status failed with:<$gitStatusMessage>";
|
}
|
||||||
|
|
||||||
|
_check_if_is_git_repository() {
|
||||||
|
if [ -d ".git" ]; then
|
||||||
|
_log "debug" "Repository found.";
|
||||||
|
else
|
||||||
|
_log "error" "Not a git repository. Please make sure to run this action in a git repository. Adjust the `repository` input if necessary.";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
[ -n "$gitStatus" ]
|
}
|
||||||
|
|
||||||
|
_check_if_repository_is_in_detached_state() {
|
||||||
|
if [ -z "$(git symbolic-ref HEAD)" ]
|
||||||
|
then
|
||||||
|
_log "error" "Repository is in detached HEAD state. Please make sure you check out a branch. Adjust the `ref` input accordingly.";
|
||||||
|
exit 1;
|
||||||
|
else
|
||||||
|
_log "debug" "Repository is on a branch.";
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_add_files() {
|
_add_files() {
|
||||||
|
@ -1088,5 +1088,24 @@ END
|
|||||||
run git_auto_commit
|
run git_auto_commit
|
||||||
|
|
||||||
assert_failure;
|
assert_failure;
|
||||||
assert_line "::error::git-status failed with:<fatal: not a git repository (or any of the parent directories): .git>"
|
assert_line "::error::Not a git repository. Please make sure to run this action in a git repository. Adjust the `repository` input if necessary."
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It detects if the repository is in a detached state and exits with an error" {
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
# Bring local repository into a detached state
|
||||||
|
prev_commit=$(git rev-parse HEAD~1);
|
||||||
|
git checkout "$prev_commit";
|
||||||
|
|
||||||
|
touch "${FAKE_TEMP_LOCAL_REPOSITORY}"/remote-files{4,5,6}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_failure;
|
||||||
|
assert_line "::error::Repository is in detached HEAD state. Please make sure you check out a branch. Adjust the `ref` input accordingly."
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user