]> Cypherpunks repositories - goredo.git/commitdiff
More understandable error message if target already exists
authorSergey Matveev <stargrave@stargrave.org>
Fri, 12 Dec 2025 14:22:26 +0000 (17:22 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 12 Dec 2025 14:29:45 +0000 (17:29 +0300)
run.go
t/goredo-$1-touch.t
t/goredo-already-existing.t [new file with mode: 0755]

diff --git a/run.go b/run.go
index 8a6e40cc34c21d65bb3ee6f66321621f52d401b8..79825816975f9be21eb54ee6097b1308be908fad 100644 (file)
--- 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
index ae2e77548709f750ce62c94165847a5757e950ec..7657f6b2748482e309ebf8c94a72f62e49ea3c96 100755 (executable)
@@ -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 (executable)
index 0000000..7ef2518
--- /dev/null
@@ -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