Skip to content

Commit 20d2580

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 cdcf09e commit 20d2580

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
@@ -27,12 +27,12 @@ test.
2727

2828
This should fail initially but not with the "Unable to resolve symlink" error.
2929
$ dune build @bench
30-
File "dune", lines 4-7, characters 0-55:
31-
4 | (rule
32-
5 | (alias bench)
33-
6 | (action
34-
7 | (diff promoted x.gen)))
35-
Error: Unable to resolve symlink _build/default/promoted
30+
File "promoted", line 1, characters 0-0:
31+
------ /dev/null
32+
++++++ x.gen
33+
File "/dev/null", line 1, characters 0-1:
34+
+|toto
35+
No newline at the end of x.gen
3636
[1]
3737

3838
Promotion should work

0 commit comments

Comments
 (0)