Only assert private dirs, when worktree = $HOME
This commit is contained in:
parent
e7d2406af3
commit
18e5fcfacc
3 changed files with 26 additions and 8 deletions
|
@ -8,7 +8,8 @@ pytestmark = pytest.mark.usefixtures('ds1_copy')
|
||||||
PRIVATE_DIRS = ['.gnupg', '.ssh']
|
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)
|
"""Private dirs (private dirs missing)
|
||||||
|
|
||||||
When a git command is run
|
When a git command is run
|
||||||
|
@ -23,8 +24,12 @@ def test_pdirs_missing(runner, yadm_y, paths):
|
||||||
path.remove()
|
path.remove()
|
||||||
assert not path.exists()
|
assert not path.exists()
|
||||||
|
|
||||||
|
env = {'DEBUG': 'yes'}
|
||||||
|
if home:
|
||||||
|
env['HOME'] = paths.work
|
||||||
|
|
||||||
# run status
|
# run status
|
||||||
run = runner(command=yadm_y('status'), env={'DEBUG': 'yes'})
|
run = runner(command=yadm_y('status'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
assert 'On branch master' in run.out
|
assert 'On branch master' in run.out
|
||||||
|
@ -33,12 +38,18 @@ def test_pdirs_missing(runner, yadm_y, paths):
|
||||||
# and are protected
|
# and are protected
|
||||||
for pdir in PRIVATE_DIRS:
|
for pdir in PRIVATE_DIRS:
|
||||||
path = paths.work.join(pdir)
|
path = paths.work.join(pdir)
|
||||||
|
if home:
|
||||||
assert path.exists()
|
assert path.exists()
|
||||||
assert oct(path.stat().mode).endswith('00'), 'Directory is not secured'
|
assert oct(path.stat().mode).endswith('00'), ('Directory is '
|
||||||
|
'not secured')
|
||||||
|
else:
|
||||||
|
assert not path.exists()
|
||||||
|
|
||||||
# confirm directories are created before command is run:
|
# confirm directories are created before command is run:
|
||||||
|
if home:
|
||||||
assert re.search(
|
assert re.search(
|
||||||
r'Creating.+\.gnupg.+Creating.+\.ssh.+Running git command git status',
|
(r'Creating.+\.gnupg.+Creating.+\.ssh.+'
|
||||||
|
r'Running git command git status'),
|
||||||
run.out, re.DOTALL), 'directories created before command is run'
|
run.out, re.DOTALL), 'directories created before command is run'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -222,8 +222,11 @@ def test_clone_perms(
|
||||||
paths.work.remove()
|
paths.work.remove()
|
||||||
paths.work.mkdir()
|
paths.work.mkdir()
|
||||||
|
|
||||||
|
env = {'HOME': paths.work}
|
||||||
run = runner(
|
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)
|
assert successful_clone(run, paths, repo_config)
|
||||||
if in_work:
|
if in_work:
|
||||||
|
|
4
yadm
4
yadm
|
@ -1564,6 +1564,10 @@ function invoke_hook() {
|
||||||
|
|
||||||
function assert_private_dirs() {
|
function assert_private_dirs() {
|
||||||
work=$(unix_path "$("$GIT_PROGRAM" config core.worktree)")
|
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
|
for private_dir in "$@"; do
|
||||||
if [ ! -d "$work/$private_dir" ]; then
|
if [ ! -d "$work/$private_dir" ]; then
|
||||||
debug "Creating $work/$private_dir"
|
debug "Creating $work/$private_dir"
|
||||||
|
|
Loading…
Reference in a new issue