aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-05-26 16:30:29 +0200
committerGuido Günther <agx@sigxcpu.org>2017-05-26 16:30:29 +0200
commit81c3d533a07c6602f07907b82b12d885239ca013 (patch)
tree08cd1d4b00fb5e9f27d41265470efd559560cd4b
parent0372be09cf6f68c4ade2e74b66cac8251d005a66 (diff)
GitRepository: add rename_file
-rw-r--r--gbp/git/repository.py11
-rw-r--r--tests/doctests/test_GitRepository.py16
2 files changed, 27 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 991b0fa..a55c477 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -1431,6 +1431,17 @@ class GitRepository(object):
return self.strip_sha1(sha1)
else:
raise GbpError("Failed to hash %s: %s" % (filename, stderr))
+
+ def rename_file(self, old, new):
+ """
+ Rename file, directory, or symlink
+ """
+ args = GitArgs(old, new)
+ _, stderr, ret = self._git_inout('mv',
+ args.args,
+ capture_stderr=True)
+ if ret:
+ raise GbpError("Failed to move '%s' to '%s': %s" % (old, new, stderr.rstrip()))
#}
#{ Comitting
diff --git a/tests/doctests/test_GitRepository.py b/tests/doctests/test_GitRepository.py
index a11211d..f6e739b 100644
--- a/tests/doctests/test_GitRepository.py
+++ b/tests/doctests/test_GitRepository.py
@@ -123,6 +123,22 @@ def test_add_files():
"""
+def test_move_file():
+ """
+ Methods tested:
+ - L{gbp.git.GitRepository.move_file}
+
+ >>> import gbp.git
+ >>> repo = gbp.git.GitRepository(dirs['repo'])
+ >>> repo.rename_file("testfile", "testfile2")
+ >>> repo.rename_file("testfile2", "testfile")
+ >>> repo.rename_file("doesnotexit", "testfile2")
+ Traceback (most recent call last):
+ ...
+ GbpError: Failed to move 'doesnotexit' to 'testfile2': fatal: bad source, source=doesnotexit, destination=testfile2
+ """
+
+
def test_branch_master():
"""
First branch is called I{master}