2018-07-11 08:50:42 -04:00
|
|
|
"""Test init"""
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-10 15:43:17 -04:00
|
|
|
"alt_work, repo_present, force",
|
|
|
|
[
|
2018-07-11 08:50:42 -04:00
|
|
|
(False, False, False),
|
|
|
|
(True, False, False),
|
|
|
|
(False, True, False),
|
|
|
|
(False, True, True),
|
|
|
|
(True, True, True),
|
2023-07-10 15:43:17 -04:00
|
|
|
],
|
|
|
|
ids=[
|
|
|
|
"simple",
|
|
|
|
"-w",
|
|
|
|
"existing repo",
|
|
|
|
"-f",
|
|
|
|
"-w & -f",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
@pytest.mark.usefixtures("ds1_work_copy")
|
|
|
|
def test_init(runner, yadm_cmd, paths, repo_config, alt_work, repo_present, force):
|
2018-07-11 08:50:42 -04: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
|
2023-07-10 15:43:17 -04:00
|
|
|
home = str(paths.root.mkdir("HOME"))
|
2018-07-11 08:50:42 -04:00
|
|
|
|
|
|
|
# ds1_work_copy comes WITH an empty repo dir present.
|
2023-07-10 15:43:17 -04:00
|
|
|
old_repo = paths.repo.join("old_repo")
|
2018-07-11 08:50:42 -04:00
|
|
|
if repo_present:
|
|
|
|
# Let's put some data in it, so we can confirm that data is gone when
|
|
|
|
# forced to be overwritten.
|
2023-07-10 15:43:17 -04:00
|
|
|
old_repo.write("old repo data")
|
2018-07-11 08:50:42 -04:00
|
|
|
assert old_repo.isfile()
|
|
|
|
else:
|
|
|
|
paths.repo.remove()
|
|
|
|
|
|
|
|
# command args
|
2023-07-10 15:43:17 -04:00
|
|
|
args = ["init"]
|
2021-01-07 12:59:41 -05:00
|
|
|
cwd = None
|
2018-07-11 08:50:42 -04:00
|
|
|
if alt_work:
|
2021-01-07 12:59:41 -05:00
|
|
|
if force:
|
|
|
|
cwd = paths.work.dirname
|
2023-07-10 15:43:17 -04:00
|
|
|
args.extend(["-w", paths.work.basename])
|
2021-01-07 12:59:41 -05:00
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
args.extend(["-w", paths.work])
|
2018-07-11 08:50:42 -04:00
|
|
|
if force:
|
2023-07-10 15:43:17 -04:00
|
|
|
args.append("-f")
|
2018-07-11 08:50:42 -04:00
|
|
|
|
|
|
|
# run init
|
2023-07-10 15:43:17 -04:00
|
|
|
runner(["git", "config", "--global", "init.defaultBranch", "master"], env={"HOME": home}, cwd=cwd)
|
|
|
|
run = runner(yadm_cmd(*args), env={"HOME": home}, cwd=cwd)
|
2018-07-11 08:50:42 -04:00
|
|
|
|
|
|
|
if repo_present and not force:
|
|
|
|
assert run.failure
|
2023-07-10 15:43:17 -04:00
|
|
|
assert "repo already exists" in run.err
|
|
|
|
assert old_repo.isfile(), "Missing original repo"
|
2018-07-11 08:50:42 -04:00
|
|
|
else:
|
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert "Initialized empty shared Git repository" in run.out
|
2018-07-11 08:50:42 -04:00
|
|
|
|
|
|
|
if repo_present:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert not old_repo.isfile(), "Original repo still exists"
|
2021-01-03 17:02:25 -05:00
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
2018-07-11 08:50:42 -04:00
|
|
|
|
|
|
|
if alt_work:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert repo_config("core.worktree") == paths.work
|
2018-07-11 08:50:42 -04:00
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert repo_config("core.worktree") == home
|
2018-07-11 08:50:42 -04:00
|
|
|
|
|
|
|
# uniform repo assertions
|
2023-07-10 15:43:17 -04:00
|
|
|
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"
|