Skip to content

Commit 24a7425

Browse files
committed
Update cloning process
1 parent 0907076 commit 24a7425

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

upstream_utils/update_mpack.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,37 @@
1111
git_am,
1212
)
1313

14+
def get_repo_path(url, tempdir=None):
15+
if tempdir is None:
16+
tempdir = tempfile.gettempdir()
17+
repo = os.path.basename(url)
18+
dest = os.path.join(tempdir, repo)
19+
dest = dest.removesuffix(".git")
20+
return dest
21+
22+
def open_repo(url, *, err_msg_if_absent):
23+
os.chdir(tempfile.gettempdir())
24+
25+
dest = get_repo_path(url, os.getcwd())
26+
27+
print(f"INFO: Opening repository at {dest}")
28+
29+
if not os.path.exists(dest):
30+
if err_msg_if_absent is None:
31+
subprocess.run(["git", "clone", "--filter=tree:0", url])
32+
else:
33+
print(err_msg_if_absent, file=sys.stderr)
34+
exit(1)
35+
os.chdir(dest)
36+
37+
def clone(url, tag):
38+
open_repo(url, err_msg_if_absent=None)
39+
40+
subprocess.run(["git", "switch", "--detach", tag])
1441

1542
def main():
16-
upstream_root = clone_repo("https://github.com/ludocode/mpack", "v1.1.1")
43+
clone("https://github.com/ludocode/mpack", "v1.1.1")
44+
upstream_root = os.getcwd()
1745
wpilib_root = get_repo_root()
1846
wpiutil = os.path.join(wpilib_root, "wpiutil")
1947

0 commit comments

Comments
 (0)