Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure compliance with git. #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JulienPalard
Copy link
Contributor

This add a TestCase to run all tests against git, thus ensuring that current tests, and all future tests, are compliant with git.

@mherrmann
Copy link
Owner

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.

@JulienPalard
Copy link
Contributor Author

JulienPalard commented Jan 24, 2024

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

@JulienPalard
Copy link
Contributor Author

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.

@astos-marcb
Copy link

astos-marcb commented May 31, 2024

@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. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants