From 205854df1f005bf8c8732f6b32492ede3a130c28 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Tue, 10 Jan 2012 14:47:23 +0100 Subject: GitRepository: add push() and push_tag() --- gbp/git/repository.py | 38 ++++++++++++++++++++++++++++++++++++++ tests/test_GitRepository.py | 7 +++++++ 2 files changed, 45 insertions(+) diff --git a/gbp/git/repository.py b/gbp/git/repository.py index df49b1db..e8692c0d 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -673,6 +673,44 @@ class GitRepository(object): args += [ repo ] if repo else [] self._git_command("pull", args) + def push(self, repo=None, src=None, dst=None, ff_only=True): + """ + Push changes to the remote repo + + @param repo: repository to push to + @type repo: C{str} + @param src: the source ref to push + @type src: C{str} + @param dst: the name of the destination ref to push to + @type dst: C{str} + @param ff_only: only push if it's a fast forward update + @type ff_only: C{bool} + """ + args = GitArgs() + args.add_cond(repo, repo) + + # Allow for src == '' to delete dst on the remote + if src != None: + refspec = src + if dst: + refspec += ':%s' % dst + if not ff_only: + refspec = '+%s' % refspec + args.add(refspec) + self._git_command("push", args.args) + + def push_tag(self, repo, tag): + """ + Push a tag to the remote repo + + @param repo: repository to push to + @type repo: C{str} + @param tag: the name of the tag + @type tag: C{str} + """ + args = GitArgs(repo, 'tag', tag) + self._git_command("push", args.args) + #{ Files def add_files(self, paths, force=False, index_file=None, work_tree=None): diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py index a2be74ee..4f581e5e 100644 --- a/tests/test_GitRepository.py +++ b/tests/test_GitRepository.py @@ -386,11 +386,18 @@ def test_fetch(): Methods tested: - L{gbp.git.GitRepository.fetch} + - L{gbp.git.GitRepository.push} + - L{gbp.git.GitRepository.push_tag} >>> import gbp.git, os >>> d = os.path.join(clone_dir, 'gbp_%s_test_repo' % __name__) >>> clone = gbp.git.GitRepository(d) >>> clone.fetch() + >>> clone.push() + >>> clone.push('origin') + >>> clone.push('origin', 'master') + >>> clone.create_tag('tag3') + >>> clone.push_tag('origin', 'tag3') """ def test_create_bare(): -- cgit v1.2.3