diff --git a/CHANGES.md b/CHANGES.md index 0fe4bd746ba..ce6fb604786 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -99,6 +99,9 @@ unreleased `.merlin` with `S`-directives pointed to original source locations and thus allowing merlin to see those. +- Improve the behavior of `dune promote` when the files to be promoted have been + deleted. (#1775, fixes #1772, @diml) + - unstable-fmt: preserve comments (#1766, @emillon) 1.6.2 (05/12/2018) diff --git a/src/promotion.ml b/src/promotion.ml index b1e2c5139cc..ab48c166c88 100644 --- a/src/promotion.ml +++ b/src/promotion.ml @@ -19,10 +19,17 @@ module File = struct let register t = db := t :: !db let promote { src; dst } = - Errors.print_to_console (Format.sprintf "Promoting %s to %s.@." - (Path.to_string_maybe_quoted src) - (Path.to_string_maybe_quoted dst)); - Io.copy_file ~src ~dst () + let src_exists = Path.exists src in + Errors.print_to_console + (Format.sprintf + (if src_exists then + "Promoting %s to %s.@." + else + "Skipping promotion of %s to %s as the file is missing.@.") + (Path.to_string_maybe_quoted src) + (Path.to_string_maybe_quoted dst)); + if src_exists then + Io.copy_file ~src ~dst () end let clear_cache () = diff --git a/test/blackbox-tests/test-cases/promote/run.t b/test/blackbox-tests/test-cases/promote/run.t index 3b4f8454eb1..2e9edf46e9e 100644 --- a/test/blackbox-tests/test-cases/promote/run.t +++ b/test/blackbox-tests/test-cases/promote/run.t @@ -74,24 +74,5 @@ Reproduction case for #1772 [1] $ rm -f _build/default/x.gen $ dune promote - Promoting _build/default/x.gen to x. - Error: exception Sys_error("_build/default/x.gen: No such file or directory") - Backtrace: - Raised by primitive operation at file "stdlib.ml", line 390, characters 28-54 - Called from file "src/stdune/io.ml", line 74, characters 17-37 - Called from file "src/promotion.ml", line 86, characters 6-31 - Called from file "map.ml", line 295, characters 20-25 - Called from file "src/promotion.ml", line 93, characters 4-44 - Called from file "src/promotion.ml", line 124, characters 11-41 - Called from file "vendor/cmdliner/src/cmdliner_term.ml", line 25, characters 19-24 - Called from file "vendor/cmdliner/src/cmdliner.ml", line 116, characters 32-39 - Called from file "vendor/cmdliner/src/cmdliner.ml", line 146, characters 18-36 - Called from file "vendor/cmdliner/src/cmdliner.ml", line 261, characters 22-48 - Called from file "bin/main.ml", line 177, characters 10-51 - - I must not segfault. Uncertainty is the mind-killer. Exceptions are - the little-death that brings total obliteration. I will fully express - my cases. Execution will pass over me and through me. And when it - has gone past, I will unwind the stack along its path. Where the - cases are handled there will be nothing. Only I will remain. - [1] + Skipping promotion of _build/default/x.gen to x as the file is missing. + Promoting _build/default/y.gen to y.