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; +}