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