From: Sergey Matveev Date: Fri, 12 Dec 2025 14:22:26 +0000 (+0300) Subject: More understandable error message if target already exists X-Git-Tag: v2.7.0~1 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2be4ecc92413b65324bbf0eb28d4d80e86924749;p=goredo.git More understandable error message if target already exists --- diff --git a/run.go b/run.go index 8a6e40c..7982581 100644 --- a/run.go +++ b/run.go @@ -298,6 +298,19 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { }() return nil } + if inodePrev == nil && FileExists(tgt.a) { + lockRelease() + if StopIfMod { + return fmt.Errorf("%s already existing", tgt) + } + Jobs.Add(1) + tracef(CWarn, "%s already existing: not redoing", tgt) + go func() { + errs <- nil + Jobs.Done() + }() + return nil + } dep = nil // Start preparing .dep diff --git a/t/goredo-$1-touch.t b/t/goredo-$1-touch.t index ae2e775..7657f6b 100755 --- a/t/goredo-$1-touch.t +++ b/t/goredo-$1-touch.t @@ -5,6 +5,7 @@ test_description="Check failing if unexistent \$1 is touched" export REDO_TOP_DIR="`pwd`" REDO_NO_PROGRESS=1 echo touch \$1 >foo.do -test_expect_success "it fails" 'redo foo ; [ $? = 1 ]' +test_expect_success "it fails" 'redo foo 2>out ; [ $? = 1 ]' +test_expect_success "message" 'grep -q "touched" out' test_done diff --git a/t/goredo-already-existing.t b/t/goredo-already-existing.t new file mode 100755 index 0000000..7ef2518 --- /dev/null +++ b/t/goredo-already-existing.t @@ -0,0 +1,24 @@ +#!/bin/sh + +test_description="Check failing if \$1 already exists" +. $SHARNESS_TEST_SRCDIR/sharness.sh +export REDO_TOP_DIR="`pwd`" REDO_NO_PROGRESS=1 + +echo echo ok >foo.do +touch foo +test_expect_success "does not fail" "redo foo 2>out" +test_expect_success "message" 'grep -q "already existing" out' + +export REDO_STOP_IF_MODIFIED=1 +test_expect_success "must fail" 'redo foo 2>out ; [ $? = 1 ]' +unset REDO_STOP_IF_MODIFIED +test_expect_success "message" 'grep -q "already existing" out' + +rm foo +test_expect_success "ok" "redo foo" + +echo overwrite >foo +test_expect_success "externally modified" "redo foo 2>out" +test_expect_success "message" 'grep -q "externally modified" out' + +test_done