def test_with_user(self, repo: Repo, tmpdir: TempDirectory): repo.commit_content('a') clone = Repo.clone(repo, 'clone', User('Foo', '*****@*****.**')) tmpdir.check('clone', 'repo') config = (clone.path / '.git' / 'config').read_text() assert 'name = Foo' in config assert 'email = [email protected]' in config
def test_with_user(self, repo: Repo, tmpdir: TempDirectory): repo.commit_content('a') git = Git.clone(repo.path, tmpdir.getpath('clone'), User(name='Foo Bar', email='*****@*****.**')) config = (git.path / '.git' / 'config').read_text() assert 'name = Foo Bar' in config assert 'email = [email protected]' in config
def test_branch_hashes(self, repo: Repo): repo.commit_content('a', branch='a-branch') repo.commit_content('b', branch='b-branch') compare(repo.branch_hashes(), expected={ 'a-branch': repo.rev_parse('a-branch'), 'b-branch': repo.rev_parse('b-branch') })
def test_tag_hashes(self, repo: Repo): repo.commit_content('a', tag='a-tag') repo.commit_content('b', tag='b-tag') compare(repo.tag_hashes(), expected={ 'a-tag': repo.rev_parse('a-tag'), 'b-tag': repo.rev_parse('b-tag') })
def test_clone(self, tmpdir: TempDirectory): root = Path(tmpdir.path) upstream = Repo.make(root / 'upstream') upstream.commit_content('a') clone = Repo.clone(upstream, root / 'clone') tmpdir.check('clone', 'upstream') config = (clone.path / '.git' / 'config').read_text() assert 'name = Giterator' in config assert 'email = [email protected]' in config
def test_repo(self, repo: Repo, tmpdir: TempDirectory): repo.commit_content('a') source = Git(repo.path) git = Git.clone(source, tmpdir.getpath('clone')) commit, = git('log', '--format=%h').split() compare(git('show', '--pretty=format:%s', '--stat', commit), expected=('a commit\n' ' a | 1 +\n' ' 1 file changed, 1 insertion(+)\n'))
def test_clone_non_testing(self, git: Git): (git.path / 'a').write_text('content') git.commit('a commit') clone = Repo.clone(git, 'clone') assert isinstance(clone, Repo) commit, = clone.git('log', '--format=%h').split() compare(clone.git('show', '--pretty=format:%s', '--stat', commit), expected=( 'a commit\n' ' a | 1 +\n' ' 1 file changed, 1 insertion(+)\n' ))
def test_minimal(self, repo: Repo, tmpdir: TempDirectory): hash = repo.commit_content('a') git = Git.clone(repo.path, tmpdir.getpath('clone')) commit, = git('log', '--format=%h').split() compare(hash, expected=commit) compare(git.git('show', '--pretty=format:%s', '--stat', commit), expected=('a commit\n' ' a | 1 +\n' ' 1 file changed, 1 insertion(+)\n')) compare(git('remote', '-v').split(), expected=[ 'origin', str(repo.path), '(fetch)', 'origin', str(repo.path), '(push)' ])
def test_branch_hashes_empty(self, repo: Repo): compare(repo.branch_hashes(), expected={})
def test_branch(self, repo: Repo): repo.commit_content('a', branch='a-branch') repo.commit_content('b', branch='b-branch') compare(repo.branches(), expected=['a-branch', 'b-branch'])
def test_tag_hashes_empty(self, repo: Repo): compare(repo.tag_hashes(), expected={})
def test_commit_with_one_date(self, repo: Repo): (repo.path / 'content.txt').write_text('content') repo.commit('commit', datetime(2000, 1, 1)) compare(repo.git('log', '--pretty=format:%ad'), expected='Sat Jan 1 00:00:00 2000 +0000') compare(repo.git('log', '--pretty=format:%cd'), expected='Sat Jan 1 00:00:00 2000 +0000')
def test_tags_empty(self, repo: Repo): compare(repo.tags(), expected=[])
def test_rev_parse(self, repo: Repo): repo.commit_content('a', datetime(2001, 1, 1, 10)) compare(repo.rev_parse('HEAD'), expected='5ee580a')
def test_commit_with_both_dates_explicit(self, repo: Repo): (repo.path / 'content.txt').write_text('content') repo.commit('commit', author_date=datetime(2000, 1, 1), commit_date=datetime(2000, 1, 2)) compare(repo.git('log', '--pretty=format:%ad'), expected='Sat Jan 1 00:00:00 2000 +0000') compare(repo.git('log', '--pretty=format:%cd'), expected='Sun Jan 2 00:00:00 2000 +0000')
def test_tags(self, repo: Repo): repo.commit_content('a', tag='a-tag') repo.commit_content('b', tag='b-tag') compare(repo.tags(), expected=['a-tag', 'b-tag'])
def repo(tmpdir: TempDirectory): return Repo.make(Path(tmpdir.path) / 'repo')