From d7514053f8a10d4ff1100f5ff06a3cdd0242b6f3 Mon Sep 17 00:00:00 2001 From: Alexandre MARY Date: Tue, 27 Jan 2026 11:27:45 +0000 Subject: [PATCH 1/2] manage multi-remotes --- ecbundle/download.py | 26 ++++++++++++++++++++++---- ecbundle/git.py | 10 ++++++++++ ecbundle/project.py | 4 ++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ecbundle/download.py b/ecbundle/download.py index b800422..c1fa758 100644 --- a/ecbundle/download.py +++ b/ecbundle/download.py @@ -9,6 +9,7 @@ import re from os import getcwd, makedirs, path from subprocess import check_call +from hashlib import md5 from .bundle import Bundle from .data import Data @@ -139,8 +140,7 @@ def download(self): skipped_optional_packages = list() class GitPackage: - def __init__(self, project): - self.remote = project.remote() + def __init__(self, project, src_dir=None): self.url = None self.name = project.name() self.version = str(project.version()) @@ -165,7 +165,24 @@ def __init__(self, project): elif self.url.startswith("~"): self.url = path.expanduser(self.url) - self.remote_str = self.remote + self._set_remote(project, src_dir=src_dir) + + def _set_remote(self, project, src_dir=None): + from .git import Git + remote = project.remote(default=None) + if remote is None: + if src_dir is None or not path.exists(src_dir): + remote = 'origin' + else: + # look for an existing remote with requested url + for remote_name, remote_url in Git.remotes(src_dir).items(): + if remote_url == self.url: + remote = remote_name + break + if remote is None: + # not found: use a bijective alias to url + remote = md5(self.url.encode('utf-8')).hexdigest() + self.remote_str = remote self.remote = self.remote_str.replace("~", "") def download_one_project(pkg): @@ -350,7 +367,8 @@ def download_data(data_packages, download_dir): if project.dir(): symlink_projects.append(project) else: - git_projects.append(GitPackage(project)) + src_dir = path.join(download_dir, project.name()) + git_projects.append(GitPackage(project, src_dir=src_dir)) for package in bundle.data(): data.append(Data(**package.config)) diff --git a/ecbundle/git.py b/ecbundle/git.py index 8f2afeb..b3f516c 100644 --- a/ecbundle/git.py +++ b/ecbundle/git.py @@ -254,6 +254,16 @@ def branch(cls, src_dir, dryrun): except CalledProcessError: return None + @staticmethod + def remotes(src_dir): + command = ["git", "remote", "-v"] + try: + remotes = execute(command, cwd=src_dir, silent=True, capture_output=True).strip().split('\n') + remotes = [l.split() for l in remotes] + return {l[0]:l[1] for l in remotes if l[2] == '(fetch)'} + except CalledProcessError: + raise RuntimeError() + @classmethod def is_remote(cls, src_dir, remote, dryrun): command = ["git", "ls-remote", remote] diff --git a/ecbundle/project.py b/ecbundle/project.py index 20c630f..fd4f1c0 100644 --- a/ecbundle/project.py +++ b/ecbundle/project.py @@ -39,8 +39,8 @@ def version(self): def git(self): return self.get("git") - def remote(self): - return self.get("remote", "origin") + def remote(self, default='origin'): + return self.get("remote", default) def submodules(self): return self.get("submodules", False) From 6bdfc711b1bde354eab0450896d8e6302114aca5 Mon Sep 17 00:00:00 2001 From: Willem Deconinck Date: Wed, 28 Jan 2026 10:02:25 +0000 Subject: [PATCH 2/2] Fix QA test --- ecbundle/download.py | 7 ++++--- ecbundle/git.py | 10 +++++++--- ecbundle/project.py | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ecbundle/download.py b/ecbundle/download.py index c1fa758..cec42d2 100644 --- a/ecbundle/download.py +++ b/ecbundle/download.py @@ -7,9 +7,9 @@ # does it submit to any jurisdiction. import re +from hashlib import md5 from os import getcwd, makedirs, path from subprocess import check_call -from hashlib import md5 from .bundle import Bundle from .data import Data @@ -169,10 +169,11 @@ def __init__(self, project, src_dir=None): def _set_remote(self, project, src_dir=None): from .git import Git + remote = project.remote(default=None) if remote is None: if src_dir is None or not path.exists(src_dir): - remote = 'origin' + remote = "origin" else: # look for an existing remote with requested url for remote_name, remote_url in Git.remotes(src_dir).items(): @@ -181,7 +182,7 @@ def _set_remote(self, project, src_dir=None): break if remote is None: # not found: use a bijective alias to url - remote = md5(self.url.encode('utf-8')).hexdigest() + remote = md5(self.url.encode("utf-8")).hexdigest() self.remote_str = remote self.remote = self.remote_str.replace("~", "") diff --git a/ecbundle/git.py b/ecbundle/git.py index b3f516c..2ac3ac5 100644 --- a/ecbundle/git.py +++ b/ecbundle/git.py @@ -258,9 +258,13 @@ def branch(cls, src_dir, dryrun): def remotes(src_dir): command = ["git", "remote", "-v"] try: - remotes = execute(command, cwd=src_dir, silent=True, capture_output=True).strip().split('\n') - remotes = [l.split() for l in remotes] - return {l[0]:l[1] for l in remotes if l[2] == '(fetch)'} + remotes = ( + execute(command, cwd=src_dir, silent=True, capture_output=True) + .strip() + .split("\n") + ) + remotes = [line.split() for line in remotes] + return {line[0]: line[1] for line in remotes if line[2] == "(fetch)"} except CalledProcessError: raise RuntimeError() diff --git a/ecbundle/project.py b/ecbundle/project.py index fd4f1c0..dfe8fe5 100644 --- a/ecbundle/project.py +++ b/ecbundle/project.py @@ -39,7 +39,7 @@ def version(self): def git(self): return self.get("git") - def remote(self, default='origin'): + def remote(self, default="origin"): return self.get("remote", default) def submodules(self):