diff options
-rw-r--r-- | gbp/git/repository.py | 25 | ||||
-rw-r--r-- | tests/test_GitRepository.py | 14 |
2 files changed, 39 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 43a8c46d..1c6fc34d 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 328a65fc..5393071e 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 |