Auto sync workspace manifest on first use
This commit is contained in:
@@ -3325,6 +3325,38 @@ def workspace_info_status(config: WorkspaceConfig) -> str:
|
||||
return "missing"
|
||||
|
||||
|
||||
def sync_workspace_info(config: WorkspaceConfig, pull_existing: bool = True) -> str:
|
||||
info_root = workspace_info_root(config)
|
||||
info_root.parent.mkdir(parents=True, exist_ok=True)
|
||||
if (info_root / ".git").is_dir():
|
||||
if pull_existing:
|
||||
subprocess.run(["git", "-C", str(info_root), "pull", "--ff-only"], check=True)
|
||||
config.workspace_info = json.loads(config.workspace_info_path.read_text(encoding="utf-8"))
|
||||
return "pulled"
|
||||
if config.workspace_info_path.is_file():
|
||||
config.workspace_info = json.loads(config.workspace_info_path.read_text(encoding="utf-8"))
|
||||
return "existing"
|
||||
raise SystemExit(f"Workspace info repo exists but manifest is missing: {config.workspace_info_path}")
|
||||
if info_root.exists():
|
||||
raise SystemExit(f"Workspace info path exists but is not a git repo: {info_root}")
|
||||
|
||||
print(f"workspace-info missing; cloning {config.workspace_info_url}", file=sys.stderr)
|
||||
subprocess.run(["git", "clone", config.workspace_info_url, str(info_root)], check=True)
|
||||
if not config.workspace_info_path.is_file():
|
||||
raise SystemExit(f"Workspace info clone does not contain manifest: {config.workspace_info_path}")
|
||||
config.workspace_info = json.loads(config.workspace_info_path.read_text(encoding="utf-8"))
|
||||
return "cloned"
|
||||
|
||||
|
||||
def ensure_workspace_info(config: WorkspaceConfig) -> None:
|
||||
if config.workspace_info:
|
||||
return
|
||||
if config.workspace_info_path.is_file():
|
||||
config.workspace_info = json.loads(config.workspace_info_path.read_text(encoding="utf-8"))
|
||||
return
|
||||
sync_workspace_info(config, pull_existing=False)
|
||||
|
||||
|
||||
def run_workspace(config: WorkspaceConfig, args: argparse.Namespace) -> None:
|
||||
if args.workspace_command == "show":
|
||||
print(f"workspace_info_path\t{config.workspace_info_path}")
|
||||
@@ -3343,13 +3375,7 @@ def run_workspace(config: WorkspaceConfig, args: argparse.Namespace) -> None:
|
||||
print(f"status\t{workspace_info_status(config)}")
|
||||
print(f"command\t{'pull' if (info_root / '.git').is_dir() else 'clone'}")
|
||||
return
|
||||
info_root.parent.mkdir(parents=True, exist_ok=True)
|
||||
if (info_root / ".git").is_dir():
|
||||
subprocess.run(["git", "-C", str(info_root), "pull", "--ff-only"], check=True)
|
||||
elif info_root.exists():
|
||||
raise SystemExit(f"Workspace info path exists but is not a git repo: {info_root}")
|
||||
else:
|
||||
subprocess.run(["git", "clone", config.workspace_info_url, str(info_root)], check=True)
|
||||
sync_workspace_info(config, pull_existing=True)
|
||||
print(f"workspace_info_path\t{config.workspace_info_path}")
|
||||
print(f"status\tready")
|
||||
return
|
||||
@@ -3810,6 +3836,8 @@ def main() -> int:
|
||||
parser = build_parser()
|
||||
args = parser.parse_args()
|
||||
config = load_config(args.config)
|
||||
if args.command in {"list-series", "list-cards", "series", "tasks", "tmux-container", "submission"}:
|
||||
ensure_workspace_info(config)
|
||||
|
||||
if args.command == "show-config":
|
||||
print_config(config)
|
||||
|
||||
Reference in New Issue
Block a user