From fa286f0c9d656fc0fdc979da0f33e3edf3213663 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Fri, 5 Aug 2016 16:09:26 -0500 Subject: [PATCH] Support for symlinked directories (#17) --- yadm | 21 ++++++++++++++------- yadm.1 | 4 ++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/yadm b/yadm index 75d5782..536e64c 100755 --- a/yadm +++ b/yadm @@ -117,16 +117,23 @@ function alt() { #; loop over all "tracked" files #; for every file which matches the above regex, create a symlink + last_linked='' for tracked_file in $(git ls-files | sort); do tracked_file="$YADM_WORK/$tracked_file" - if [ -e "$tracked_file" ] ; then - if [[ $tracked_file =~ $match ]] ; then - new_link="${BASH_REMATCH[1]}" - debug "Linking $tracked_file to $new_link" - [ -n "$loud" ] && echo "Linking $tracked_file to $new_link" - ln -fs "$tracked_file" "$new_link" + #; process both the path, and it's parent directory + for alt_path in "$tracked_file" "${tracked_file%/*}"; do + if [ -e "$alt_path" ] ; then + if [[ $alt_path =~ $match ]] ; then + if [ "$alt_path" != "$last_linked" ] ; then + new_link="${BASH_REMATCH[1]}" + debug "Linking $alt_path to $new_link" + [ -n "$loud" ] && echo "Linking $alt_path to $new_link" + ln -nfs "$alt_path" "$new_link" + last_linked="$alt_path" + fi + fi fi - fi + done done } diff --git a/yadm.1 b/yadm.1 index a8b791d..a23514f 100644 --- a/yadm.1 +++ b/yadm.1 @@ -356,6 +356,10 @@ If running on a Solaris server, the link use the default "##" version: If no "##" version exists and no files match the current OS/HOSTNAME/USER, then no link will be created. +Links are also created for directories named this way, as long as they have at least one +.B yadm +managed file within them. + OS is determined by running .BR uname\ -s , HOSTNAME by running