Add GitRepository.add_remote_repo()
authorGuido Günther <agx@sigxcpu.org>
Mon, 24 Oct 2011 15:20:19 +0000 (17:20 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 26 Oct 2011 07:45:10 +0000 (09:45 +0200)
gbp-create-remote-repo
gbp/git.py

index fa105d1..84bac66 100755 (executable)
@@ -131,9 +131,7 @@ def read_yn():
 
 
 def setup_branch_tracking(repo, remote, branches):
-    gitRemoteAdd = GitCommand('remote', ['add'])
-    gitRemoteAdd([remote['name'], remote['url']])
-    repo.fetch(remote['name'])
+    repo.add_remote_repo(name=remote['name'], url=remote['url'], fetch=True)
     gitTrackRemote = GitCommand('branch', ['--set-upstream'])
     for branch in branches:
         gitTrackRemote(['%s' % branch, '%s/%s' % (remote['name'], branch)])
index a7b5fba..41b83c3 100644 (file)
@@ -710,6 +710,24 @@ class GitRepository(object):
         else:
             return False
 
+    def add_remote_repo(self, name, url, tags=True, fetch=False):
+        """
+        Add a tracked remote repository
+
+        @param name: the name to use for the remote
+        @type name: string
+        @param url: the url to add
+        @type url: string
+        @param tags: whether to fetch tags
+        @type tags: bool
+        @param fetch: whether to fetch immediately from the remote side
+        @type fetch: bool
+        """
+        args = [ "add" ]
+        args += [ '--tags' ] if tags else [ '--no-tags']
+        args += [ '--fetch' ] if fetch else []
+        args += [ name, url ]
+        self._git_command("remote", args)
 
     def add_files(self, paths, force=False, index_file=None, work_tree=None):
         """