From 120e88bb943a07b5640cad1f7b7b522a3d0f7bc9 Mon Sep 17 00:00:00 2001 From: Filippo Cremonese <filippocremonese@rev.ng> Date: Tue, 15 Sep 2020 11:07:22 +0200 Subject: [PATCH] Get remote list dynamically --- orchestra/actions/clone.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/orchestra/actions/clone.py b/orchestra/actions/clone.py index 7acaf7d..821dc93 100644 --- a/orchestra/actions/clone.py +++ b/orchestra/actions/clone.py @@ -1,5 +1,6 @@ import os.path import re +from functools import cached_property from .action import Action from .util import run_script @@ -30,13 +31,17 @@ class CloneAction(Action): def _is_satisfied(self): return os.path.exists(self.environment["SOURCE_DIR"]) + @cached_property + def remotes(self): + result = run_script('git -C "$ORCHESTRA_DOTDIR" remote show', environment=self.environment, quiet=True) + return result.stdout.decode("utf-8").split("\n").strip().split("\n") + def remote_base_urls(self): # TODO: the remote is not necessarily called origin, and there might be more than one # remote names should be configurable - remotes = ["origin", "private"] base_urls = [] - for remote in remotes: + for remote in self.remotes: result = run_script( f'git -C "$ORCHESTRA_DOTDIR" config --get remote.{remote}.url', environment=self.environment, @@ -64,7 +69,7 @@ class CloneAction(Action): quiet=True, environment=self.environment, check_returncode=False - ).stdout.decode("utf-8") + ).stdout.decode("utf-8") parse_regex = re.compile(r"(?P<commit>[a-f0-9]*)\W*refs/heads/(?P<branch>.*)") matches = parse_regex.findall(result) for commit, branch in matches: -- GitLab