Skip to content

Adding to the index of a bare repository. #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
moshevds committed Dec 31, 2013
commit f9133376f2262f9f4067e41d9ed6da420f83437b
34 changes: 34 additions & 0 deletions git/test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
import time
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):

def __init__(self, *args):
Expand Down Expand Up @@ -646,6 +652,34 @@ def make_paths():
for absfile in absfiles:
assert os.path.isfile(absfile)

@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."


@with_rw_repo('HEAD')
def test_compare_write_tree(self, rw_repo):
Expand Down