Fix Git branch support.

This commit is contained in:
Casper V. Kristensen 2019-10-09 22:48:38 +02:00
parent 17e625474a
commit 6e3203108a
Signed by: caspervk
GPG key ID: 289CA03790535054

View file

@ -1,6 +1,7 @@
import logging import logging
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from typing import List
from .base import Provider from .base import Provider
from ..addons import Addon from ..addons import Addon
@ -14,7 +15,7 @@ class Git(Provider):
logger.debug("Performing 'git ls-remote' on %s", url) logger.debug("Performing 'git ls-remote' on %s", url)
try: try:
subprocess.run( subprocess.run(
["git", "ls-remote", "-h", "--exit-code", url], ["git", "ls-remote", "-h", "--exit-code", *cls.split_branch_url(url)],
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
timeout=3, timeout=3,
@ -31,12 +32,16 @@ class Git(Provider):
cls._clone(addon) cls._clone(addon)
return True return True
@classmethod
def split_branch_url(cls, url: str) -> List[str]:
return url.replace("#", " -b ").split() # allows for '<repo>#<branch>' syntax
@classmethod @classmethod
def _clone(cls, addon: Addon) -> None: def _clone(cls, addon: Addon) -> None:
logger.debug("Git clone %s", addon.url) logger.debug("Git clone %s", addon.url)
subprocess.call( subprocess.call(
["git", "clone", ["git", "clone",
*addon.url.replace("#", " -b ").split(), # allows for '<repo>#<branch>' syntax *cls.split_branch_url(addon.url),
"--depth", "1", "--depth", "1",
"--single-branch", "--single-branch",
"--quiet"], "--quiet"],