Skip to content

Commit

Permalink
Better error message for old versions of Git (#11197)
Browse files Browse the repository at this point in the history
* Better error message for old versions of Git

Old versions of git don't support the  flag. This patch detects this particular failure and prints an error message hinting that.

Signed-off-by: Sudha Parimala <[email protected]>

* fix(pkg): print stderr on git errors

instead of discarding the stderr

Signed-off-by: Rudi Grinberg <[email protected]>

---------

Signed-off-by: Sudha Parimala <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Co-authored-by: Rudi Grinberg <[email protected]>
  • Loading branch information
Sudha247 and rgrinberg authored Dec 31, 2024
1 parent 3b9d0fd commit 8bf833a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/dune_pkg/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(libraries
stdune
fiber
fiber_util
chrome_trace
dune_engine
dune_digest
Expand Down
31 changes: 27 additions & 4 deletions src/dune_pkg/rev_store.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,37 @@ end

let run_with_exit_code { dir; _ } ~allow_codes ~display args =
let stdout_to = make_stdout () in
let stderr_to = make_stderr () in
let git = Lazy.force Vcs.git in
let+ (), exit_code =
Process.run ~dir ~display ~stdout_to ~stderr_to ~env failure_mode git args
let+ stderr, exit_code =
Fiber_util.Temp.with_temp_file
~prefix:"dune"
~suffix:"run_with_exit_code"
~dir:(Path.of_string (Filename.get_temp_dir_name ()))
~f:(function
| Error exn -> raise exn
| Ok path ->
let+ (), exit_code =
let stderr_to = Process.Io.file path Out in
Process.run ~dir ~display ~stdout_to ~stderr_to ~env failure_mode git args
in
Io.read_file path, exit_code)
in
if allow_codes exit_code
then Ok exit_code
else Error { Git_error.dir; args; exit_code; output = [] }
else (
match exit_code with
| 129
when String.is_prefix ~prefix:"error: unknown option `no-write-fetch-head'" stderr
->
User_error.raise
[ User_message.command
"Your git version doesn't support the '--no-write-fetch-head' flag. The \
minimum supported version is Git 2.29."
]
~hints:[ User_message.command "Please update your git version." ]
| _ ->
Dune_console.print [ Pp.verbatim stderr ];
Error { Git_error.dir; args; exit_code; output = [] })
;;

let run t ~display args =
Expand Down

0 comments on commit 8bf833a

Please sign in to comment.