[jj] Make JjWrapper support secondary JJ workspaces

This change makes JjWrapper a no-op for secondary JJ workspaces that do not have a .git directory or worktree. It now holds an instance of GitWrapper and forwards commands to it only if a .git directory or worktree exists.

In particular, this allows gclient sync to run in secondary workspaces without fetching the git repository for the root.

Change-Id: Id89a83d7ce193304847dd75bbffa133e6a6a6964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7780501
Commit-Queue: Sunny Sachanandani <sunnyps@chromium.org>
Auto-Submit: Sunny Sachanandani <sunnyps@chromium.org>
Reviewed-by: Matt Stark <msta@google.com>
Commit-Queue: Matt Stark <msta@google.com>
changes/01/7780501/4
Sunny Sachanandani 1 day ago committed by infra-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 0ac9c5de48
commit e16ce5a52d

@ -7,14 +7,61 @@ import subprocess
import gclient_scm
class JjWrapper(gclient_scm.GitWrapper):
class JjWrapper(gclient_scm.SCMWrapper):
"""JjWrapper handles repos that are intended to be used with jj.
The repo does not yet need to be using jj, and does not even need to exist.
"""
def __init__(self, url=None, *args, **kwargs):
super(JjWrapper, self).__init__(url, *args, **kwargs)
git_path = pathlib.Path(self.checkout_path, '.git')
if git_path.exists():
self._git_wrapper = gclient_scm.GitWrapper(url, *args, **kwargs)
else:
self._git_wrapper = None
def _check_git_wrapper(self, command):
if not self._git_wrapper:
self.Print(
f"Command '{command}' is not supported on JJ workspaces "
"without a .git directory or worktree file"
)
return False
return True
def update(self, options, args, file_list):
if self._check_git_wrapper('update'):
self._git_wrapper.update(options, args, file_list)
def revert(self, options, args, file_list):
if self._check_git_wrapper('revert'):
self._git_wrapper.revert(options, args, file_list)
def revinfo(self, options, args, file_list):
if self._check_git_wrapper('revinfo'):
self._git_wrapper.revinfo(options, args, file_list)
def status(self, options, args, file_list):
if self._check_git_wrapper('status'):
self._git_wrapper.status(options, args, file_list)
def diff(self, options, args, file_list):
if self._check_git_wrapper('diff'):
self._git_wrapper.diff(options, args, file_list)
def pack(self, options, args, file_list):
if self._check_git_wrapper('pack'):
self._git_wrapper.pack(options, args, file_list)
def runhooks(self, options, args, file_list):
if self._check_git_wrapper('runhooks'):
self._git_wrapper.runhooks(options, args, file_list)
def _GetSubmodulePaths(self):
with pathlib.Path(self.checkout_path, '.gitmodules').open('r') as f:
gitmodules_path = pathlib.Path(self.checkout_path, '.gitmodules')
with gitmodules_path.open('r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if not line.startswith('path = '):

Loading…
Cancel
Save