minimal/do whichdo: should print ../default.do if ../$1.do exists.

It would be incorrect to print ../$1.do (we only use $1.do in the
*current* directly, not prefix dirs; we only use default*.do in
those).  However, when we found ../default.do, we forgot to print it,
because of a silly logic error.
This commit is contained in:
Avery Pennarun 2018-11-02 03:11:38 -04:00
commit a14aa4c86d
5 changed files with 21 additions and 2 deletions

View file

@ -208,10 +208,11 @@ _find_dofiles()
_dirsplit "$dofile" _dirsplit "$dofile"
dodir=$_dirsplit_dir dodir=$_dirsplit_dir
dofile=$_dirsplit_base dofile=$_dirsplit_base
[ -n "$dodir" ] && dodir=${dodir%/}/
[ -e "$dodir$dofile" ] && return 0
for i in $(seq 100); do for i in $(seq 100); do
[ -n "$dodir" ] && dodir=${dodir%/}/ [ -n "$dodir" ] && dodir=${dodir%/}/
#echo "_find_dofiles: '$dodir' '$dofile'" >&2 #echo "_find_dofiles: '$dodir' '$dofile'" >&2
[ -e "$dodir$dofile" ] && return 0
_find_dofiles_pwd "$dodir" "$dofile" && return 0 _find_dofiles_pwd "$dodir" "$dofile" && return 0
newdir=$(_normpath "${dodir}..") newdir=$(_normpath "${dodir}..")
[ "$newdir" = "$dodir" ] && break [ "$newdir" = "$dodir" ] && break

View file

@ -1 +1 @@
redo exists nonexists redo exists nonexists defaults

16
t/260-whichdo/defaults.do Normal file
View file

@ -0,0 +1,16 @@
exec >&2
a=$(cd fakesub2 && redo-whichdo d/snork)
# if sh doesn't abort after the above, then it found a .do file as expected
b=$(cat <<EOF
d/snork.do
d/default.do
default.do
EOF
)
if [ "$a" != "$b" ]; then
printf 'redo-whichdo mismatch.\n\ngot:\n%s\n\nexpected:\n%s\n' "$a" "$b"
exit 11
fi

View file

@ -0,0 +1 @@
:

View file

@ -0,0 +1 @@
: