summaryrefslogtreecommitdiff
path: root/git/test/test_index.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/test/test_index.py')
-rw-r--r--git/test/test_index.py34
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."
+
+