Skip to content

Commit 90ce2fa

Browse files
committed
Merge branch 'main' of github.com:ansible/ansible-dev-environment into fix/adt_install
2 parents 440c198 + ff28c25 commit 90ce2fa

File tree

2 files changed

+76
-16
lines changed

2 files changed

+76
-16
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ repos:
7171
name: Spell check with cspell
7272

7373
- repo: https://github.com/jsh9/pydoclint
74-
rev: 0.3.10
74+
rev: 0.4.0
7575
hooks:
7676
- id: pydoclint
7777
args:

src/ansible_dev_environment/subcommands/installer.py

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,30 +215,24 @@ def _install_galaxy_requirements(self: Installer) -> None:
215215
msg = f"Source installed collections include: {oxford_join(installed)}"
216216
self._output.note(msg)
217217

218-
def _copy_git_repo_files(
218+
def _copy_files_using_git_ls_files(
219219
self: Installer,
220220
local_repo_path: Path | None,
221-
destination_path: Path,
222-
) -> None:
223-
"""Copy collection files tracked in git to the build directory.
221+
) -> str | None:
222+
"""Copy collection files tracked using git ls-files to the build directory.
224223
225224
Args:
226225
local_repo_path: The collection local path.
227-
destination_path: The build destination path.
228-
226+
Returns:
227+
string containing a list of files or nothing
229228
"""
230-
if local_repo_path is None:
231-
msg = "Invalid repo path, no files to copy from Git"
232-
self._output.info(msg)
233-
return
234-
235229
msg = "List collection files using git ls-files."
236230
self._output.debug(msg)
237231

238232
try:
239233
# Get the list of tracked files in the repository
240234
tracked_files_output = subprocess_run(
241-
command="git ls-files 2> /dev/null || ls",
235+
command="git ls-files 2> /dev/null",
242236
cwd=local_repo_path,
243237
verbose=self._config.args.verbose,
244238
msg=msg,
@@ -247,10 +241,76 @@ def _copy_git_repo_files(
247241
except subprocess.CalledProcessError as exc:
248242
err = f"Failed to list collection using git ls-files: {exc} {exc.stderr}"
249243
self._output.critical(err)
244+
245+
return tracked_files_output.stdout
246+
247+
def _copy_files_using_ls(
248+
self: Installer,
249+
local_repo_path: Path | None,
250+
) -> str | None:
251+
"""Copy collection files tracked using ls to the build directory.
252+
253+
Args:
254+
local_repo_path: The collection local path.
255+
Returns:
256+
string containing a list of files or nothing
257+
"""
258+
msg = "List collection files using ls."
259+
self._output.debug(msg)
260+
261+
try:
262+
# Get the list of tracked files in the repository
263+
tracked_files_output = subprocess_run(
264+
command="ls 2> /dev/null",
265+
cwd=local_repo_path,
266+
verbose=self._config.args.verbose,
267+
msg=msg,
268+
output=self._output,
269+
)
270+
except subprocess.CalledProcessError as exc:
271+
err = f"Failed to list collection using ls: {exc} {exc.stderr}"
272+
self._output.critical(err)
273+
274+
return tracked_files_output.stdout
275+
276+
def _copy_repo_files(
277+
self: Installer,
278+
local_repo_path: Path | None,
279+
destination_path: Path,
280+
) -> None:
281+
"""Copy collection files tracked in git to the build directory.
282+
283+
Args:
284+
local_repo_path: The collection local path.
285+
destination_path: The build destination path.
286+
287+
"""
288+
if local_repo_path is None:
289+
msg = "Invalid repo path, no files to copy"
290+
self._output.info(msg)
291+
return
292+
293+
# Get tracked files from git ls-files command
294+
tracked_files_output = self._copy_files_using_git_ls_files(
295+
local_repo_path=local_repo_path,
296+
)
297+
298+
if tracked_files_output is None:
299+
msg = "No tracked files found using git ls-files"
300+
self._output.info(msg)
301+
302+
# If no tracked files found, get files using ls command
303+
tracked_files_output = self._copy_files_using_ls(
304+
local_repo_path=local_repo_path,
305+
)
306+
307+
if tracked_files_output is None:
308+
msg = "No files found"
309+
self._output.info(msg)
250310
return
251311

252-
# Get the list of tracked files
253-
tracked_files = tracked_files_output.stdout.split("\n")
312+
# Parse tracked files output
313+
tracked_files = tracked_files_output.split("\n")
254314

255315
# Create the destination folder if it doesn't exist
256316
Path(destination_path).mkdir(parents=True, exist_ok=True)
@@ -289,7 +349,7 @@ def _install_local_collection(
289349
msg = f"Installing local collection from: {collection.build_dir}"
290350
self._output.info(msg)
291351

292-
self._copy_git_repo_files(
352+
self._copy_repo_files(
293353
local_repo_path=collection.path,
294354
destination_path=collection.build_dir,
295355
)

0 commit comments

Comments
 (0)