Skip to content

Commit

Permalink
Use Path.parents to determine if a dependency is created in a Commo…
Browse files Browse the repository at this point in the history
…dore working tree

We don't need to use the ugly exception-based check to figure out if the
dependency directory is a subdirectory of the Commodore `dependencies/`
directory.

Instead we can just check if the `dependencies` directory is one of the
dependency directory's parents.

Co-authored-by: Fabian Fischer <[email protected]>
  • Loading branch information
simu and glrf committed Jul 19, 2022
1 parent f5ba1a1 commit 8d8b8c0
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions commodore/dependency_templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,9 @@ def create(self) -> None:
+ f"{self.target_dir} already exists."
)

want_worktree = True
try:
# Use target_dir.relative_to(work_dir / "dependencies") to determine whether
# the new dependency is created in a commodore working tree (i.e. as a
# subdirectory of `work_dir / "dependencies"`).
_ = self.target_dir.absolute().relative_to(
self.config.inventory.dependencies_dir.absolute()
)
except ValueError:
want_worktree = False

want_worktree = (
self.config.inventory.dependencies_dir in self.target_dir.parents
)
if want_worktree:
md = MultiDependency(self.repo_url, self.config.inventory.dependencies_dir)
md.initialize_worktree(self.target_dir)
Expand Down

0 comments on commit 8d8b8c0

Please sign in to comment.