Instead of doing work to find the default branch just to be able to set up the repository before doing a fetch, do a "git clone" and let git handle it. Use -c core.sharedrepository=0600 to get the same result as --shared=0600 passed to init. Use --separate-git-dir to get the git directory in $YADM_REPO. Use a temporary dir as work tree and remove it right after the clone is done. When the clone is done, iterate over all missing files in $YADM_WORK and perform a checkout. If local files exists that differ compared with the cloned ones the local files are left intact and the user is instructed to deal with the conflicts.pull/289/head
parent
a5b1067e02
commit
f45e66d4da
@ -1,27 +0,0 @@
|
||||
"""Unit tests: _default_remote_branch()"""
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize('condition', ['found', 'missing'])
|
||||
def test(runner, paths, condition):
|
||||
"""Test _default_remote_branch()"""
|
||||
test_branch = 'test/branch'
|
||||
output = f'ref: refs/heads/{test_branch}\\tHEAD\\n'
|
||||
if condition == 'missing':
|
||||
output = 'output that is missing ref'
|
||||
script = f"""
|
||||
YADM_TEST=1 source {paths.pgm}
|
||||
function git() {{
|
||||
printf '{output}';
|
||||
printf 'mock stderr\\n' 1>&2
|
||||
}}
|
||||
_default_remote_branch URL
|
||||
"""
|
||||
print(condition)
|
||||
run = runner(command=['bash'], inp=script)
|
||||
assert run.success
|
||||
assert run.err == ''
|
||||
if condition == 'found':
|
||||
assert run.out.strip() == test_branch
|
||||
else:
|
||||
assert run.out.strip() == 'master'
|
@ -1,40 +0,0 @@
|
||||
"""Unit tests: is_valid_branch_name"""
|
||||
import pytest
|
||||
|
||||
# Git branches do not allow:
|
||||
# * path component that begins with "."
|
||||
# * double dot
|
||||
# * "~", "^", ":", "\", space
|
||||
# * end with a "/"
|
||||
# * end with ".lock"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'branch, expected', [
|
||||
('master', 'valid'),
|
||||
('path/branch', 'valid'),
|
||||
('path/.branch', 'invalid'),
|
||||
('path..branch', 'invalid'),
|
||||
('path~branch', 'invalid'),
|
||||
('path^branch', 'invalid'),
|
||||
('path:branch', 'invalid'),
|
||||
('path\\branch', 'invalid'),
|
||||
('path branch', 'invalid'),
|
||||
('path/branch/', 'invalid'),
|
||||
('branch.lock', 'invalid'),
|
||||
])
|
||||
def test_is_valid_branch_name(runner, yadm, branch, expected):
|
||||
"""Test function is_valid_branch_name()"""
|
||||
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
if is_valid_branch_name "{branch}"; then
|
||||
echo valid
|
||||
else
|
||||
echo invalid
|
||||
fi
|
||||
"""
|
||||
run = runner(command=['bash'], inp=script)
|
||||
assert run.success
|
||||
assert run.err == ''
|
||||
assert run.out.strip() == expected
|
Loading…
Reference in new issue