Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf913337

Browse files
committed
Test if it is possible to add files to the index of a bare repo.
Adding using a path should still require a non-bare repository.
1 parent660bdca commitf913337

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎git/test/test_index.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
importtime
2121
fromstatimport*
2222

23+
fromStringIOimportStringIO
24+
fromgitdb.baseimportIStream
25+
fromgit.objectsimportBlob
26+
fromgit.index.typimportBaseIndexEntry
27+
28+
2329
classTestIndex(TestBase):
2430

2531
def__init__(self,*args):
@@ -646,6 +652,34 @@ def make_paths():
646652
forabsfileinabsfiles:
647653
assertos.path.isfile(absfile)
648654

655+
@with_rw_repo('HEAD',bare=True)
656+
deftest_index_bare_add(self,rw_bare_repo):
657+
# Something is wrong after cloning to a bare repo, reading the
658+
# property rw_bare_repo.working_tree_dir will return '/tmp'
659+
# instead of throwing the Exception we are expecting. This is
660+
# a quick hack to make this test fail when expected.
661+
rw_bare_repo._working_tree_dir=None
662+
contents='This is a StringIO file'
663+
filesize=len(contents)
664+
fileobj=StringIO(contents)
665+
filename='my-imaginary-file'
666+
istream=rw_bare_repo.odb.store(
667+
IStream(Blob.type,filesize,fileobj))
668+
entry=BaseIndexEntry((100644,istream.binsha,0,filename))
669+
try:
670+
rw_bare_repo.index.add([entry])
671+
exceptAssertionError,e:
672+
self.fail("Adding to the index of a bare repo is not allowed.")
673+
674+
# Adding using a path should still require a non-bare repository.
675+
asserted=False
676+
path=os.path.join('git','test','test_index.py')
677+
try:
678+
rw_bare_repo.index.add([path])
679+
exceptException,e:
680+
asserted="does not have a working tree"ine.message
681+
assertasserted,"Adding using a filename is not correctly asserted."
682+
649683

650684
@with_rw_repo('HEAD')
651685
deftest_compare_write_tree(self,rw_repo):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp