MCPcopy Create free account
hub / github.com/METR/vivaria / create_working_tree_permalink

Function create_working_tree_permalink

cli/viv_cli/github.py:98–144  ·  view source on GitHub ↗

Make a temp commit if necessary & return GitHub permalink. Args: org: The GitHub organization name repo: The GitHub repository name ignore_workdir: If true, start task from current commit and ignore any uncommitted changes. Returns: GitHub orga

(
    org: str, repo: str, ignore_workdir: bool = False
)

Source from the content-addressed store, hash-verified

96
97
98def create_working_tree_permalink(
99 org: str, repo: str, ignore_workdir: bool = False
100) -> tuple[str, str, str]:
101 """Make a temp commit if necessary & return GitHub permalink.
102
103 Args:
104 org: The GitHub organization name
105 repo: The GitHub repository name
106 ignore_workdir: If true, start task from current commit and ignore any
107 uncommitted changes.
108
109 Returns:
110 GitHub organization, repository, commit id, permalink to commit.
111 """
112
113 def exec_with_err_log(cmd: str | list[str]) -> ExecResult:
114 """Execute a command and log errors."""
115 return execute(cmd, error_out=True, log=True)
116
117 if ignore_workdir:
118 commit = get_latest_commit_id()
119 return get_branch() or commit, commit, create_commit_permalink(org, repo, commit)
120
121 branch = get_branch() or err_exit(
122 "Error: can't start run from detached head (must be on branch)"
123 )
124
125 tmp_branch_name = "temp-branch-" + str(randint(0, 1_000_000)) # noqa: S311
126
127 if not check_repo_is_dirty():
128 commit = get_latest_commit_id()
129 exec_with_err_log(f"git push -u origin {branch}")
130 return branch, commit, create_commit_permalink(org, repo, commit)
131
132 exec_with_err_log("git stash --include-untracked -m viv-autostash")
133 exec_with_err_log(f"git checkout -b {tmp_branch_name}")
134 exec_with_err_log("git stash apply")
135 exec_with_err_log("git add --all")
136 exec_with_err_log(["git", "commit", "-m", "viv auto commit"])
137 commit = get_latest_commit_id()
138 exec_with_err_log(f"git checkout {branch}")
139 exec_with_err_log("git stash pop")
140 exec_with_err_log(f"git push -u origin {tmp_branch_name}")
141 exec_with_err_log(f"git branch -D {tmp_branch_name}")
142 threading.Thread(target=lambda: execute(f"git push origin --delete {tmp_branch_name}")).start()
143
144 return branch, commit, create_commit_permalink(org, repo, commit)
145
146
147def ask_pull_repo_or_exit() -> None:

Callers

nothing calls this directly

Calls 8

err_exitFunction · 0.90
executeFunction · 0.90
get_latest_commit_idFunction · 0.85
get_branchFunction · 0.85
create_commit_permalinkFunction · 0.85
check_repo_is_dirtyFunction · 0.85
exec_with_err_logFunction · 0.85
startMethod · 0.80

Tested by

no test coverage detected