From 571d6b78ed2213bc3630491d4cfffb7fe3f152bb Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 28 Jun 2022 20:08:10 +0200 Subject: [PATCH] Add test to verify issue #227 This test confirms the problem mentioned in #227. If `file_pattern` contains a pattern of, for example 2 file extensions, and only files for one extensions are dirty but not for the otherone, `git-add` will throw a fatal error. It does not throw an error if the files for the pattern already exist but are not dirty. --- tests/git-auto-commit.bats | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index ea53cad..47687ce 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -793,3 +793,33 @@ git_auto_commit() { assert_equal $current_sha $remote_sha; } + +@test "throws fatal error if file pattern includes files that do not exist" { + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo + + INPUT_FILE_PATTERN="*.foo *.bar" + + run git_auto_commit + + assert_failure + assert_line --partial "fatal: pathspec '*.bar' did not match any files" +} + +@test "does not throw fataal error if files for file pattern exist but only one is dirty" { + # Add some .foo and .bar files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.bar + + INPUT_FILE_PATTERN="*.foo *.bar" + + run git_auto_commit + + # Add more .foo files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{4,5,6}.foo + + INPUT_FILE_PATTERN="*.foo *.bar" + + run git_auto_commit + + assert_success +}