diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2014-11-17 11:47:48 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2014-11-17 11:47:48 +0100 |
commit | 81223de22691e2df7b81cd384ad23be25cfd999c (patch) | |
tree | 49e2591530014913d40e66bbea77ee150cf7be46 /git/test/test_index.py | |
parent | 9eb902eee03806db5868fc84afb23aa28802e841 (diff) | |
download | gitpython-81223de22691e2df7b81cd384ad23be25cfd999c.tar.gz |
Allow Index.add() on bare repositories
Diffstat (limited to 'git/test/test_index.py')
-rw-r--r-- | git/test/test_index.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/git/test/test_index.py b/git/test/test_index.py index f1f718cd..3440c5be 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -14,6 +14,10 @@ import glob import shutil from stat import * +from StringIO import StringIO +from gitdb.base import IStream +from git.objects import Blob +from git.index.typ import BaseIndexEntry class TestIndex(TestBase): @@ -661,3 +665,33 @@ class TestIndex(TestBase): index = IndexFile.new(self.rorepo, *args) assert isinstance(index, IndexFile) # END for each arg tuple + + @with_rw_repo('HEAD', bare=True) + def test_index_bare_add(self, rw_bare_repo): + # Something is wrong after cloning to a bare repo, reading the + # property rw_bare_repo.working_tree_dir will return '/tmp' + # instead of throwing the Exception we are expecting. This is + # a quick hack to make this test fail when expected. + rw_bare_repo._working_tree_dir = None + contents = 'This is a StringIO file' + filesize = len(contents) + fileobj = StringIO(contents) + filename = 'my-imaginary-file' + istream = rw_bare_repo.odb.store( + IStream(Blob.type, filesize, fileobj)) + entry = BaseIndexEntry((100644, istream.binsha, 0, filename)) + try: + rw_bare_repo.index.add([entry]) + except AssertionError, e: + self.fail("Adding to the index of a bare repo is not allowed.") + + # Adding using a path should still require a non-bare repository. + asserted = False + path = os.path.join('git', 'test', 'test_index.py') + try: + rw_bare_repo.index.add([path]) + except Exception, e: + asserted = "does not have a working tree" in e.message + assert asserted, "Adding using a filename is not correctly asserted." + + |