Skip to content

Commit d7e28f2

Browse files
committed
feat: add --no-vcs command-line option to ignore VCS directories (e.g., .git) when detecting the project root
#closes 201
1 parent add4102 commit d7e28f2

File tree

12 files changed

+66
-16
lines changed

12 files changed

+66
-16
lines changed

packages/analyze/src/robotcode/analyze/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def analyze(app: Application, paths: Tuple[str]) -> Union[str, int, None]:
2727
"""TODO: Analyzes a Robot Framework project."""
2828

2929
config_files, root_folder, _ = get_config_files(
30-
paths, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
30+
paths,
31+
app.config.config_files,
32+
root_folder=app.config.root,
33+
no_vcs=app.config.no_vcs,
34+
verbose_callback=app.verbose,
3135
)
3236

3337
try:

packages/language_server/src/robotcode/language_server/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ def language_server(
8383
analysis_config: Optional[WorkspaceAnalysisConfig] = None
8484

8585
config_files, root_folder, _ = get_config_files(
86-
paths, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
86+
paths,
87+
app.config.config_files,
88+
root_folder=app.config.root,
89+
no_vcs=app.config.no_vcs,
90+
verbose_callback=app.verbose,
8791
)
8892
if root_folder:
8993
os.chdir(root_folder)

packages/plugin/src/robotcode/plugin/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class CommonConfig:
6565
config_files: Optional[Sequence[Path]] = None
6666
profiles: Optional[Sequence[str]] = None
6767
root: Optional[Path] = None
68+
no_vcs: bool = False
6869
dry: bool = False
6970
verbose: bool = False
7071
colored_output: ColoredOutput = ColoredOutput.AUTO

packages/robot/src/robotcode/robot/config/loader.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def load_robot_config_from_path(
193193
def find_project_root(
194194
*sources: Union[str, Path],
195195
root_folder: Optional[Path] = None,
196+
no_vcs: bool = False,
196197
) -> Tuple[Optional[Path], DiscoverdBy]:
197198

198199
if root_folder:
@@ -220,11 +221,12 @@ def find_project_root(
220221
if (directory / PYPROJECT_TOML).is_file():
221222
return directory, DiscoverdBy.PYPROJECT_TOML
222223

223-
if (directory / ".git").exists():
224-
return directory, DiscoverdBy.GIT
224+
if not no_vcs:
225+
if (directory / ".git").exists():
226+
return directory, DiscoverdBy.GIT
225227

226-
if (directory / ".hg").is_dir():
227-
return directory, DiscoverdBy.HG
228+
if (directory / ".hg").is_dir():
229+
return directory, DiscoverdBy.HG
228230

229231
return None, DiscoverdBy.NOT_FOUND
230232

packages/robot/src/robotcode/robot/config/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,19 @@ def get_config_files(
4444
paths: Optional[Sequence[Union[str, Path]]] = None,
4545
config_files: Optional[Sequence[Path]] = None,
4646
root_folder: Optional[Path] = None,
47+
no_vcs: bool = False,
4748
*,
4849
verbose_callback: Optional[Callable[[str], None]] = None,
4950
) -> Tuple[Sequence[Tuple[Path, ConfigType]], Optional[Path], DiscoverdBy]:
50-
root_folder, discovered_by = find_project_root(*(paths or []), root_folder=root_folder)
51+
root_folder, discovered_by = find_project_root(*(paths or []), root_folder=root_folder, no_vcs=no_vcs)
5152

5253
if root_folder is None:
5354
root_folder = Path.cwd()
5455
if verbose_callback:
5556
verbose_callback(f"Cannot detect root folder. Use current folder '{root_folder}' as root.")
5657

5758
if verbose_callback:
58-
verbose_callback(f"Found root at:\n {root_folder} ({discovered_by.value})")
59+
verbose_callback(f"Use root at:\n {root_folder} ({discovered_by.value})")
5960

6061
if config_files:
6162
if verbose_callback:

packages/runner/src/robotcode/runner/cli/libdoc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ def libdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
6767
pass
6868

6969
config_files, root_folder, _ = get_config_files(
70-
robot_arguments, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
70+
robot_arguments,
71+
app.config.config_files,
72+
root_folder=app.config.root,
73+
no_vcs=app.config.no_vcs,
74+
verbose_callback=app.verbose,
7175
)
7276
try:
7377
profile = (

packages/runner/src/robotcode/runner/cli/rebot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ def rebot(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
6868
pass
6969

7070
config_files, root_folder, _ = get_config_files(
71-
robot_arguments, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
71+
robot_arguments,
72+
app.config.config_files,
73+
root_folder=app.config.root,
74+
no_vcs=app.config.no_vcs,
75+
verbose_callback=app.verbose,
7276
)
7377

7478
try:

packages/runner/src/robotcode/runner/cli/robot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ def handle_robot_options(
255255
sys.path = old_sys_path
256256

257257
config_files, root_folder, _ = get_config_files(
258-
robot_arguments, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
258+
robot_arguments,
259+
app.config.config_files,
260+
root_folder=app.config.root,
261+
no_vcs=app.config.no_vcs,
262+
verbose_callback=app.verbose,
259263
)
260264
try:
261265
profile = (

packages/runner/src/robotcode/runner/cli/testdoc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ def testdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
6767
pass
6868

6969
config_files, root_folder, _ = get_config_files(
70-
robot_arguments, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
70+
robot_arguments,
71+
app.config.config_files,
72+
root_folder=app.config.root,
73+
no_vcs=app.config.no_vcs,
74+
verbose_callback=app.verbose,
7175
)
7276

7377
try:

src/robotcode/cli/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
show_envvar=True,
5959
help="Specifies the root path to be used for the project. It will be automatically detected if not provided.",
6060
)
61+
@click.option(
62+
"--no-vcs",
63+
is_flag=True,
64+
show_envvar=True,
65+
help="Ignore version control system directories (e.g., .git, .hg) when detecting the project root.",
66+
)
6167
@click.option(
6268
"-f",
6369
"--format",
@@ -186,6 +192,7 @@ def robotcode(
186192
config_files: Optional[List[Path]],
187193
profiles: Optional[List[str]],
188194
root: Optional[Path],
195+
no_vcs: bool,
189196
format: Optional[OutputFormat],
190197
dry: bool,
191198
verbose: bool,
@@ -218,6 +225,7 @@ def robotcode(
218225
app.config.dry = dry
219226
app.config.verbose = verbose
220227
app.config.root = root
228+
app.config.no_vcs = no_vcs
221229

222230
if color is None:
223231
app.config.colored_output = ColoredOutput.AUTO

src/robotcode/cli/commands/config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ def show(app: Application, single: bool, paths: List[Path]) -> None:
6565
"""
6666
try:
6767
config_files, _, _ = get_config_files(
68-
paths, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
68+
paths,
69+
app.config.config_files,
70+
root_folder=app.config.root,
71+
no_vcs=app.config.no_vcs,
72+
verbose_callback=app.verbose,
6973
)
7074

7175
if single:
@@ -126,7 +130,11 @@ def files(app: Application, paths: List[Path], user: bool = False) -> None:
126130

127131
try:
128132
config_files, _, discovered_by = get_config_files(
129-
paths, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
133+
paths,
134+
app.config.config_files,
135+
root_folder=app.config.root,
136+
no_vcs=app.config.no_vcs,
137+
verbose_callback=app.verbose,
130138
)
131139

132140
result: Dict[str, Any] = {"files": [{"path": str(file), "type": type} for file, type in config_files]}
@@ -172,7 +180,9 @@ def root(app: Application, paths: List[Path]) -> None:
172180
```
173181
"""
174182

175-
root_folder, discovered_by = find_project_root(*(paths or []), root_folder=app.config.root)
183+
root_folder, discovered_by = find_project_root(
184+
*(paths or []), root_folder=app.config.root, no_vcs=app.config.no_vcs
185+
)
176186

177187
if root_folder is None and (app.config.output_format is None or app.config.output_format == OutputFormat.TEXT):
178188
raise click.ClickException("Cannot detect root folder. 😥")

src/robotcode/cli/commands/profiles.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ def list(app: Application, paths: List[Path], show_hidden: bool = False, sort_by
7676

7777
try:
7878
config_files, _, discovered_by = get_config_files(
79-
paths, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
79+
paths,
80+
app.config.config_files,
81+
root_folder=app.config.root,
82+
no_vcs=app.config.no_vcs,
83+
verbose_callback=app.verbose,
8084
)
8185

8286
config = load_robot_config_from_path(*config_files, verbose_callback=app.verbose)

0 commit comments

Comments
 (0)