| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -873,8 +873,15 @@ def ignored(self, *paths: PathLike) -> List[str]: | |||
| 873 | 873 | """ | |
| 874 | 874 | try: | |
| 875 | 875 | proc: str = self.git.check_ignore(*paths) | |
| 876 | - except GitCommandError: | ||
| 877 | - return [] | ||
| 876 | + except GitCommandError as err: | ||
| 877 | + # If return code is 1, this means none of the items in *paths | ||
| 878 | + # are ignored by Git, so return an empty list. Raise the | ||
| 879 | + # exception on all other return codes. | ||
| 880 | + if err.status == 1: | ||
| 881 | + return [] | ||
| 882 | + else: | ||
| 883 | + raise | ||
| 884 | + | ||
| 878 | 885 | return proc.replace("\\\\", "\\").replace('"', "").split("\n") | |
| 879 | 886 | ||
| 880 | 887 | @property | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1384,3 +1384,30 @@ def test_clone_from_command_injection(self, rw_repo): | |||
| 1384 | 1384 | rw_repo.clone_from(payload, temp_repo.common_dir) | |
| 1385 | 1385 | ||
| 1386 | 1386 | assert not unexpected_file.exists() | |
| 1387 | + | ||
| 1388 | + def test_ignored_items_reported(self): | ||
| 1389 | + with tempfile.TemporaryDirectory() as tdir: | ||
| 1390 | + tmp_dir = pathlib.Path(tdir) | ||
| 1391 | + temp_repo = Repo.init(tmp_dir / "repo") | ||
| 1392 | + | ||
| 1393 | + gi = tmp_dir / "repo" / ".gitignore" | ||
| 1394 | + | ||
| 1395 | + with open(gi, 'w') as file: | ||
| 1396 | + file.write('ignored_file.txt\n') | ||
| 1397 | + file.write('ignored_dir/\n') | ||
| 1398 | + | ||
| 1399 | + assert temp_repo.ignored(['included_file.txt', 'included_dir/file.txt']) == [] | ||
| 1400 | + assert temp_repo.ignored(['ignored_file.txt']) == ['ignored_file.txt'] | ||
| 1401 | + assert temp_repo.ignored(['included_file.txt', 'ignored_file.txt']) == ['ignored_file.txt'] | ||
| 1402 | + 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'] | ||
| 1403 | + | ||
| 1404 | + def test_ignored_raises_error_w_symlink(self): | ||
| 1405 | + with tempfile.TemporaryDirectory() as tdir: | ||
| 1406 | + tmp_dir = pathlib.Path(tdir) | ||
| 1407 | + temp_repo = Repo.init(tmp_dir / "repo") | ||
| 1408 | + | ||
| 1409 | + os.mkdir(tmp_dir / "target") | ||
| 1410 | + os.symlink(tmp_dir / "target", tmp_dir / "symlink") | ||
| 1411 | + | ||
| 1412 | + with pytest.raises(GitCommandError): | ||
| 1413 | + temp_repo.ignored(tmp_dir / "symlink/file.txt") | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments