Skip to content

Commit 94a1947

Browse files
committed
fix: promotion over non-existent file
When we use "git diff" as the git tool, we have some logic to resolve symlinks since "git diff" doesn't handle them. This logic doesn't take into account the case where the target of a symlink doesn't exist, which happens when the file you are promoting doesn't exist yet. This can easily be fixed by taking into account this case. Signed-off-by: Ali Caglayan <[email protected]>
1 parent efe0f89 commit 94a1947

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

doc/changes/fixed/12615.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Fix a bug where dune was unable to promote over non-existant files in certain
2+
cases (#12615, fixes #8075, @Alizter)

src/promote/print_diff.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ let resolve_link_for_git path =
1313
"Unable to resolve symlink %s. Max recursion depth exceeded"
1414
(Path.to_string path)
1515
]
16-
| Error (Unix_error _) ->
17-
User_error.raise [ Pp.textf "Unable to resolve symlink %s" (Path.to_string path) ]
16+
| Error (Unix_error (ENOENT, _, _)) -> path
17+
| Error (Unix_error err) ->
18+
User_error.raise
19+
[ Pp.textf "Unable to resolve symlink %s" (Path.to_string path)
20+
; Unix_error.Detailed.pp err
21+
]
1822
;;
1923

2024
module Diff = struct

test/blackbox-tests/test-cases/promote/symlink-to-nonexistent.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ detection will now be automatic so a dune-workspace file was included above.
2323

2424
This should fail initially but not with the "Unable to resolve symlink" error.
2525
$ dune build @bench
26-
File "dune", lines 4-7, characters 0-55:
27-
4 | (rule
28-
5 | (alias bench)
29-
6 | (action
30-
7 | (diff promoted x.gen)))
31-
Error: Unable to resolve symlink _build/default/promoted
26+
File "promoted", line 1, characters 0-0:
27+
------ /dev/null
28+
++++++ x.gen
29+
File "/dev/null", line 1, characters 0-1:
30+
+|toto
31+
No newline at the end of x.gen
3232
[1]
3333

3434
Promotion should work

0 commit comments

Comments
 (0)