Skip to content
Snippets Groups Projects
Commit 3411ea85 authored by Georges Racinet's avatar Georges Racinet :squid:
Browse files

testhelpers.git: git init with working directory

Its own `test_git` is a good example of how it can be useful.
parent d88573c9
No related branches found
No related tags found
1 merge request!116testhelpers.git: creating from bundle data
......@@ -55,8 +55,12 @@
self.path = path
@classmethod
def init(cls, path):
subprocess.call(('git', 'init', '--bare', str(path)))
def init(cls, path, bare=True):
cmd = ['git', 'init']
if bare:
cmd.append('--bare')
cmd.append(str(path))
subprocess.call(cmd)
return cls(path)
def git(self, *args):
......
......@@ -6,6 +6,9 @@
# SPDX-License-Identifier: GPL-2.0-or-later
import subprocess
from ..git import GitRepo
import pytest
parametrize = pytest.mark.parametrize
def test_refs(tmpdir):
......@@ -14,12 +17,9 @@
server_repo = GitRepo.init(server)
client = tmpdir / 'client'
subprocess.call(('git', 'init', str(client)))
subprocess.call(('git', 'remote', 'add', 'origin', str(server)),
cwd=str(client))
subprocess.call(('git', 'config', 'user.name', 'John Doe'),
cwd=str(client))
subprocess.call(('git', 'config', 'user.email', 'jdoe@heptapod.example'),
cwd=str(client))
client_repo = GitRepo.init(client, bare=False)
client_repo.git('remote', 'add', 'origin', str(server))
client_repo.git('config', 'user.name', 'John Doe')
client_repo.git('config', 'user.email', 'jdoe@heptapod.example')
(client / 'foo').write('foo')
......@@ -24,10 +24,8 @@
(client / 'foo').write('foo')
subprocess.call(('git', 'add', 'foo'), cwd=str(client))
subprocess.call(('git', 'commit', '-m', 'init commit', '--no-gpg-sign'),
cwd=str(client))
subprocess.call(('git', 'push', 'origin', 'master'), cwd=str(client))
client_repo.git('add', 'foo')
client_repo.git('commit', '-m', 'init commit', '--no-gpg-sign')
client_repo.git('push', 'origin', 'master')
assert server_repo.branch_titles() == {b'master': b'init commit'}
......@@ -50,9 +48,7 @@
# (for Git < 2.45 coverage): same HEAD but an additional branch
(client / 'foo').write('bar')
subprocess.call(('git', 'checkout', '-b', 'other'), cwd=str(client))
subprocess.call(('git', 'add', 'foo'), cwd=str(client))
subprocess.call(('git', 'commit', '-m', 'other branch', '--no-gpg-sign'),
cwd=str(client))
client_repo.git('checkout', '-b', 'other')
client_repo.git('add', 'foo')
client_repo.git('commit', '-m', 'other branch', '--no-gpg-sign')
assert server_repo != client_repo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment