aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-05-31 14:40:12 +0200
committerGuido Günther <agx@sigxcpu.org>2012-05-31 17:00:04 +0200
commit25fc07047b9abf915d300d0072734296bbaa5d82 (patch)
tree1dc8d1a6e0a89fa20d519ff917052f0265a56198
parent829eea6abab9e28894f50f3766b7bd67110a5d53 (diff)
gbp.git.repository: Add GitRepository.write_file
Signed-off-by: Guido Günther <agx@sigxcpu.org>
-rw-r--r--gbp/git/repository.py25
-rw-r--r--tests/test_GitRepository.py14
2 files changed, 39 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 43a8c46..1c6fc34 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -917,6 +917,31 @@ class GitRepository(object):
else:
return []
+
+ def write_file(self, filename, filters=True):
+ """
+ Hash a single file and write it into the object database
+
+ @param filename: the filename to the content of the file to hash
+ @type filename: C{str}
+ @param filters: whether to run filters
+ @type filters: C{bool}
+ @return: the hash of the file
+ @rtype: C{str}
+ """
+ args = GitArgs('-w', '-t', 'blob')
+ args.add_false(filters, '--no-filters')
+ args.add(filename)
+
+ sha1, stderr, ret = self._git_inout('hash-object',
+ args.args,
+ capture_stderr=True)
+ if not ret:
+ return sha1.strip()
+ else:
+ raise GbpError("Failed to hash %s: %s" % (filename, stderr))
+#}
+
#{ Comitting
def _commit(self, msg, args=[], author_info=None):
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index 328a65f..5393071 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -617,6 +617,20 @@ def test_update_ref():
"""
+def test_write_file():
+ """
+ Test git-write-file
+
+ Methods tested:
+ - L{gbp.git.GitRepository.write_file}
+
+ >>> import gbp.git
+ >>> repo = gbp.git.GitRepository(repo_dir)
+ >>> repo.write_file('testfile')
+ '19af7398c894bc5e86e17259317e4db519e9241f'
+ """
+
+
def test_list_tree():
"""
Test git-ls-tree