mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 11:42:33 +01:00
Fix abs_dirname
There are no tests for this unfortunately and it is copied into two places. Ref: https://github.com/rbenv/rbenv/pull/868
This commit is contained in:
parent
03608115df
commit
87ae363144
19
install.sh
19
install.sh
|
@ -6,17 +6,22 @@ resolve_link() {
|
||||||
}
|
}
|
||||||
|
|
||||||
abs_dirname() {
|
abs_dirname() {
|
||||||
local cwd="$(pwd)"
|
|
||||||
local path="$1"
|
local path="$1"
|
||||||
|
local save_cwd="$PWD"
|
||||||
|
local dir name
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
while [[ -n "$path" ]]; do
|
||||||
cd "${path%/*}"
|
dir="${path%/*}"
|
||||||
local name="${path##*/}"
|
if [[ "$dir" != "$path" ]]; then
|
||||||
|
cd "$dir"
|
||||||
|
name="${path##*/}"
|
||||||
|
else
|
||||||
|
name="$path"
|
||||||
|
fi
|
||||||
path="$(resolve_link "$name" || true)"
|
path="$(resolve_link "$name" || true)"
|
||||||
done
|
done
|
||||||
|
echo "$PWD"
|
||||||
pwd
|
cd "$save_cwd"
|
||||||
cd "$cwd"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PREFIX="$1"
|
PREFIX="$1"
|
||||||
|
|
19
libexec/bats
19
libexec/bats
|
@ -31,17 +31,22 @@ resolve_link() {
|
||||||
}
|
}
|
||||||
|
|
||||||
abs_dirname() {
|
abs_dirname() {
|
||||||
local cwd="$(pwd)"
|
|
||||||
local path="$1"
|
local path="$1"
|
||||||
|
local save_cwd="$PWD"
|
||||||
|
local dir name
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
while [[ -n "$path" ]]; do
|
||||||
cd "${path%/*}"
|
dir="${path%/*}"
|
||||||
local name="${path##*/}"
|
if [[ "$dir" != "$path" ]]; then
|
||||||
|
cd "$dir"
|
||||||
|
name="${path##*/}"
|
||||||
|
else
|
||||||
|
name="$path"
|
||||||
|
fi
|
||||||
path="$(resolve_link "$name" || true)"
|
path="$(resolve_link "$name" || true)"
|
||||||
done
|
done
|
||||||
|
echo "$PWD"
|
||||||
pwd
|
cd "$save_cwd"
|
||||||
cd "$cwd"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_path() {
|
expand_path() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user