mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2024-11-06 02:08:05 +00:00
* fix crlf test * add diff check before commit * add dirty check flag (not sure if needed) * Update test name and add more assertions Update test name to make it clear that the Action no longer fails to detect CRLF changes. * Add Comment to explain why we use git-diff again * Add test to confirm content changes are commited * Closes #241 Co-authored-by: Stefan Zweifel <hello@stefanzweifel.io>
This commit is contained in:
parent
976f22029f
commit
3ea6ae190b
@ -25,11 +25,28 @@ _main() {
|
|||||||
|
|
||||||
_add_files
|
_add_files
|
||||||
|
|
||||||
_local_commit
|
# Check dirty state of repo again using git-diff.
|
||||||
|
# (git-diff detects beter if CRLF of files changes and does NOT
|
||||||
|
# proceed, if only CRLF changes are detected. See #241 and #265
|
||||||
|
# for more details.)
|
||||||
|
if [ -n "$(git diff --staged)" ] || "$INPUT_SKIP_DIRTY_CHECK"; then
|
||||||
|
_local_commit
|
||||||
|
|
||||||
_tag_commit
|
_tag_commit
|
||||||
|
|
||||||
_push_to_github
|
_push_to_github
|
||||||
|
else
|
||||||
|
|
||||||
|
# Check if $GITHUB_OUTPUT is available
|
||||||
|
# (Feature detection will be removed in late December 2022)
|
||||||
|
if [ -z ${GITHUB_OUTPUT+x} ]; then
|
||||||
|
echo "::set-output name=changes_detected::false";
|
||||||
|
else
|
||||||
|
echo "changes_detected=false" >> $GITHUB_OUTPUT;
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Working tree clean. Nothing to commit.";
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
|
||||||
# Check if $GITHUB_OUTPUT is available
|
# Check if $GITHUB_OUTPUT is available
|
||||||
|
@ -974,7 +974,7 @@ cat_github_output() {
|
|||||||
assert_line --partial "another-subdirectory/new-file-3.txt"
|
assert_line --partial "another-subdirectory/new-file-3.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "fails to detect crlf change in files and does not detect change or commit changes" {
|
@test "detects if crlf in files change and does not create commit" {
|
||||||
# Set autocrlf to true
|
# Set autocrlf to true
|
||||||
cd "${FAKE_LOCAL_REPOSITORY}"
|
cd "${FAKE_LOCAL_REPOSITORY}"
|
||||||
git config core.autocrlf true
|
git config core.autocrlf true
|
||||||
@ -982,26 +982,65 @@ cat_github_output() {
|
|||||||
assert_line "true"
|
assert_line "true"
|
||||||
|
|
||||||
# Add more .txt files
|
# Add more .txt files
|
||||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
||||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
|
echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
|
||||||
|
|
||||||
# Run git-auto-commit to add new files to repository
|
# Run git-auto-commit to add new files to repository
|
||||||
run git_auto_commit
|
run git_auto_commit
|
||||||
|
|
||||||
# Change control characters in files
|
# Change control characters in files
|
||||||
sed 's/^M$//' "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
||||||
sed 's/$/^M/' "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
|
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
|
||||||
|
|
||||||
# Run git-auto-commit to commit the 2 changes files
|
# Run git-auto-commit to commit the 2 changes files
|
||||||
run git_auto_commit
|
run git_auto_commit
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
# Changes are not detected
|
refute_line --partial "2 files changed, 2 insertions(+), 2 deletions(-)"
|
||||||
assert_line --partial "Working tree clean. Nothing to commit."
|
assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
|
||||||
|
|
||||||
refute_line --partial "new-file-2.txt"
|
assert_line --partial "Working tree clean. Nothing to commit."
|
||||||
refute_line --partial "new-file-3.txt"
|
assert_line --partial "new-file-2.txt"
|
||||||
|
assert_line --partial "new-file-3.txt"
|
||||||
|
|
||||||
|
# Changes are not detected
|
||||||
|
run cat_github_output
|
||||||
|
assert_line "changes_detected=false"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "detects if crlf in files change and creates commit if the actual content of the files change" {
|
||||||
|
# Set autocrlf to true
|
||||||
|
cd "${FAKE_LOCAL_REPOSITORY}"
|
||||||
|
git config core.autocrlf true
|
||||||
|
run git config --get-all core.autocrlf
|
||||||
|
assert_line "true"
|
||||||
|
|
||||||
|
# Add more .txt files
|
||||||
|
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
||||||
|
echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
|
||||||
|
|
||||||
|
# Run git-auto-commit to add new files to repository
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
# Change control characters in files
|
||||||
|
echo -ne "crlf test2\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
||||||
|
echo -ne "crlf test2\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
|
||||||
|
|
||||||
|
# Run git-auto-commit to commit the 2 changes files
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line --partial "2 files changed, 2 insertions(+), 2 deletions(-)"
|
||||||
|
assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
|
||||||
|
|
||||||
|
assert_line --partial "new-file-2.txt"
|
||||||
|
assert_line --partial "new-file-3.txt"
|
||||||
|
|
||||||
|
# Changes are detected
|
||||||
|
run cat_github_output
|
||||||
|
assert_line "changes_detected=true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user