Skip to content

Commit

Permalink
Better workdir tests, fixed git commit method.
Browse files Browse the repository at this point in the history
Removed repo.refs.set_symbolic_ref('HEAD', ref) as it
does similar to what branch checkout does without updating
wokring directory files (which should not occur at
in memory commit)
  • Loading branch information
lukaszb committed Apr 28, 2013
1 parent e8ae800 commit 67fc1ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion vcs/backends/git/inmemory.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def commit(self, message, author, parents=None, branch=None, date=None,

ref = 'refs/heads/%s' % branch
repo.refs[ref] = commit.id
repo.refs.set_symbolic_ref('HEAD', ref)

# Update vcs repository object & recreate dulwich repo
self.repository.revisions.append(commit.id)
Expand Down
1 change: 1 addition & 0 deletions vcs/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def setUpClass(cls):
cls.repo_path = get_new_dir(str(time.time()))
cls.repo = Backend(cls.repo_path, create=True)
cls.imc = cls.repo.in_memory_changeset
cls.default_branch = cls.repo.DEFAULT_BRANCH_NAME

for commit in cls._get_commits():
for node in commit.get('added', []):
Expand Down
8 changes: 8 additions & 0 deletions vcs/tests/test_workdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,25 @@ def test_get_branch_after_adding_one(self):
author=u'joe',
branch='foobar',
)
self.assertEqual(self.repo.workdir.get_branch(), self.default_branch)

def test_get_changeset(self):
old_head = self.repo.get_changeset()
self.imc.add(FileNode('docs/index.txt',
content='Documentation\n'))
head = self.imc.commit(
message=u'New branch: foobar',
author=u'joe',
branch='foobar',
)
self.assertEqual(self.repo.workdir.get_branch(), self.default_branch)
self.repo.workdir.checkout_branch('foobar')
self.assertEqual(self.repo.workdir.get_changeset(), head)

# Make sure that old head is still there after update to defualt branch
self.repo.workdir.checkout_branch(self.default_branch)
self.assertEqual(self.repo.workdir.get_changeset(), old_head)

def test_checkout_branch(self):
from vcs.exceptions import BranchDoesNotExistError
# first, 'foobranch' does not exist.
Expand Down

0 comments on commit 67fc1ca

Please sign in to comment.