Skip to content

Commit

Permalink
Handle newer Git versions when checking for conflicting worktree
Browse files Browse the repository at this point in the history
repoutil.Worktree is designed to clean up any existing worktree before
adding a new one. Currently, it relies on the error message produced
by Git to determine if there is one. The format of the error message
has recently changed [1], causing the test suite to fail. This fix
should work with both older and newer versions of Git.

1. git/git@2a499264d39
  • Loading branch information
Sangho Na committed Feb 19, 2024
1 parent 78c5a6c commit a3a8687
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion utility/repoutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ def _create_worktree(
try:
repo_git.worktree('add', self.worktree_dir, branch)
except GitCommandError as e:
if 'is already checked out at' not in e.stderr:
conflicting_worktree_exists: bool = (
'is already checked out at' in e.stderr or 'is already used by worktree at' in e.stderr
)
if not conflicting_worktree_exists:
raise e
worktrees_output: list[str] = repo.git.worktree('list', '--porcelain').splitlines()
conflicting_worktree = None
Expand Down

0 comments on commit a3a8687

Please sign in to comment.