From 4e7c0d67cd27ac96adcf4d3e06db1070c1a3c4f0 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 6 Sep 2022 21:04:34 +0200 Subject: [PATCH] Assert throws error when force adding ignored files See https://github.com/stefanzweifel/git-auto-commit-action/issues/204#issuecomment-1236880360 --- tests/git-auto-commit.bats | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 449d9d8..775d24a 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -839,3 +839,36 @@ git_auto_commit() { assert_line --partial "new-file-1.neon" assert_line --partial "foo/new-file-2.neon" } + +@test "throws error if tries to force add ignored files which do not have any changes" { + # Create 2 files which will later will be added to .gitignore + touch "${FAKE_LOCAL_REPOSITORY}"/ignored-file.txt + touch "${FAKE_LOCAL_REPOSITORY}"/another-ignored-file.txt + + # Commit the 2 new files + run git_auto_commit + + # Add our txt files to gitignore + echo "ignored-file.txt" >> "${FAKE_LOCAL_REPOSITORY}"/.gitignore + echo "another-ignored-file.txt" >> "${FAKE_LOCAL_REPOSITORY}"/.gitignore + + # Commit & push .gitignore changes + run git_auto_commit + + # Sanity check that txt files are ignored + run cat "${FAKE_LOCAL_REPOSITORY}"/.gitignore + assert_output --partial "ignored-file.txt" + assert_output --partial "another-ignored-file.txt"; + + # Configure git-auto-commit + INPUT_SKIP_DIRTY_CHECK=true + INPUT_ADD_OPTIONS="-f" + INPUT_FILE_PATTERN="ignored-file.txt another-ignored-file.txt" + + # Run git-auto-commit with special configuration + run git_auto_commit + + assert_output --partial "nothing to commit, working tree clean"; + + assert_failure; +}