Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --keep-git-dir flag to the pull command. #160

Merged
merged 7 commits into from
Oct 19, 2021
Merged
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 CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Add a depext subcommand to install the external system dependencies listed
in lock file (#207, @samoht)
- Add the `--keep-git-dir` flag to the `pull` command that can be used to keep
the [.git] directory after pulling the vendored sources. (#160, @rizo)

### Changed

Expand Down
9 changes: 9 additions & 0 deletions cli/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ module Arg = struct
let non_empty_list_opt =
Cmdliner.Term.pure (function [] -> None | l -> Some l)

let keep_git_dir =
let doc =
"Keep the `.git' directory if the pulled vendored source is a git \
repository."
in
named
(fun x -> `Keep_git_dir x)
Cmdliner.Arg.(value & flag & info [ "keep-git-dir" ] ~doc)

let duniverse_repos =
let open Cmdliner in
let docv = "REPOSITORIES" in
Expand Down
3 changes: 3 additions & 0 deletions cli/common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ module Arg : sig
(** CLI arguments consisting of the list of source deps repo to process. If [None],
the whole duniverse should be processed. If [Some l] then [l] is non empty. *)

val keep_git_dir : [ `Keep_git_dir of bool ] Cmdliner.Term.t
(** CLI flag to keep the [.git] directory after pulling the vendored sources. *)

val setup_logs : unit -> unit Cmdliner.Term.t
(** Adds the common options -v and --version and sets up the logs before being passed as [()] to a
command. *)
Expand Down
8 changes: 5 additions & 3 deletions cli/pull.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let check_dune_lang_version ~yes ~repo =
Ok ())

let run (`Yes yes) (`Repo repo) (`Lockfile explicit_lockfile)
(`Duniverse_repos duniverse_repos) () =
(`Keep_git_dir keep_git_dir) (`Duniverse_repos duniverse_repos) () =
let open Result.O in
Common.find_lockfile ~explicit_lockfile repo >>= fun lockfile ->
Lockfile.to_duniverse lockfile >>= function
Expand All @@ -64,7 +64,8 @@ let run (`Yes yes) (`Repo repo) (`Lockfile explicit_lockfile)
>>= fun duniverse ->
check_dune_lang_version ~yes ~repo >>= fun () ->
OpamGlobalState.with_ `Lock_none (fun global_state ->
Pull.duniverse ~global_state ~repo ~full duniverse)
Pull.duniverse ~global_state ~repo ~full
~trim_clone:(not keep_git_dir) duniverse)

let info =
let open Cmdliner in
Expand All @@ -90,6 +91,7 @@ let term =
Cmdliner.Term.(
term_result
(const run $ Common.Arg.yes $ Common.Arg.repo $ Common.Arg.lockfile
$ Common.Arg.duniverse_repos $ Common.Arg.setup_logs ()))
$ Common.Arg.keep_git_dir $ Common.Arg.duniverse_repos
$ Common.Arg.setup_logs ()))

let cmd = (term, info)
5 changes: 2 additions & 3 deletions lib/pull.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ let pre_pull_clean_up ~full ~duniverse_dir duniverse =
Bos.OS.Dir.delete ~must_exist:false ~recurse:true
Fpath.(duniverse_dir / dir))

let duniverse ~full ~repo ~global_state duniverse =
let duniverse ~full ~repo ~global_state ~trim_clone duniverse =
if List.is_empty duniverse then Ok ()
else
let open Result.O in
let duniverse_dir = Fpath.(repo // Config.vendor_dir) in
pre_pull_clean_up ~full ~duniverse_dir duniverse >>= fun () ->
Bos.OS.Dir.create duniverse_dir >>= fun _created ->
mark_duniverse_content_as_vendored ~duniverse_dir >>= fun () ->
pull_source_dependencies ~global_state ~trim_clone:true ~duniverse_dir
duniverse
pull_source_dependencies ~global_state ~trim_clone ~duniverse_dir duniverse
1 change: 1 addition & 0 deletions lib/pull.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ val duniverse :
full:bool ->
repo:Fpath.t ->
global_state:OpamStateTypes.unlocked OpamStateTypes.global_state ->
trim_clone:bool ->
Duniverse.t ->
(unit, [> Rresult.R.msg ]) result
(** [duniverse ~full ~repo ~global_state duniverse]
Expand Down