GitRepository.push: Add 'force' option
authorLingchaox Xin <lingchaox.xin@intel.com>
Fri, 5 Jul 2013 09:09:50 +0000 (17:09 +0800)
committerGuido Günther <agx@sigxcpu.org>
Tue, 10 Sep 2013 07:16:23 +0000 (09:16 +0200)
Signed-off-by: Lingchaox Xin <lingchaox.xin@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/git/repository.py
tests/test_GitRepository.py

index 7d52216..6389d28 100644 (file)
@@ -1077,7 +1077,7 @@ 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):
+    def push(self, repo=None, src=None, dst=None, ff_only=True, force=False):
         """
         Push changes to the remote repo
 
@@ -1089,9 +1089,13 @@ class GitRepository(object):
         @type dst: C{str}
         @param ff_only: only push if it's a fast forward update
         @type ff_only: C{bool}
+        @param force: force push, can cause the remote repository to lose
+        commits; use it with care
+        @type force: C{bool}
         """
         args = GitArgs()
         args.add_cond(repo, repo)
+        args.add_true(force, "-f")
 
         # Allow for src == '' to delete dst on the remote
         if src != None:
@@ -1101,6 +1105,7 @@ class GitRepository(object):
             if not ff_only:
                 refspec = '+%s' % refspec
             args.add(refspec)
+
         self._git_command("push", args.args)
 
     def push_tag(self, repo, tag):
index 3ea0356..791cf70 100644 (file)
@@ -615,6 +615,7 @@ def test_fetch():
     >>> clone.push()
     >>> clone.push('origin')
     >>> clone.push('origin', 'master')
+    >>> clone.push('origin', 'master', force=True)
     >>> clone.create_tag('tag3')
     >>> clone.push_tag('origin', 'tag3')
     >>> clone.add_remote_repo('foo', repo_dir)