Move logic around assert_private_dirs to be more efficient

This commit is contained in:
Tim Byrne 2019-12-12 08:09:00 -06:00
parent 46105aae47
commit cc1993dc14
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
1 changed files with 17 additions and 14 deletions

31
yadm
View File

@ -732,14 +732,18 @@ function clone() {
rm -rf "$YADM_REPO" rm -rf "$YADM_REPO"
error_out "Clone failed, 'origin/${branch}' does not exist in ${clone_args[0]}" error_out "Clone failed, 'origin/${branch}' does not exist in ${clone_args[0]}"
} }
debug "Determining if repo tracks private directories"
for private_dir in .ssh/ .gnupg/; do if [ "$YADM_WORK" = "$HOME" ]; then
found_log=$("$GIT_PROGRAM" log -n 1 "origin/${branch}" -- "$private_dir" 2>/dev/null) debug "Determining if repo tracks private directories"
if [ -n "$found_log" ]; then for private_dir in .ssh/ .gnupg/; do
debug "Private directory $private_dir is tracked by repo" found_log=$("$GIT_PROGRAM" log -n 1 "origin/${branch}" -- "$private_dir" 2>/dev/null)
assert_private_dirs "$private_dir" if [ -n "$found_log" ]; then
fi debug "Private directory $private_dir is tracked by repo"
done assert_private_dirs "$private_dir"
fi
done
fi
[ -n "$DEBUG" ] && display_private_perms "pre-merge" [ -n "$DEBUG" ] && display_private_perms "pre-merge"
debug "Doing an initial merge of origin/${branch}" debug "Doing an initial merge of origin/${branch}"
"$GIT_PROGRAM" merge "origin/${branch}" || { "$GIT_PROGRAM" merge "origin/${branch}" || {
@ -940,9 +944,11 @@ function git_command() {
# ensure private .ssh and .gnupg directories exist first # ensure private .ssh and .gnupg directories exist first
# TODO: consider restricting this to only commands which modify the work-tree # TODO: consider restricting this to only commands which modify the work-tree
auto_private_dirs=$(config --bool yadm.auto-private-dirs) if [ "$YADM_WORK" = "$HOME" ]; then
if [ "$auto_private_dirs" != "false" ] ; then auto_private_dirs=$(config --bool yadm.auto-private-dirs)
assert_private_dirs .gnupg/ .ssh/ if [ "$auto_private_dirs" != "false" ] ; then
assert_private_dirs .gnupg/ .ssh/
fi
fi fi
CHANGES_POSSIBLE=1 CHANGES_POSSIBLE=1
@ -1567,9 +1573,6 @@ function invoke_hook() {
} }
function assert_private_dirs() { function assert_private_dirs() {
# only assert private dirs if the worktree is the same as $HOME
[ "$YADM_WORK" != "$HOME" ] && return
for private_dir in "$@"; do for private_dir in "$@"; do
if [ ! -d "$YADM_WORK/$private_dir" ]; then if [ ! -d "$YADM_WORK/$private_dir" ]; then
debug "Creating $YADM_WORK/$private_dir" debug "Creating $YADM_WORK/$private_dir"