do.go | 2 +- doc/news.texi | 7 +++++++ main.go | 14 +++++++++++--- t/apenwarr/260-whichdo/all.do | 1 + t/apenwarr/260-whichdo/default.y.z.do | 1 + t/apenwarr/260-whichdo/defaults.do | 16 ++++++++++++++++ t/apenwarr/260-whichdo/exists.do | 25 +++++++++++++++++++++++++ t/apenwarr/260-whichdo/fakesub2/default.do | 1 + t/apenwarr/260-whichdo/fakesub2/snork.do | 1 + t/apenwarr/260-whichdo/nonexists.do | 45 +++++++++++++++++++++++++++++++++++++++++++++ t/apenwarr/README | 4 ++-- t/apewarr-260-whichdo | 1 + usage.go | 2 +- diff --git a/do.go b/do.go index 76d2b4f1d2927ea19f936c41a9ec0be548fa329eead4a34ff82b61e0897e4e29..2bf7a65ff5f637746424132195d90bf971090e16f09f21771ff3e94a358f65bf 100644 --- a/do.go +++ b/do.go @@ -82,7 +82,7 @@ return doFile, len(levels), nil } } levels = append(levels, "..") - dirAbs, err := filepath.Abs(updir) + dirAbs, err := filepath.Abs(path.Join(cwd, updir)) if err != nil { panic(err) } diff --git a/doc/news.texi b/doc/news.texi index c5e171ab832c5669f123c6662719d3cf06d0978840ed8cd79b0e6391004671dd..d03b05282e371a8f87bf6e1fe0a52283cee63730089685667ad0217535af7ee0 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -1,6 +1,13 @@ @node News @unnumbered News +@anchor{Release 0.13.0} +@section Release 0.13.0 +@itemize +@item + @command{redo-whichdo} resembles @code{apenwarr/redo}'s one behaviour more. +@end itemize + @anchor{Release 0.12.3} @section Release 0.12.3 @itemize diff --git a/main.go b/main.go index 9067dc05319185aa6a016b434cfcc2008a1ae4414a3acefd96f56df87c509add..6f966d760a652c37d7fd9690342e7f98b15b73ccc850a82d4edc0ca07b2b53de 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,6 @@ "os" "path" "path/filepath" "strconv" - "strings" "go.cypherpunks.ru/recfile" ) @@ -270,7 +269,6 @@ break } os.Remove(fdTmp.Name()) cwd, tgt := cwdAndTgt(tgts[0]) - cwdRel := cwdMustRel(cwd) doFile, upLevels, err := findDo(fdTmp, cwd, tgt) if err != nil { break @@ -293,7 +291,17 @@ } if doFile == "" { ok = false } else { - fmt.Println(path.Join(cwdRel, strings.Repeat("..", upLevels), doFile)) + p := make([]string, 0, upLevels+2) + p = append(p, cwd) + for i := 0; i < upLevels; i++ { + p = append(p, "..") + } + p = append(p, doFile) + rel, err := filepath.Rel(Cwd, path.Join(p...)) + if err != nil { + panic(err) + } + fmt.Println(rel) } default: log.Fatalln("unknown command", cmdName) diff --git a/t/apenwarr/260-whichdo/all.do b/t/apenwarr/260-whichdo/all.do new file mode 100644 index 0000000000000000000000000000000000000000..0fd3c0e92308955e8224b516a8adfc1e12fa066e26d74c5b043794336ca54065 --- /dev/null +++ b/t/apenwarr/260-whichdo/all.do @@ -0,0 +1 @@ +redo exists nonexists defaults diff --git a/t/apenwarr/260-whichdo/default.y.z.do b/t/apenwarr/260-whichdo/default.y.z.do new file mode 100644 index 0000000000000000000000000000000000000000..7d8fbe2f2deced3d75efa61b485567e96e62e90ffcd407060c00e884468f13e5 --- /dev/null +++ b/t/apenwarr/260-whichdo/default.y.z.do @@ -0,0 +1 @@ +: diff --git a/t/apenwarr/260-whichdo/defaults.do b/t/apenwarr/260-whichdo/defaults.do new file mode 100644 index 0000000000000000000000000000000000000000..aaa4cc9cbe0f13927f18564303bb363fe7efa14a07e52098207788e7001c1641 --- /dev/null +++ b/t/apenwarr/260-whichdo/defaults.do @@ -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 <&2 + +a=$(cd fakesub && redo-whichdo ../a/b/x.y.z) +# if sh doesn't abort after the above, then it found a .do file as expected + +# Note: we expect redo-whichdo to return paths relative to $PWD at the time +# it's run, which in this case is fakesub. +# Likely bugs would be to return paths relative to the start dir, the .redo +# dir, the current target dir, the requested target dir, etc. +b=$(cat <&2 + +# Testing the search path for non-existent do files is a little tricky. +# We can't be sure where our current directory is, so we don't know how +# far up the stack redo will need to search. +# +# To dodge the problem, let's "cd /" first so that we're testing a target +# relative to a known location (the root directory). + +if [ -e '/default.do' -o \ + -e '/default.z.do' -o \ + -e '/default.y.z.do' ]; then + echo "Weird: /default.*.do exists; can't run this test." + exit 99 +fi + +# redo-whichdo *should* fail here, so don't abort the script for that. +set +e +a=$(cd / && redo-whichdo __nonexist/a/x.y.z) +rv=$? +set -e + +if [ "$rv" -eq 0 ]; then + echo "redo-whichdo should return nonzero for a missing .do file." + exit 10 +fi + +b=$(cat <