From 18e5fcfacc7f460473d8e3202c512273cad698bd Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Tue, 10 Dec 2019 08:16:42 -0600 Subject: [PATCH] Only assert private dirs, when worktree = $HOME --- test/test_assert_private_dirs.py | 25 ++++++++++++++++++------- test/test_clone.py | 5 ++++- yadm | 4 ++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/test/test_assert_private_dirs.py b/test/test_assert_private_dirs.py index 65cb0b7..2d4d163 100644 --- a/test/test_assert_private_dirs.py +++ b/test/test_assert_private_dirs.py @@ -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): diff --git a/test/test_clone.py b/test/test_clone.py index 7cbbb5f..a6df6d0 100644 --- a/test/test_clone.py +++ b/test/test_clone.py @@ -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: diff --git a/yadm b/yadm index 2bbecc8..d38376b 100755 --- a/yadm +++ b/yadm @@ -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"