Ensure compliance with git.
This add a TestCase to run all tests against git, thus ensuring that current tests, and all future tests, are compliant with git.
Thank you. Unfortunately, some tests are failing. Also, there is a lot of superfluous output.
Run python -m unittest
python -m unittest
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.10.13/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.13/x64/lib
...................hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpkfjc9vx6/.git/
hello.txt
hello.c
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpbpaxbow0/.git/
somematch
othermatch
#imnocomment
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmp7f81_833/.git/
data/01_raw/
Fhint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmp_yw4p6fl/.git/
a/bc/d
a/bXc/d
a/bbc/d
a/bcc/d
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpxytwzfcx/.git/
foo/hello/Bar
foo/world/Bar
foo/Bar
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpttl7k2d5/.git/
Fhint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpp91w5u1b/.git/
.venv/folder
.venv/file.txt
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpx6nxr5jv/.git/
o.py
dir/o.py
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpmxhez6hx/.git/
!ignore_me!
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpjhttg447/.git/
XYZa/b
a/bXYZ
a/b/foo
Fhint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmp_qckpzjm/.git/
trash.ignore
waste.ignore
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpvxc2s_bg/.git/
main.pyc
dir/main.pyc
__pycache__/
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmp_gf6c2t7/.git/
file.txt
directory
directory-trailing/
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpq5kyrcz5/.git/
abcXdef
abcYdef
abcZdef
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmp50tvk6l6/.git/
file1
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpqi_uesy1/.git/
link
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpzhto7mmd/.git/
file.txt
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
Initialized empty Git repository in /tmp/tmpi64a_p1q/.git/
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
ignoretrailingspace
partiallyignoredspace
partiallyignoredspace2
notignoredspace
notignoredmultiplespace
.hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/tmpt18q8etn/.git/
hello.txt
hello.foobar/
dir/hello.txt
hello.
.
======================================================================
FAIL: test_directory_only_negation (tests.TestAgainstGit)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/work/gitignore_parser/gitignore_parser/tests.py", line 169, in test_directory_only_negation
self.assertFalse(matches('/home/michael/data/01_raw/'))
AssertionError: True is not false
======================================================================
FAIL: test_ignore_directory (tests.TestAgainstGit)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/work/gitignore_parser/gitignore_parser/tests.py", line 96, in test_ignore_directory
self.assertTrue(matches('/home/michael/.venv'))
AssertionError: False is not true
======================================================================
FAIL: test_more_asterisks_handled_like_single_asterisk (tests.TestAgainstGit)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/work/gitignore_parser/gitignore_parser/tests.py", line 158, in test_more_asterisks_handled_like_single_asterisk
self.assertFalse(matches('/home/michael/a/b/foo'))
AssertionError: True is not false
----------------------------------------------------------------------
Ran 38 tests in 0.313s
FAILED (failures=3)
Error: Process completed with exit code 1.
Ohh « It is not possible to re-include a file if a parent directory of that file is excluded. ».
Also we may have hard times spotting directories, as git does use its knowledge about the index to tell appart files and directories:
if (pattern->flags & PATTERN_FLAG_MUSTBEDIR) {
*dtype = resolve_dtype(*dtype, istate, pathname, pathlen);
if (*dtype != DT_DIR)
continue;
}
I know the tests are failing, but it has to be fixed, they are failing because gitignore_parser behave differently than gitignore.
I played a bit with the code and went down to a single error instead of 4, but the error is with the exclusion rules, and I can't wrap my head around it yet... I pushed my failures here: https://github.com/JulienPalard/gitignore_parser/tree/mdk-playing
To be honest I don't really know if my modifications enhance anything, it enhance the current tests, but adding more tests could reveal more subtleties, I don't know.
@mherrmann if you are interested in full (or at least more) git compliance, I've been working on a collection of corner cases tests for a similar project.
Here is a gist with slight adjustments to run standalone. Install (or make somehow differently available) one or more of the supported modules:
- gitignore_parser
- igittigitt
- pygit2
- py_walk
IMPORTANT: apply git config core.ignorecase false when cloned on Win32, case insensitive support is not (yet) a goal. :smile:
Thank you @astos-marcb. I don't have time to proactively investigate edge cases that gitignore_parser might handle incorrectly. I will be happy to accept PRs that add test cases for and / or fix them.