def test_set_config(self): """Test the set config functionality""" repo = MirrorGitRepository.create('testrepo') with assert_raises(GitRepositoryError): repo.set_config('foo', 'bar') repo.set_config('foo.bar', 'baz') repo.set_config('foo.bar', 'bax', replace=True) eq_(repo.get_config('foo.bar'), 'bax')
def setup_class(cls): """Set-up tests""" # Fake committer and author author = {'name': 'John Doe', 'email': '*****@*****.**', 'date': '1390000000 +0200'} os.environ['GIT_AUTHOR_NAME'] = author['name'] os.environ['GIT_AUTHOR_EMAIL'] = author['email'] os.environ['GIT_AUTHOR_DATE'] = author['date'] committer = {'name': 'Jane Doe', 'email': '*****@*****.**', 'date': '1391000000 +0200'} os.environ['GIT_COMMITTER_NAME'] = committer['name'] os.environ['GIT_COMMITTER_EMAIL'] = committer['email'] os.environ['GIT_COMMITTER_DATE'] = committer['date'] # Initialize repo super(TestGitMeta, cls).setup_class() cls.repo = MirrorGitRepository.clone('myrepo', cls._template_repo.path) # Create test tags cls.repo.create_tag('tag', msg='Subject\n\nBody') cls.repo.create_tag('tag2', msg='Subject 2') cls.repo.create_tag('tag3', msg='Subject 3', commit='tag') cls.repo.create_tag('light_tag') # Reference meta _tags_meta = {'tag': {'tagname': 'tag', 'sha1': cls.repo.rev_parse('tag'), 'tagger': committer, 'subject': 'Subject', 'body': 'Body\n'}, 'tag2': {'tagname': 'tag2', 'sha1': cls.repo.rev_parse('tag2'), 'tagger': committer, 'subject': 'Subject 2', 'body': ''}, 'tag3': {'tagname': 'tag3', 'sha1': cls.repo.rev_parse('tag3'), 'tagger': committer, 'subject': 'Subject 3', 'body': ''}} cls.tag_meta = {'tagname': 'tag', 'sha1': cls.repo.rev_parse('tag'), 'tagger': committer, 'subject': 'Subject', 'body': 'Body\n', 'tags': [_tags_meta['tag3']]} commit = cls.repo.rev_parse('tag^0') cls.commit_meta = {'sha1': commit, 'author': author, 'committer': committer, 'subject': 'Add debian packaging files', 'body': '', 'files': {'A': ['debian/changelog', 'debian/control']}, 'tags': [_tags_meta['tag'], _tags_meta['tag2']]}
def test_list_tags(self): """Test list_tags() method""" repo = MirrorGitRepository.clone('testrepo', self.orig_repo.path) # No tags pointing to HEAD repo.create_tag('tag1', msg='Tag 1', commit='HEAD^') eq_(repo.list_tags('HEAD'), []) # One tag pointing to HEAD repo.create_tag('tag2', msg='Tag 2') eq_(repo.list_tags('HEAD'), ['tag2'])
def test_refs_hack(self): """Test git fetch refs hack""" repo = MirrorGitRepository.clone('testrepo', self.orig_repo.path, refs_hack=True) refs_path = os.path.join(repo.git_dir, 'refs') ok_(os.path.islink(refs_path)) # Fetch without hack and see that symlink is removed repo.force_fetch() ok_(not os.path.islink(refs_path)) # Re-fetch with hack enabled and see that symlink restored repo.force_fetch(refs_hack=True) ok_(os.path.islink(refs_path))
def test_get_tag_info(self): """Test get_tag_info() method""" repo = MirrorGitRepository.clone('testrepo', self.orig_repo.path) tagger = { 'name': 'John Doe', 'email': '*****@*****.**', 'date': '1390000000 +0200' } os.environ['GIT_COMMITTER_NAME'] = tagger['name'] os.environ['GIT_COMMITTER_EMAIL'] = tagger['email'] os.environ['GIT_COMMITTER_DATE'] = tagger['date'] # Non-tag with assert_raises(GitRepositoryError): info = repo.get_tag_info('HEAD') # Completely empty message repo.create_tag('tag1', msg=' ') info = repo.get_tag_info('tag1') eq_(info['tagger'], tagger) eq_(info['subject'], '') eq_(info['body'], '') eq_(info['sha1'], repo.rev_parse('tag1')) # Empty message body repo.create_tag('tag2', msg='Tag subject') info = repo.get_tag_info('tag2') eq_(info['tagger'], tagger) eq_(info['subject'], 'Tag subject') eq_(info['body'], '') # Multi-line subject with body repo.create_tag('tag3', msg='Tag\nsubject\n\nTag\nbody') info = repo.get_tag_info('tag3') eq_(info['tagger'], tagger) eq_(info['subject'], 'Tag subject') eq_(info['body'], 'Tag\nbody\n') # Clean environmemt del os.environ['GIT_COMMITTER_NAME'] del os.environ['GIT_COMMITTER_EMAIL'] del os.environ['GIT_COMMITTER_DATE']
def test_force_fetch(self): """Test fetching""" repo = MirrorGitRepository.clone('testrepo', self.orig_repo.path) # Make remote HEAD invalid orig_branch = self.orig_repo.get_branch() with open(os.path.join(self.orig_repo.git_dir, 'HEAD'), 'w') as head: head.write('ref: refs/heads/non-existent-branch\n') # Local HEAD should be invalid after fetch repo.force_fetch() eq_(repo.get_ref('FETCH_HEAD'), '0000000000000000000000000000000000000000') # Fetch should succeed even if local head is invalid repo.set_ref('HEAD', '1234567890123456789012345678901234567890') repo.force_fetch() eq_(repo.get_ref('HEAD'), '1234567890123456789012345678901234567890') # Restore orig repo HEAD self.orig_repo.set_branch(orig_branch)
def test_get_set_ref(self): """Test setting and getting ref""" repo = MirrorGitRepository.clone('testrepo', self.orig_repo.path) remote_head = 'refs/heads/' + self.orig_repo.get_branch() eq_(repo.get_ref('HEAD'), remote_head) with assert_raises(GitRepositoryError): repo.get_ref('MY_REF') repo.set_ref('MY_REF', repo.get_ref('HEAD')) eq_(repo.get_ref('MY_REF'), remote_head) sha1 = repo.rev_parse('HEAD') repo.set_ref('MY_REF', sha1) eq_(repo.get_ref('MY_REF'), sha1) # Test failure cases (unable to create ref) with assert_raises(GitRepositoryError): repo.set_ref('refs/heads', sha1) with assert_raises(GitRepositoryError): repo.set_ref('refs/heads', 'refs/heads/master')
def test_get_tag_info(self): """Test get_tag_info() method""" repo = MirrorGitRepository.clone('testrepo', self.orig_repo.path) tagger = {'name': 'John Doe', 'email': '*****@*****.**', 'date': '1390000000 +0200'} os.environ['GIT_COMMITTER_NAME'] = tagger['name'] os.environ['GIT_COMMITTER_EMAIL'] = tagger['email'] os.environ['GIT_COMMITTER_DATE'] = tagger['date'] # Non-tag with assert_raises(GitRepositoryError): info = repo.get_tag_info('HEAD') # Completely empty message repo.create_tag('tag1', msg=' ') info = repo.get_tag_info('tag1') eq_(info['tagger'], tagger) eq_(info['subject'], '') eq_(info['body'], '') eq_(info['sha1'], repo.rev_parse('tag1')) # Empty message body repo.create_tag('tag2', msg='Tag subject') info = repo.get_tag_info('tag2') eq_(info['tagger'], tagger) eq_(info['subject'], 'Tag subject') eq_(info['body'], '') # Multi-line subject with body repo.create_tag('tag3', msg='Tag\nsubject\n\nTag\nbody') info = repo.get_tag_info('tag3') eq_(info['tagger'], tagger) eq_(info['subject'], 'Tag subject') eq_(info['body'], 'Tag\nbody\n') # Clean environmemt del os.environ['GIT_COMMITTER_NAME'] del os.environ['GIT_COMMITTER_EMAIL'] del os.environ['GIT_COMMITTER_DATE']
def setup_class(cls): """Set-up tests""" # Fake committer and author author = { 'name': 'John Doe', 'email': '*****@*****.**', 'date': '1390000000 +0200' } os.environ['GIT_AUTHOR_NAME'] = author['name'] os.environ['GIT_AUTHOR_EMAIL'] = author['email'] os.environ['GIT_AUTHOR_DATE'] = author['date'] committer = { 'name': 'Jane Doe', 'email': '*****@*****.**', 'date': '1391000000 +0200' } os.environ['GIT_COMMITTER_NAME'] = committer['name'] os.environ['GIT_COMMITTER_EMAIL'] = committer['email'] os.environ['GIT_COMMITTER_DATE'] = committer['date'] # Initialize repo super(TestGitMeta, cls).setup_class() cls.repo = MirrorGitRepository.clone('myrepo', cls._template_repo.path) # Create test tags cls.repo.create_tag('tag', msg='Subject\n\nBody') cls.repo.create_tag('tag2', msg='Subject 2') cls.repo.create_tag('tag3', msg='Subject 3', commit='tag') cls.repo.create_tag('light_tag') # Reference meta _tags_meta = { 'tag': { 'tagname': 'tag', 'sha1': cls.repo.rev_parse('tag'), 'tagger': committer, 'subject': 'Subject', 'body': 'Body\n' }, 'tag2': { 'tagname': 'tag2', 'sha1': cls.repo.rev_parse('tag2'), 'tagger': committer, 'subject': 'Subject 2', 'body': '' }, 'tag3': { 'tagname': 'tag3', 'sha1': cls.repo.rev_parse('tag3'), 'tagger': committer, 'subject': 'Subject 3', 'body': '' } } cls.tag_meta = { 'tagname': 'tag', 'sha1': cls.repo.rev_parse('tag'), 'tagger': committer, 'subject': 'Subject', 'body': 'Body\n', 'tags': [_tags_meta['tag3']] } commit = cls.repo.rev_parse('tag^0') cls.commit_meta = { 'sha1': commit, 'author': author, 'committer': committer, 'subject': 'Add debian packaging files', 'body': '', 'files': { 'A': ['debian/changelog', 'debian/control'] }, 'tags': [_tags_meta['tag'], _tags_meta['tag2']] }