Only assert private dirs, when worktree = $HOME

This commit is contained in:
Tim Byrne 2019-12-10 08:16:42 -06:00
parent e7d2406af3
commit 18e5fcfacc
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
3 changed files with 26 additions and 8 deletions

View File

@ -8,7 +8,8 @@ pytestmark = pytest.mark.usefixtures('ds1_copy')
PRIVATE_DIRS = ['.gnupg', '.ssh']
def test_pdirs_missing(runner, yadm_y, paths):
@pytest.mark.parametrize('home', [True, False], ids=['home', 'not-home'])
def test_pdirs_missing(runner, yadm_y, paths, home):
"""Private dirs (private dirs missing)
When a git command is run
@ -23,8 +24,12 @@ def test_pdirs_missing(runner, yadm_y, paths):
path.remove()
assert not path.exists()
env = {'DEBUG': 'yes'}
if home:
env['HOME'] = paths.work
# run status
run = runner(command=yadm_y('status'), env={'DEBUG': 'yes'})
run = runner(command=yadm_y('status'), env=env)
assert run.success
assert run.err == ''
assert 'On branch master' in run.out
@ -33,13 +38,19 @@ def test_pdirs_missing(runner, yadm_y, paths):
# and are protected
for pdir in PRIVATE_DIRS:
path = paths.work.join(pdir)
assert path.exists()
assert oct(path.stat().mode).endswith('00'), 'Directory is not secured'
if home:
assert path.exists()
assert oct(path.stat().mode).endswith('00'), ('Directory is '
'not secured')
else:
assert not path.exists()
# confirm directories are created before command is run:
assert re.search(
r'Creating.+\.gnupg.+Creating.+\.ssh.+Running git command git status',
run.out, re.DOTALL), 'directories created before command is run'
if home:
assert re.search(
(r'Creating.+\.gnupg.+Creating.+\.ssh.+'
r'Running git command git status'),
run.out, re.DOTALL), 'directories created before command is run'
def test_pdirs_missing_apd_false(runner, yadm_y, paths):

View File

@ -222,8 +222,11 @@ def test_clone_perms(
paths.work.remove()
paths.work.mkdir()
env = {'HOME': paths.work}
run = runner(
yadm_y('clone', '-d', '-w', paths.work, f'file://{paths.remote}'))
yadm_y('clone', '-d', '-w', paths.work, f'file://{paths.remote}'),
env=env
)
assert successful_clone(run, paths, repo_config)
if in_work:

4
yadm
View File

@ -1564,6 +1564,10 @@ function invoke_hook() {
function assert_private_dirs() {
work=$(unix_path "$("$GIT_PROGRAM" config core.worktree)")
# only assert private dirs if the worktree is the same as $HOME
[ "$work" != "$HOME" ] && return
for private_dir in "$@"; do
if [ ! -d "$work/$private_dir" ]; then
debug "Creating $work/$private_dir"