Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/fixed/12615.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix a bug where dune was unable to promote over non-existant files in certain
cases (#12615, fixes #8075, @Alizter)
8 changes: 6 additions & 2 deletions src/promote/print_diff.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ let resolve_link_for_git path =
"Unable to resolve symlink %s. Max recursion depth exceeded"
(Path.to_string path)
]
| Error (Unix_error _) ->
User_error.raise [ Pp.textf "Unable to resolve symlink %s" (Path.to_string path) ]
| Error (Unix_error (ENOENT, _, _)) -> path
| Error (Unix_error err) ->
User_error.raise
[ Pp.textf "Unable to resolve symlink %s" (Path.to_string path)
; Unix_error.Detailed.pp err
]
;;

module Diff = struct
Expand Down
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/promote/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(cram
(applies_to symlink-to-nonexistent)
(deps %{bin:git} ../git-helpers.sh))
44 changes: 44 additions & 0 deletions test/blackbox-tests/test-cases/promote/symlink-to-nonexistent.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Tests for promoting with symlink to non-existent file.

$ cat > dune-project <<EOF
> (lang dune 3.21)
> EOF
$ cp dune-project dune-workspace

$ cat > dune <<EOF
> (rule
> (with-stdout-to "x.gen"
> (echo "toto")))
> (rule
> (alias bench)
> (action
> (diff promoted x.gen)))
> EOF

Unset INSIDE_DUNE in order to choose the "git diff" diff algorithm. Root
detection will now be automatic so a dune-workspace file was included above.
$ unset INSIDE_DUNE

The "git diff" command that dune will run will unfortunately go looking for a
`.git` root. We therefore initialise a git repo to avoid this from escaping the
test.
$ . ../git-helpers.sh
$ git init -q

This should fail initially but not with the "Unable to resolve symlink" error.
$ dune build @bench
File "promoted", line 1, characters 0-0:
------ /dev/null
++++++ x.gen
File "/dev/null", line 1, characters 0-1:
+|toto
No newline at the end of x.gen
[1]

Promotion should work
$ dune promote
Promoting _build/default/x.gen to promoted.

$ cat promoted
toto

Loading