@@ -61,6 +61,7 @@ PROC_VERSION="/proc/version"
6161OPERATING_SYSTEM=" Unknown"
6262
6363ENCRYPT_INCLUDE_FILES=" unparsed"
64+ NO_ENCRYPT_TRACKED_FILES=()
6465
6566LEGACY_WARNING_ISSUED=0
6667INVALID_ALT=()
@@ -1042,6 +1043,12 @@ function encrypt() {
10421043 printf ' %s\n' " ${ENCRYPT_INCLUDE_FILES[@]} "
10431044 echo
10441045
1046+ if [ ${# NO_ENCRYPT_TRACKED_FILES[@]} -gt 0 ]; then
1047+ echo " Warning: The following files are tracked and will NOT be encrypted:"
1048+ printf ' %s\n' " ${NO_ENCRYPT_TRACKED_FILES[@]} "
1049+ echo
1050+ fi
1051+
10451052 # encrypt all files which match the globs
10461053 if tar -f - -c " ${ENCRYPT_INCLUDE_FILES[@]} " | _encrypt_to " $YADM_ARCHIVE " ; then
10471054 echo " Wrote new file: $YADM_ARCHIVE "
@@ -1468,38 +1475,59 @@ function version() {
14681475
14691476function exclude_encrypted() {
14701477
1478+ local auto_exclude
14711479 auto_exclude=$( config --bool yadm.auto-exclude)
14721480 [ " $auto_exclude " == " false" ] && return 0
14731481
1474- exclude_path=" ${YADM_REPO} /info/exclude"
1475- newline=$' \n '
1476- exclude_flag=" # yadm-auto-excludes"
1477- exclude_header=" ${exclude_flag}${newline} "
1482+ # do nothing if there is no YADM_ENCRYPT
1483+ [ -e " $YADM_ENCRYPT " ] || return 0
1484+
1485+ readonly exclude_path=" ${YADM_REPO} /info/exclude"
1486+ readonly newline=$' \n '
1487+ readonly exclude_flag=" # yadm-auto-excludes"
1488+
1489+ local exclude_header=" ${exclude_flag}${newline} "
14781490 exclude_header=" ${exclude_header} # This section is managed by yadm."
14791491 exclude_header=" ${exclude_header}${newline} "
14801492 exclude_header=" ${exclude_header} # Any edits below will be lost."
14811493 exclude_header=" ${exclude_header}${newline} "
14821494
1483- # do nothing if there is no YADM_ENCRYPT
1484- [ -e " $YADM_ENCRYPT " ] || return 0
1485-
14861495 # read encrypt
1487- encrypt_data=" "
1488- while IFS=' ' read -r line || [ -n " $line " ]; do
1489- encrypt_data=" ${encrypt_data}${line}${newline} "
1496+ local encrypt_data=" "
1497+ local pattern
1498+ while IFS=' ' read -r pattern || [ -n " $pattern " ]; do
1499+ case ${pattern: 0: 1} in
1500+ \# )
1501+ pattern=" "
1502+ ;;
1503+ !)
1504+ # Prepend / to the pattern so that it matches the same files as in
1505+ # parse_encrypt (i.e. only from the root)
1506+ pattern=" !/${pattern: 1} $newline "
1507+ ;;
1508+ * )
1509+ if ! [[ $pattern =~ ^[[:blank:]]* (# |$) ]]; then
1510+ pattern=" /$pattern$newline "
1511+ else
1512+ pattern=" "
1513+ fi
1514+ ;;
1515+ esac
1516+ encrypt_data=" ${encrypt_data}${pattern} "
14901517 done < " $YADM_ENCRYPT "
14911518
14921519 # read info/exclude
1493- unmanaged=" "
1494- managed=" "
1520+ local unmanaged=" "
1521+ local managed=" "
14951522 if [ -e " $exclude_path " ]; then
1496- flag_seen=0
1523+ local -i flag_seen=0
1524+ local line
14971525 while IFS=' ' read -r line || [ -n " $line " ]; do
14981526 [ " $line " = " $exclude_flag " ] && flag_seen=1
1499- if [ " $flag_seen " -eq 0 ]; then
1500- unmanaged=" ${unmanaged}${line}${newline} "
1501- else
1527+ if (( flag_seen)) ; then
15021528 managed=" ${managed}${line}${newline} "
1529+ else
1530+ unmanaged=" ${unmanaged}${line}${newline} "
15031531 fi
15041532 done < " $exclude_path "
15051533 fi
@@ -1926,26 +1954,44 @@ function parse_encrypt() {
19261954 local -a exclude
19271955 local -a include
19281956
1929- while IFS= read -r pattern; do
1930- case $pattern in
1931- \# * )
1957+ local pattern
1958+ while IFS=' ' read -r pattern || [ -n " $pattern " ]; do
1959+ case ${pattern: 0: 1} in
1960+ \# )
19321961 # Ignore comments
19331962 ;;
1934- !* )
1935- exclude+=(" --exclude=${pattern: 1} " )
1963+ !)
1964+ exclude+=(" --exclude=/ ${pattern: 1} " )
19361965 ;;
19371966 * )
1938- if ! [[ $pattern =~ ^[[:blank:]]* $ ]]; then
1967+ if ! [[ $pattern =~ ^[[:blank:]]* ( # |$) ]]; then
19391968 include+=(" $pattern " )
19401969 fi
19411970 ;;
19421971 esac
19431972 done < " $YADM_ENCRYPT "
19441973
1945- if [[ ${# include} -gt 0 ]]; then
1946- while IFS= read -r filename; do
1947- ENCRYPT_INCLUDE_FILES+=(" ${filename%/ } " )
1948- done <<< " $(" $GIT_PROGRAM " ls-files --others " ${exclude[@]} " -- " ${include[@]} " )"
1974+ if [ ${# include[@]} -gt 0 ]; then
1975+ while IFS=' ' read -r filename; do
1976+ if [ -n " $filename " ]; then
1977+ ENCRYPT_INCLUDE_FILES+=(" ${filename%/ } " )
1978+ fi
1979+ done <<< " $(
1980+ " $GIT_PROGRAM " --glob-pathspecs ls-files --others \
1981+ " ${exclude[@]} " -- " ${include[@]} " 2>/dev/null
1982+ )"
1983+
1984+ [ " $YADM_COMMAND " = " encrypt" ] || return
1985+
1986+ # List files that matches encryption pattern but is tracked
1987+ while IFS=' ' read -r filename; do
1988+ if [ -n " $filename " ]; then
1989+ NO_ENCRYPT_TRACKED_FILES+=(" ${filename%/ } " )
1990+ fi
1991+ done <<< " $(
1992+ " $GIT_PROGRAM " --glob-pathspecs ls-files \
1993+ " ${exclude[@]} " -- " ${include[@]} "
1994+ )"
19491995 fi
19501996}
19511997
0 commit comments