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

Mathieu Bridon bochecha at fedoraproject.org
Mon Mar 24 08:47:03 UTC 2014


Ping?

On Mon, 2014-03-10 at 20:01 +0800, Mathieu Bridon wrote:
> 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.remote attribute.
> 
> That attribute is set to "origin" though, to not break existing clones.
> 
> 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.
> ---
> This is important for us at $dayjob.
> 
> We have this rpkg-based tool called nbpkg, which we use to interact with
> our packaging infrastructure, similar to fedpkg:
> 
>     https://github.com/network-box/nbpkg
> 
> But as I'm also a Fedora packager, I like to be able to interact with
> both our internal infrastructure, and the Fedora one, in the same Git
> clone, as it allows me to easily flow changes in both directions.
> 
> This workflow requires having different names for each remote though,
> they can't just be all called 'origin'. This patch makes this possible.
> 
> I can imagine a similar use case for RHEL packagers, which could
> probably want to interact with both the Fedora and RHEL packaging
> infrastructures in the same Git clone, flowing changes both ways.
> 
> I know RPMFusion would be interested as well (I added Nicolas as CC).
> 
>  src/pyrpkg/__init__.py | 21 ++++++++++++++-------
>  src/rpkg.bash          |  3 +--
>  2 files changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
> index c5b4ae4..89a84a2 100644
> --- a/src/pyrpkg/__init__.py
> +++ b/src/pyrpkg/__init__.py
> @@ -135,6 +135,9 @@ class Commands(object):
>          self._ver = None
>          self.log = log
>  
> +        # The local name of the remote (might be overridden by subclasses)
> +        self.remote = "origin"
> +
>      # Define properties here
>      # Properties allow us to "lazy load" various attributes, which also means
>      # that we can do clone actions without knowing things like the spec
> @@ -961,6 +964,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.remote])
> +
>          self._run_command(cmd, cwd=path)
>  
>          return
> @@ -1009,14 +1017,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.remote,
> +                        repo_path, branch)
>  
> -                # Set the origin correctly
> +                # Set the remote 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.remote, giturl)
>              except (git.GitCommandError, OSError), e:
>                  raise rpkgError('Could not locally clone %s from %s: %s' %
>                          (branch, repo_path, e))
> @@ -1452,8 +1460,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'
>  }
>  


-- 
Mathieu




More information about the rel-eng mailing list