Support GNUPGHOME environment variable (#134)
This commit is contained in:
parent
84a173551e
commit
b9f5fdaafa
3 changed files with 57 additions and 5 deletions
|
@ -48,7 +48,7 @@ def test_pdirs_missing(runner, yadm_y, paths, home):
|
||||||
# confirm directories are created before command is run:
|
# confirm directories are created before command is run:
|
||||||
if home:
|
if home:
|
||||||
assert re.search(
|
assert re.search(
|
||||||
(r'Creating.+\.gnupg.+Creating.+\.ssh.+'
|
(r'Creating.+\.(gnupg|ssh).+Creating.+\.(gnupg|ssh).+'
|
||||||
r'Running git command git status'),
|
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'
|
||||||
|
|
||||||
|
|
34
test/test_unit_private_dirs.py
Normal file
34
test/test_unit_private_dirs.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
"""Unit tests: private_dirs"""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'gnupghome',
|
||||||
|
[True, False],
|
||||||
|
ids=['gnupghome-set', 'gnupghome-unset'],
|
||||||
|
)
|
||||||
|
@pytest.mark.parametrize('param', ['all', 'gnupg'])
|
||||||
|
def test_relative_path(runner, paths, gnupghome, param):
|
||||||
|
"""Test translate_to_relative"""
|
||||||
|
|
||||||
|
alt_gnupghome = 'alt/gnupghome'
|
||||||
|
env_gnupghome = paths.work.join(alt_gnupghome)
|
||||||
|
|
||||||
|
script = f"""
|
||||||
|
YADM_TEST=1 source {paths.pgm}
|
||||||
|
YADM_WORK={paths.work}
|
||||||
|
private_dirs {param}
|
||||||
|
"""
|
||||||
|
|
||||||
|
env = {}
|
||||||
|
if gnupghome:
|
||||||
|
env['GNUPGHOME'] = env_gnupghome
|
||||||
|
|
||||||
|
expected = alt_gnupghome if gnupghome else '.gnupg'
|
||||||
|
if param == 'all':
|
||||||
|
expected = f'.ssh {expected}'
|
||||||
|
|
||||||
|
run = runner(command=['bash'], inp=script, env=env)
|
||||||
|
assert run.success
|
||||||
|
assert run.err == ''
|
||||||
|
assert run.out.strip() == expected
|
26
yadm
26
yadm
|
@ -735,7 +735,7 @@ function clone() {
|
||||||
|
|
||||||
if [ "$YADM_WORK" = "$HOME" ]; then
|
if [ "$YADM_WORK" = "$HOME" ]; then
|
||||||
debug "Determining if repo tracks private directories"
|
debug "Determining if repo tracks private directories"
|
||||||
for private_dir in .ssh/ .gnupg/; do
|
for private_dir in $(private_dirs all); do
|
||||||
found_log=$("$GIT_PROGRAM" log -n 1 "origin/${branch}" -- "$private_dir" 2>/dev/null)
|
found_log=$("$GIT_PROGRAM" log -n 1 "origin/${branch}" -- "$private_dir" 2>/dev/null)
|
||||||
if [ -n "$found_log" ]; then
|
if [ -n "$found_log" ]; then
|
||||||
debug "Private directory $private_dir is tracked by repo"
|
debug "Private directory $private_dir is tracked by repo"
|
||||||
|
@ -947,7 +947,9 @@ function git_command() {
|
||||||
if [ "$YADM_WORK" = "$HOME" ]; then
|
if [ "$YADM_WORK" = "$HOME" ]; then
|
||||||
auto_private_dirs=$(config --bool yadm.auto-private-dirs)
|
auto_private_dirs=$(config --bool yadm.auto-private-dirs)
|
||||||
if [ "$auto_private_dirs" != "false" ] ; then
|
if [ "$auto_private_dirs" != "false" ] ; then
|
||||||
assert_private_dirs .gnupg/ .ssh/
|
for pdir in $(private_dirs all); do
|
||||||
|
assert_private_dirs "$pdir"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1115,8 +1117,9 @@ function perms() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# include all gpg files (unless disabled)
|
# include all gpg files (unless disabled)
|
||||||
|
gnupghome="$(private_dirs gnupg)"
|
||||||
if [[ $(config --bool yadm.gpg-perms) != "false" ]] ; then
|
if [[ $(config --bool yadm.gpg-perms) != "false" ]] ; then
|
||||||
GLOBS+=(".gnupg" ".gnupg/*" ".gnupg/.[!.]*")
|
GLOBS+=("${gnupghome}" "${gnupghome}/*" "${gnupghome}/.[!.]*")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1575,6 +1578,21 @@ function invoke_hook() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function private_dirs() {
|
||||||
|
fetch="$1"
|
||||||
|
pdirs=(.ssh)
|
||||||
|
if [ -z "${GNUPGHOME:-}" ]; then
|
||||||
|
pdirs+=(.gnupg)
|
||||||
|
else
|
||||||
|
pdirs+=("$(relative_path "$YADM_WORK" "$GNUPGHOME")")
|
||||||
|
fi
|
||||||
|
if [ "$fetch" = "all" ]; then
|
||||||
|
echo "${pdirs[@]}"
|
||||||
|
else
|
||||||
|
echo "${pdirs[1]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function assert_private_dirs() {
|
function assert_private_dirs() {
|
||||||
for private_dir in "$@"; do
|
for private_dir in "$@"; do
|
||||||
if [ ! -d "$YADM_WORK/$private_dir" ]; then
|
if [ ! -d "$YADM_WORK/$private_dir" ]; then
|
||||||
|
@ -1592,7 +1610,7 @@ function assert_parent() {
|
||||||
|
|
||||||
function display_private_perms() {
|
function display_private_perms() {
|
||||||
when="$1"
|
when="$1"
|
||||||
for private_dir in .ssh .gnupg; do
|
for private_dir in $(private_dirs all); do
|
||||||
if [ -d "$YADM_WORK/$private_dir" ]; then
|
if [ -d "$YADM_WORK/$private_dir" ]; then
|
||||||
private_perms=$(ls -ld "$YADM_WORK/$private_dir")
|
private_perms=$(ls -ld "$YADM_WORK/$private_dir")
|
||||||
debug "$when" private dir perms "$private_perms"
|
debug "$when" private dir perms "$private_perms"
|
||||||
|
|
Loading…
Reference in a new issue