Skip to content

Commit 358aa60

Browse files
authored
Add --skip-gitignore flag (#307)
* Add --ignore-gitignore flag * Rename --ignore-gitignore to --skip-gitignore
1 parent 544fb1d commit 358aa60

File tree

8 files changed

+36
-6
lines changed

8 files changed

+36
-6
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ by using ``skip_documentation`` parameter ([#300](https://github.com/MarketSquar
2828
robotidy --configure NormalizeSeparators:skip_documentation=True src
2929
```
3030

31+
### Other
32+
- Added ``--skip-gitignore`` flag to ignore ``.gitignore`` files and parse files listed there ([#299](https://github.com/MarketSquare/robotframework-tidy/issues/299)).
3133

3234
## 2.3
3335

docs/source/configuration/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Robotidy reads and ignores paths from ``.gitignore`` and ``--exclude``. You can
2828

2929
robotidy --extend-exclude skip_me.robot|some_dir/* .
3030

31+
To parse files listed in ``.gitignore`` use ``--skip-gitignore`` flag::
32+
33+
robotidy --skip-gitignore .
34+
3135
.. rubric:: Target Version
3236

3337
Robotidy can automatically disable transformers that are not supported in target version of Robot Framework.

robotidy/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, src: str, output: Optional[str], **kwargs):
3737
src=(),
3838
exclude=exclude,
3939
extend_exclude=extend_exclude,
40+
skip_gitignore=False,
4041
overwrite=False,
4142
show_diff=False,
4243
formatting_config=formatting_config,

robotidy/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(
2626
src: Tuple[str, ...],
2727
exclude: Optional[Pattern],
2828
extend_exclude: Optional[Pattern],
29+
skip_gitignore: bool,
2930
overwrite: bool,
3031
show_diff: bool,
3132
formatting_config: GlobalFormattingConfig,
@@ -36,7 +37,7 @@ def __init__(
3637
target_version: int,
3738
color: bool,
3839
):
39-
self.sources = get_paths(src, exclude, extend_exclude)
40+
self.sources = get_paths(src, exclude, extend_exclude, skip_gitignore)
4041
self.overwrite = overwrite
4142
self.show_diff = show_diff
4243
self.check = check

robotidy/cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"--endline",
6161
],
6262
},
63-
{"name": "File exclusion", "options": ["--exclude", "--extend-exclude"]},
63+
{"name": "File exclusion", "options": ["--exclude", "--extend-exclude", "--skip-gitignore"]},
6464
{
6565
"name": "Other",
6666
"options": ["--target-version", "--verbose", "--color", "--output", "--version", "--help"],
@@ -243,6 +243,12 @@ def print_transformers_list(target_version: int):
243243
" excluded ones. (Useful if you simply want to add to the default)"
244244
),
245245
)
246+
@click.option(
247+
"--skip-gitignore",
248+
is_flag=True,
249+
show_default=True,
250+
help="Skip **.gitignore** files and do not ignore files listed inside.",
251+
)
246252
@click.option(
247253
"--config",
248254
type=click.Path(
@@ -390,6 +396,7 @@ def cli(
390396
src: Tuple[str, ...],
391397
exclude: Optional[Pattern],
392398
extend_exclude: Optional[Pattern],
399+
skip_gitignore: bool,
393400
overwrite: bool,
394401
diff: bool,
395402
color: bool,
@@ -457,6 +464,7 @@ def cli(
457464
src=src,
458465
exclude=exclude,
459466
extend_exclude=extend_exclude,
467+
skip_gitignore=skip_gitignore,
460468
overwrite=overwrite,
461469
show_diff=diff,
462470
formatting_config=formatting_config,

robotidy/files.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,14 @@ def should_parse_path(
104104
return True
105105

106106

107-
def get_paths(src: Tuple[str, ...], exclude: Optional[Pattern], extend_exclude: Optional[Pattern]):
107+
def get_paths(
108+
src: Tuple[str, ...], exclude: Optional[Pattern], extend_exclude: Optional[Pattern], skip_gitignore: bool
109+
):
108110
root = find_project_root(src)
109-
gitignore = get_gitignore(root)
111+
if skip_gitignore:
112+
gitignore = None
113+
else:
114+
gitignore = get_gitignore(root)
110115
sources = set()
111116
for s in src:
112117
if s == "-":

tests/utest/test_cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def test_line_sep(self, line_sep, test_data_dir):
337337
actual_str = f.read()
338338
assert actual_str == expected_str, "Line endings does not match"
339339

340+
@pytest.mark.parametrize("skip_gitignore", [True, False])
340341
@pytest.mark.parametrize(
341342
"exclude, extend_exclude, allowed",
342343
[
@@ -346,11 +347,18 @@ def test_line_sep(self, line_sep, test_data_dir):
346347
("test.resource", "nested/*", ["test.robot"]),
347348
],
348349
)
349-
def test_exclude_gitignore(self, exclude, extend_exclude, allowed, test_data_dir):
350+
def test_exclude_gitignore(self, exclude, extend_exclude, skip_gitignore, allowed, test_data_dir):
351+
if skip_gitignore:
352+
allowed = allowed + ["test2.robot"] # extend will not work due to mutability of list
353+
if not extend_exclude or "nested" not in extend_exclude:
354+
allowed = allowed + ["nested/test2.robot"]
350355
source = test_data_dir / "gitignore"
351356
allowed_paths = {Path(source, path) for path in allowed}
352357
paths = get_paths(
353-
(str(source),), exclude=validate_regex(exclude), extend_exclude=validate_regex(extend_exclude)
358+
(str(source),),
359+
exclude=validate_regex(exclude),
360+
extend_exclude=validate_regex(extend_exclude),
361+
skip_gitignore=skip_gitignore,
354362
)
355363
assert paths == allowed_paths
356364

tests/utest/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def app():
2323
src=(".",),
2424
exclude=None,
2525
extend_exclude=None,
26+
skip_gitignore=False,
2627
overwrite=False,
2728
show_diff=False,
2829
formatting_config=formatting_config,

0 commit comments

Comments
 (0)