Skip to content

Commit 15db96d

Browse files
committed
Add default . path to add -i
1 parent 4da01cb commit 15db96d

4 files changed

Lines changed: 93 additions & 46 deletions

File tree

dfetch/commands/add.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,22 @@ def browse_tree(subproject: SubProject, version: str = "") -> Generator[LsFuncti
8888
8989
Adapts the VCS-level ``(name, is_dir)`` tuples into :class:`~dfetch.terminal.Entry`
9090
objects so the terminal tree browser has no knowledge of VCS internals.
91+
92+
Adds '.' as the first entry to allow selecting the repo root (which is
93+
treated as empty src).
9194
"""
9295
if isinstance(subproject, (GitSubProject, SvnSubProject)):
9396
remote = subproject._remote_repo # pylint: disable=protected-access
9497
with remote.browse_tree(version) as vcs_ls:
9598

9699
def ls(path: str = "") -> list[Entry]:
97-
return [
100+
entries = [
98101
Entry(display=name, has_children=is_dir)
99102
for name, is_dir in vcs_ls(path)
100103
]
104+
if not path:
105+
return [Entry(display=".", has_children=True, value=".")] + entries
106+
return entries
101107

102108
yield ls
103109
else:
@@ -281,7 +287,7 @@ def _build_entry( # pylint: disable=too-many-arguments
281287
dst=dst,
282288
)
283289
entry_dict[kind] = value # type: ignore[literal-required]
284-
if src:
290+
if src and src != ".":
285291
entry_dict["src"] = src
286292
if ignore:
287293
entry_dict["ignore"] = ignore

dfetch/terminal/tree_browser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ def run(self) -> list[str]: # pragma: no cover - interactive TTY only
265265
)
266266
for entry in root_entries
267267
]
268+
269+
if len(self._nodes) == 1 and self._nodes[0].is_dir:
270+
self._expand(0)
271+
268272
screen = Screen()
269273

270274
while True:

features/add-project-through-cli.feature

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ Feature: Add a project to the manifest via the CLI
7878
url: some-remote-server/existing.git
7979
"""
8080
When I interactively add "some-remote-server/MyLib.git" with inputs
81-
| prompt_contains | answer |
82-
| Project name | my-lib |
83-
| Destination path | libs/my |
84-
| Version | master |
85-
| Source path | |
86-
| Ignore paths | |
87-
| Add project to manifest? | y |
88-
| Run update | n |
81+
| Question | Answer |
82+
| Project name | my-lib |
83+
| Destination path | libs/my |
84+
| Version | master |
85+
| Source path | |
86+
| Ignore paths | |
87+
| Add project to manifest? | y |
88+
| Run update | n |
8989
Then the manifest 'dfetch.yaml' contains entry
9090
"""
9191
- name: my-lib
@@ -104,14 +104,14 @@ Feature: Add a project to the manifest via the CLI
104104
url: some-remote-server/existing.git
105105
"""
106106
When I interactively add "some-remote-server/MyLib.git" with inputs
107-
| prompt_contains | answer |
108-
| Project name | my-lib |
109-
| Destination path | my-lib |
110-
| Version | v1 |
111-
| Source path | |
112-
| Ignore paths | |
113-
| Add project to manifest? | y |
114-
| Run update | n |
107+
| Question | Answer |
108+
| Project name | my-lib |
109+
| Destination path | my-lib |
110+
| Version | v1 |
111+
| Source path | |
112+
| Ignore paths | |
113+
| Add project to manifest? | y |
114+
| Run update | n |
115115
Then the manifest 'dfetch.yaml' contains entry
116116
"""
117117
- name: my-lib
@@ -129,14 +129,14 @@ Feature: Add a project to the manifest via the CLI
129129
url: some-remote-server/existing.git
130130
"""
131131
When I interactively add "some-remote-server/MyLib.git" with inputs
132-
| prompt_contains | answer |
133-
| Project name | my-lib |
134-
| Destination path | my-lib |
135-
| Version | master |
136-
| Source path | docs/api |
137-
| Ignore paths | |
138-
| Add project to manifest? | y |
139-
| Run update | n |
132+
| Question | Answer |
133+
| Project name | my-lib |
134+
| Destination path | my-lib |
135+
| Version | master |
136+
| Source path | docs/api |
137+
| Ignore paths | |
138+
| Add project to manifest? | y |
139+
| Run update | n |
140140
Then the manifest 'dfetch.yaml' contains entry
141141
"""
142142
- name: my-lib
@@ -155,7 +155,7 @@ Feature: Add a project to the manifest via the CLI
155155
url: some-remote-server/existing.git
156156
"""
157157
When I interactively add "some-remote-server/MyLib.git" with inputs
158-
| prompt_contains | answer |
158+
| Question | Answer |
159159
| Project name | my-lib |
160160
| Destination path | my-lib |
161161
| Version | master |
@@ -183,14 +183,14 @@ Feature: Add a project to the manifest via the CLI
183183
url: some-remote-server/existing.git
184184
"""
185185
When I interactively add "some-remote-server/MyLib.git" with inputs
186-
| prompt_contains | answer |
187-
| Project name | MyLib |
188-
| Destination path | MyLib |
189-
| Version | master |
190-
| Source path | |
191-
| Ignore paths | |
192-
| Add project to manifest? | y |
193-
| Run update | y |
186+
| Question | Answer |
187+
| Project name | MyLib |
188+
| Destination path | MyLib |
189+
| Version | master |
190+
| Source path | |
191+
| Ignore paths | |
192+
| Add project to manifest? | y |
193+
| Run update | y |
194194
Then the manifest 'dfetch.yaml' contains entry
195195
"""
196196
- name: MyLib
@@ -209,13 +209,13 @@ Feature: Add a project to the manifest via the CLI
209209
url: some-remote-server/existing.git
210210
"""
211211
When I interactively add "some-remote-server/MyLib.git" with inputs
212-
| prompt_contains | answer |
213-
| Project name | MyLib |
214-
| Destination path | MyLib |
215-
| Version | master |
216-
| Source path | |
217-
| Ignore paths | |
218-
| Add project to manifest? | n |
212+
| Question | Answer |
213+
| Project name | MyLib |
214+
| Destination path | MyLib |
215+
| Version | master |
216+
| Source path | |
217+
| Ignore paths | |
218+
| Add project to manifest? | n |
219219
Then the manifest 'dfetch.yaml' is replaced with
220220
"""
221221
manifest:
@@ -224,3 +224,29 @@ Feature: Add a project to the manifest via the CLI
224224
- name: existing
225225
url: some-remote-server/existing.git
226226
"""
227+
228+
Scenario: Interactive add with empty src (repo root) does not add src field
229+
Given the manifest 'dfetch.yaml'
230+
"""
231+
manifest:
232+
version: '0.0'
233+
projects:
234+
- name: existing
235+
url: some-remote-server/existing.git
236+
"""
237+
When I interactively add "some-remote-server/MyLib.git" with inputs
238+
| Question | Answer |
239+
| Project name | MyLib |
240+
| Destination path | MyLib |
241+
| Version | master |
242+
| Source path | |
243+
| Ignore paths | |
244+
| Add project to manifest? | y |
245+
| Run update | n |
246+
Then the manifest 'dfetch.yaml' contains entry
247+
"""
248+
- name: MyLib
249+
url: some-remote-server/MyLib.git
250+
branch: master
251+
"""
252+
And the manifest 'dfetch.yaml' does not contain 'src:'

features/steps/add_steps.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def step_impl(context, remote_url):
4242
prompt_answers: deque[str] = deque()
4343

4444
for row in context.table:
45-
prompt = row["prompt_contains"]
46-
answer = row["answer"]
47-
if "Add project to manifest" in prompt:
45+
question = row["Question"]
46+
answer = row["Answer"]
47+
if "Add project to manifest" in question:
4848
add_confirm = answer.lower() not in ("n", "no", "false")
49-
elif "update" in prompt.lower() and "run" in prompt.lower():
49+
elif "update" in question.lower() and "run" in question.lower():
5050
update_confirm = answer.lower() not in ("n", "no", "false")
5151
else:
5252
prompt_answers.append(answer)
@@ -100,3 +100,14 @@ def step_impl(context, message):
100100
assert (
101101
message in context.cmd_output
102102
), f"Expected error message '{message}' not found in output:\n{context.cmd_output}"
103+
104+
105+
@then("the manifest '{name}' does not contain '{text}'")
106+
def step_impl(_, name, text):
107+
with open(name, "r", encoding="utf-8") as fh:
108+
actual = fh.read()
109+
110+
if text in actual:
111+
print("Actual manifest:")
112+
print(actual)
113+
assert False, f"Expected text '{text}' should not be in manifest"

0 commit comments

Comments
 (0)