Skip to content

Commit 77a862f

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 dfe7a98 commit 77a862f

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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
@@ -21,12 +21,12 @@ detection will now be automatic so a dune-workspace file was included above.
2121

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

3232
Promotion should work

0 commit comments

Comments
 (0)