Clone and check out branch in two steps

pull/809/head
David Brochart 2019-11-05 18:53:45 +01:00
rodzic 56e6c116f3
commit 97c8bfb68f
1 zmienionych plików z 14 dodań i 2 usunięć

Wyświetl plik

@ -23,15 +23,18 @@ class Git(ContentProvider):
try:
cmd = ["git", "clone"]
if ref is None:
# check out of HEAD is performed after the clone is complete
cmd.extend(["--depth", "1"])
else:
cmd.extend(["--branch", ref])
# don't check out HEAD, the given ref will be checked out later
# this prevents HEAD's submodules to be cloned if ref doesn't have them
cmd.extend(["--no-checkout"])
cmd.extend([repo, output_dir])
for line in execute_cmd(cmd, capture=yield_output):
yield line
except subprocess.CalledProcessError as e:
msg = "Failed to clone repository from {repo}".format(repo=repo)
msg = "Failed to clone repository from {repo}.".format(repo=repo)
if ref is not None:
msg += " (ref {ref})".format(ref=ref)
msg += "."
@ -39,6 +42,15 @@ class Git(ContentProvider):
# check out the specific ref given by the user
if ref is not None:
# check out ref as it has not been done yet
try:
for line in execute_cmd(
["git", "checkout", ref], cwd=output_dir, capture=yield_output
):
yield line
except subprocess.CalledProcessError as e:
msg = "Failed to check out ref {ref}.".format(ref=ref)
raise ContentProviderException(msg) from e
hash = check_ref(ref, output_dir)
if hash is None:
self.log.error(