upd: fix bug where realpath could crash

This commit is contained in:
PowerUser64 2025-05-24 15:13:49 -07:00
parent 01bf4de331
commit e535616faf

View file

@ -51,21 +51,16 @@ contains() {
pretty_path() {
arg="$1"
# If the arg starts with our home dir, replace the prefix with a tilde
case "$arg" in
# If the arg starts with our home dir,
"$HOME"*)
# replace the home dir part with a ~
printf '~%s' "$(printf '%s' "$arg" | sed -E 's/^.{'"${#HOME}"'}//')"
arg="~${arg#"$HOME"}"
;;
esac
# Otherwise,
*)
# Just print the arg
printf '%s' "${arg}"
;;
esac | # Pass through some other filters
sed -E 's_/+$__' | # Remove trailing slash
tr -s '/' # Remove duplicate slashes
printf '%s' "$arg" |
tr -s '/' | # Remove duplicate slashes
sed 's+/$++' # Remove trailing slash
}
# Warn about incomplete changes to a repository
@ -101,7 +96,7 @@ do_pull() {
for repo in "$@"; do
if [ -n "$repo" ]; then
repo_pretty="$(pretty_path "$repo")"
repo="$(realpath "$repo" 2>/dev/null)"
repo="$(realpath "$repo" 2>/dev/null || true)"
repo="$(git -C "$repo" rev-parse --show-toplevel 2> /dev/null || true)"
if [ -n "$repo" ]; then
if ! contains "$repo" ':' "$updated"; then
@ -133,7 +128,7 @@ do_pull() {
${did_updates:-false} && echo
echo " Updating ${green}dotfiles${nc}…"
dotfiles pull
do_checks "$(dotfiles rev-parse --git-dir)" dotfiles
do_checks "$(pretty_path "$(dotfiles rev-parse --git-dir)")" dotfiles
fi
}