def test_with_tz_datetime(self, git: Git): (git.path / 'a').write_text('content') dt = datetime(2001, 1, 1, 10).astimezone(timezone.utc) git.commit('a commit', dt, dt) compare( git('log', '--format=%aI %cI'), expected='2001-01-01T10:00:00+00:00 2001-01-01T10:00:00+00:00\n')
def test_from_empty(self, git: Git): (git.path / 'a').write_text('content') git.commit('a commit') compare(git.git('status', '-s'), expected='') commit, = git.git('log', '--format=%h').split() compare(git.git('show', '--pretty=format:%s', '--stat', commit), expected=('a commit\n' ' a | 1 +\n' ' 1 file changed, 1 insertion(+)\n'))
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_with_dates_as_strings(self, git: Git): (git.path / 'content.txt').write_text('content') git.commit( 'commit', author_date='format:iso8601:' + datetime(2000, 1, 1).isoformat(), commit_date='format:iso8601:' + datetime(2000, 1, 2).isoformat()) compare(git('log', '--pretty=format:%ad'), expected='Sat Jan 1 00:00:00 2000 +0000') compare(git('log', '--pretty=format:%cd'), expected='Sun Jan 2 00:00:00 2000 +0000')
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_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_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_from_one_commit(self, git: Git): (git.path / 'a').write_text('a content') (git.path / 'b').write_text('b content') (git.path / 'c').write_text('c content') git.commit('commit 1') (git.path / 'b').write_text('new content') (git.path / 'c').unlink() (git.path / 'd').write_text('d content') git.commit('commit 2') compare(git.git('status', '-s'), expected='') commit2, commit1 = git.git('log', '--format=%h').split() compare(git.git('show', '--pretty=format:%s', '--stat', commit1), expected=('commit 1\n' ' a | 1 +\n' ' b | 1 +\n' ' c | 1 +\n' ' 3 files changed, 3 insertions(+)\n')) compare( git.git('show', '--pretty=format:%s', '--stat', commit2), expected=('commit 2\n' ' b | 2 +-\n' ' c | 1 -\n' ' d | 1 +\n' ' 3 files changed, 2 insertions(+), 2 deletions(-)\n'))
def test_init_with_user(self, tmpdir: TempDirectory): Git(tmpdir.getpath('foo')).init( User(name='Foo Bar', email='*****@*****.**')) config = tmpdir.read('foo/.git/config') assert b'name = Foo Bar' in config assert b'email = [email protected]' in config
def test_init_make_path(self, tmpdir): Git(tmpdir.getpath('foo/bar')).init() assert os.path.exists(tmpdir.getpath('foo/bar/.git'))
def test_init(self, tmpdir: TempDirectory): tmpdir.makedir('foo') Git(tmpdir.getpath('foo')).init() assert os.path.exists(tmpdir.getpath('foo/.git'))
def test_with_committer_date(self, git: Git): (git.path / 'content.txt').write_text('content') git.commit('commit', commit_date=datetime(2000, 1, 1)) compare(git('log', '--pretty=format:%cd'), expected='Sat Jan 1 00:00:00 2000 +0000')
def git(tmpdir: TempDirectory): git_ = Git(Path(tmpdir.path) / 'git') git_.init(User(name='Giterator', email='*****@*****.**')) return git_