2018-07-11 12:50:42 +00:00
|
|
|
"""Test init"""
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'alt_work, repo_present, force', [
|
|
|
|
(False, False, False),
|
|
|
|
(True, False, False),
|
|
|
|
(False, True, False),
|
|
|
|
(False, True, True),
|
|
|
|
(True, True, True),
|
|
|
|
], ids=[
|
|
|
|
'simple',
|
|
|
|
'-w',
|
|
|
|
'existing repo',
|
|
|
|
'-f',
|
|
|
|
'-w & -f',
|
|
|
|
])
|
|
|
|
@pytest.mark.usefixtures('ds1_work_copy')
|
|
|
|
def test_init(
|
2020-11-17 20:38:31 +00:00
|
|
|
runner, yadm_cmd, paths, repo_config, alt_work, repo_present, force):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""Test init
|
|
|
|
|
|
|
|
Repos should have attribs:
|
|
|
|
- 0600 permissions
|
|
|
|
- not bare
|
|
|
|
- worktree = $HOME
|
|
|
|
- showUntrackedFiles = no
|
|
|
|
- yadm.managed = true
|
|
|
|
"""
|
|
|
|
|
|
|
|
# these tests will assume this for $HOME
|
|
|
|
home = str(paths.root.mkdir('HOME'))
|
|
|
|
|
|
|
|
# ds1_work_copy comes WITH an empty repo dir present.
|
|
|
|
old_repo = paths.repo.join('old_repo')
|
|
|
|
if repo_present:
|
|
|
|
# Let's put some data in it, so we can confirm that data is gone when
|
|
|
|
# forced to be overwritten.
|
|
|
|
old_repo.write('old repo data')
|
|
|
|
assert old_repo.isfile()
|
|
|
|
else:
|
|
|
|
paths.repo.remove()
|
|
|
|
|
|
|
|
# command args
|
|
|
|
args = ['init']
|
2021-01-07 17:59:41 +00:00
|
|
|
cwd = None
|
2018-07-11 12:50:42 +00:00
|
|
|
if alt_work:
|
2021-01-07 17:59:41 +00:00
|
|
|
if force:
|
|
|
|
cwd = paths.work.dirname
|
|
|
|
args.extend(['-w', paths.work.basename])
|
|
|
|
else:
|
|
|
|
args.extend(['-w', paths.work])
|
2018-07-11 12:50:42 +00:00
|
|
|
if force:
|
|
|
|
args.append('-f')
|
|
|
|
|
|
|
|
# run init
|
2021-01-07 17:59:41 +00:00
|
|
|
run = runner(yadm_cmd(*args), env={'HOME': home}, cwd=cwd)
|
2018-07-11 12:50:42 +00:00
|
|
|
|
|
|
|
if repo_present and not force:
|
|
|
|
assert run.failure
|
2021-01-05 20:57:32 +00:00
|
|
|
assert 'repo already exists' in run.err
|
2018-07-11 12:50:42 +00:00
|
|
|
assert old_repo.isfile(), 'Missing original repo'
|
|
|
|
else:
|
|
|
|
assert run.success
|
|
|
|
assert 'Initialized empty shared Git repository' in run.out
|
2021-01-05 20:57:32 +00:00
|
|
|
assert run.err == ''
|
2018-07-11 12:50:42 +00:00
|
|
|
|
|
|
|
if repo_present:
|
|
|
|
assert not old_repo.isfile(), 'Original repo still exists'
|
|
|
|
|
|
|
|
if alt_work:
|
|
|
|
assert repo_config('core.worktree') == paths.work
|
|
|
|
else:
|
|
|
|
assert repo_config('core.worktree') == home
|
|
|
|
|
|
|
|
# uniform repo assertions
|
|
|
|
assert oct(paths.repo.stat().mode).endswith('00'), (
|
|
|
|
'Repo is not secure')
|
|
|
|
assert repo_config('core.bare') == 'false'
|
|
|
|
assert repo_config('status.showUntrackedFiles') == 'no'
|
|
|
|
assert repo_config('yadm.managed') == 'true'
|