From c4a60a7dfbf2d53f572397c9507ee09fae7d9cd4 Mon Sep 17 00:00:00 2001 From: James Ottaway Date: Sat, 25 Apr 2020 12:50:19 +1000 Subject: [PATCH] Fix how `vcs_relative_path` first resolves an absolute path --- bin/_blackbox_common.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index b935f5d8..ae1d78b2 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -366,13 +366,21 @@ function enumerate_blackbox_repos() { done } +# Resolve the absolute path of a relative one +function abs() { + local _pwd bn + [ -d "${1}" ] && _pwd="${1}" + [ -f "${1}" ] && { _pwd=$(dirname "${1}") ; bn=/$(basename "${1}") ;} + pushd "$_pwd" >/dev/null || exit + echo "$(pwd)${bn}" + popd >/dev/null || exit +} + # Output the path of a file relative to the repo base function vcs_relative_path() { - # Usage: vcs_relative_path file - local name="$1" - #python -c 'import os ; print(os.path.relpath("'"$(pwd -P)"'/'"$name"'", "'"$REPOBASE"'"))' - local p=$( printf "%s" "$( pwd -P )/${1}" | sed 's#//*#/#g' ) - local name="${p#$REPOBASE}" + local name + name=$(abs "$1") + name="${name#$REPOBASE}" name=$( printf "%s" "$name" | sed 's#^/##g' | sed 's#/$##g' ) printf "%s" "$name" }