[PATCH 2/2] De-hardcode 'origin' as the remote name

Mathieu Bridon bochecha at fedoraproject.org
Tue Jul 1 13:19:19 UTC 2014


By default, Git remotes are named 'origin', but some pyrpkg-based tools
might be used to interact with several remotes for the same package
module.

This change allows sites to define how remotes should be called by
simply overriding the Commands.branch_remote attribute.

The rpkg bash completion resource had to be modified accordingly. Since
the fedpkg one already handles this properly, a simple copy-paste of
that specific line was enough.
---
 src/pyrpkg/__init__.py | 16 ++++++++++------
 src/rpkg.bash          |  3 +--
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index f3b7362..362bbca 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -1057,6 +1057,11 @@ class Commands(object):
         else:
             self.log.debug('Cloning %s' % giturl)
             cmd.extend([giturl])
+
+        if not bare_dir:
+            # --bare and --origin are incompatible
+            cmd.extend(['--origin', self.branch_remote])
+
         self._run_command(cmd, cwd=path)
 
         return
@@ -1105,14 +1110,14 @@ class Commands(object):
         for branch in branches:
             try:
                 # Make a local clone for our branch
-                top_git.clone("--branch", branch, repo_path, branch)
+                top_git.clone("--branch", branch, "--origin", self.branch_remote,
+                        repo_path, branch)
 
                 # Set the origin correctly
                 branch_path = os.path.join(top_path, branch)
                 branch_git = git.Git(branch_path)
-                branch_git.config("--replace-all", "remote.origin.url", giturl)
-                # Bad use of "origin" here, need to fix this when more than one
-                # remote is used.
+                branch_git.config("--replace-all",
+                        "remote.%s.url" % self.branch_remote, giturl)
             except (git.GitCommandError, OSError), e:
                 raise rpkgError('Could not locally clone %s from %s: %s' %
                         (branch, repo_path, e))
@@ -1548,8 +1553,7 @@ class Commands(object):
             self.log.debug('No local branch found, creating a new one')
             totrack = None
             for remote in remotes:
-                # bad use of "origin" here, will have to be fixed
-                if remote.replace('origin/', '') == branch:
+                if remote.endswith(branch):
                     totrack = remote
                     break
             else:
diff --git a/src/rpkg.bash b/src/rpkg.bash
index 047c98d..a2e45b6 100644
--- a/src/rpkg.bash
+++ b/src/rpkg.bash
@@ -283,8 +283,7 @@ _rpkg_branch()
     local git_options= format="--format %(refname:short)"
     [[ -n $1 ]] && git_options="--git-dir=$1/.git"
 
-    git $git_options for-each-ref $format 'refs/remotes/origin/*' \
-        | sed 's,origin/,,'
+    git $git_options for-each-ref $format 'refs/remotes' | sed 's,.*/,,'
     git $git_options for-each-ref $format 'refs/heads'
 }
 
-- 
1.9.3



More information about the rel-eng mailing list