summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2023-01-22 10:02:15 +0100
committerGitHub <noreply@github.com>2023-01-22 10:02:15 +0100
commitcc92d5126b2fc80f7cc6866fc8f99b3ffb0189ae (patch)
tree35f8366a66261ee5710b5c4f8491fbaa544413c7
parentf594266acf09896608234947611fb3af356130dd (diff)
parentdf4dabb17c4e83c580d515894dbf7d57912ee554 (diff)
downloadgitpython-cc92d5126b2fc80f7cc6866fc8f99b3ffb0189ae.tar.gz
Merge pull request #1545 from Lightborne/fix_ignored
Fix ignored
-rw-r--r--git/repo/base.py11
-rw-r--r--test/test_repo.py27
2 files changed, 36 insertions, 2 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index 30f71b0c..9cdf673e 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -873,8 +873,15 @@ class Repo(object):
"""
try:
proc: str = self.git.check_ignore(*paths)
- except GitCommandError:
- return []
+ except GitCommandError as err:
+ # If return code is 1, this means none of the items in *paths
+ # are ignored by Git, so return an empty list. Raise the
+ # exception on all other return codes.
+ if err.status == 1:
+ return []
+ else:
+ raise
+
return proc.replace("\\\\", "\\").replace('"', "").split("\n")
@property
diff --git a/test/test_repo.py b/test/test_repo.py
index d5474353..07c1e9ad 100644
--- a/test/test_repo.py
+++ b/test/test_repo.py
@@ -1384,3 +1384,30 @@ class TestRepo(TestBase):
rw_repo.clone_from(payload, temp_repo.common_dir)
assert not unexpected_file.exists()
+
+ def test_ignored_items_reported(self):
+ with tempfile.TemporaryDirectory() as tdir:
+ tmp_dir = pathlib.Path(tdir)
+ temp_repo = Repo.init(tmp_dir / "repo")
+
+ gi = tmp_dir / "repo" / ".gitignore"
+
+ with open(gi, 'w') as file:
+ file.write('ignored_file.txt\n')
+ file.write('ignored_dir/\n')
+
+ assert temp_repo.ignored(['included_file.txt', 'included_dir/file.txt']) == []
+ assert temp_repo.ignored(['ignored_file.txt']) == ['ignored_file.txt']
+ assert temp_repo.ignored(['included_file.txt', 'ignored_file.txt']) == ['ignored_file.txt']
+ assert temp_repo.ignored(['included_file.txt', 'ignored_file.txt', 'included_dir/file.txt', 'ignored_dir/file.txt']) == ['ignored_file.txt', 'ignored_dir/file.txt']
+
+ def test_ignored_raises_error_w_symlink(self):
+ with tempfile.TemporaryDirectory() as tdir:
+ tmp_dir = pathlib.Path(tdir)
+ temp_repo = Repo.init(tmp_dir / "repo")
+
+ os.mkdir(tmp_dir / "target")
+ os.symlink(tmp_dir / "target", tmp_dir / "symlink")
+
+ with pytest.raises(GitCommandError):
+ temp_repo.ignored(tmp_dir / "symlink/file.txt") \ No newline at end of file