Set answer upstream for task branches
This commit is contained in:
@@ -2718,6 +2718,19 @@ def submission_branch_name(user_name: str, task_name: str) -> str:
|
||||
return branch_value(f"{slug_value(user_name, 'student user')}{task_branch_part(task_name)}a")
|
||||
|
||||
|
||||
def set_branch_upstream(repo_path: Path, branch_name: str, remote_name: str, dry_run: bool = False) -> str:
|
||||
expected_merge = f"refs/heads/{branch_name}"
|
||||
current_remote = git_capture(repo_path, ["config", "--get", f"branch.{branch_name}.remote"])
|
||||
current_merge = git_capture(repo_path, ["config", "--get", f"branch.{branch_name}.merge"])
|
||||
if current_remote == remote_name and current_merge == expected_merge:
|
||||
return "unchanged"
|
||||
if dry_run:
|
||||
return "dry-run"
|
||||
subprocess.run(["git", "-C", str(repo_path), "config", f"branch.{branch_name}.remote", remote_name], check=True)
|
||||
subprocess.run(["git", "-C", str(repo_path), "config", f"branch.{branch_name}.merge", expected_merge], check=True)
|
||||
return "updated" if current_remote or current_merge else "set"
|
||||
|
||||
|
||||
def print_card_tasks(config: WorkspaceConfig, series_name: str, card_name: str) -> None:
|
||||
card_path = resolve_workspace_card_path(config, series_name, card_name)
|
||||
for task_name in task_names(card_path):
|
||||
@@ -2761,6 +2774,25 @@ def switch_card_task(
|
||||
check=False,
|
||||
).returncode == 0
|
||||
|
||||
token_status = "dry-run"
|
||||
answer_remote_status = "dry-run"
|
||||
if not dry_run:
|
||||
token_status, source_token = ensure_answer_token_from_source(
|
||||
config,
|
||||
config.git.source_remote,
|
||||
config.git.answer_remote,
|
||||
answer_url,
|
||||
)
|
||||
answer_remote_status = set_git_remote(
|
||||
card_path,
|
||||
config.git.answer_remote,
|
||||
credentialed_remote_url(
|
||||
answer_url,
|
||||
str(source_token.get("user", "")),
|
||||
str(source_token.get("value", "")),
|
||||
),
|
||||
)
|
||||
|
||||
if dry_run:
|
||||
status = "dry-run"
|
||||
elif current_branch == branch_name:
|
||||
@@ -2771,6 +2803,7 @@ def switch_card_task(
|
||||
else:
|
||||
subprocess.run(["git", "-C", str(card_path), "switch", "-c", branch_name], check=True)
|
||||
status = "created"
|
||||
upstream_status = set_branch_upstream(card_path, branch_name, config.git.answer_remote, dry_run=dry_run)
|
||||
|
||||
return {
|
||||
"series": series_name,
|
||||
@@ -2778,6 +2811,12 @@ def switch_card_task(
|
||||
"task": task_name,
|
||||
"student_user": student_user,
|
||||
"branch": branch_name,
|
||||
"answer_remote": config.git.answer_remote,
|
||||
"answer_url": answer_url,
|
||||
"token_status": token_status,
|
||||
"answer_remote_status": answer_remote_status,
|
||||
"upstream": f"{config.git.answer_remote}/{branch_name}",
|
||||
"upstream_status": upstream_status,
|
||||
"workspace": str(card_path),
|
||||
"status": status,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user