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

Resolving issue #13, #18 and #25 #24

Merged
merged 4 commits into from
Jun 26, 2023
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
12 changes: 6 additions & 6 deletions lib/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let cmd_clear =
Command.basic
~summary:"Clear all local changes without the ability to recover"
(let%map_open.Command force =
flag "f" no_arg ~doc:"Clear forcefully without asking any questions"
flag "f" ~aliases:[ "--force" ] no_arg
~doc:"Clear forcefully without asking any questions"
in
fun () -> Git.clear (to_force_flag force))

Expand All @@ -40,7 +41,8 @@ let cmd_new =
let cmd_push =
Command.basic ~summary:"Push the current branch to origin"
(let%map_open.Command force =
flag "f" no_arg ~doc:"Push forcefully and override changes"
flag "f" ~aliases:[ "--force" ] no_arg
~doc:"Push forcefully and override changes"
in
fun () -> Git.push (to_force_flag force))

Expand All @@ -63,15 +65,13 @@ let cmd_status =

let cmd_switch =
Command.basic ~summary:"Switch to [branch] and sync it with origin"
(let%map_open.Command branch =
anon (maybe_with_default "main" ("branch" %: string))
in
(let%map_open.Command branch = anon (maybe ("branch" %: string)) in
fun () -> Git.switch branch)

let cmd_sync =
Command.basic ~summary:"Sync local branch with the remote branch"
(let%map_open.Command force =
flag "f" no_arg
flag "f" ~aliases:[ "--force" ] no_arg
~doc:
"Sync forcefully by overriding local version with the remote one \
instead of rebasing"
Expand Down
3 changes: 2 additions & 1 deletion lib/git.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ let stash msg_opt =

let status = Status.status

let switch branch =
let switch branch_opt =
let branch = branch_or_main branch_opt in
Process.proc @@ Printf.sprintf "git checkout %s" branch;
Process.proc "git pull --ff-only --prune"

Expand Down
2 changes: 1 addition & 1 deletion lib/git.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ val stash : string option -> unit
val status : string -> unit
(** Show pretty status of local changes. *)

val switch : string -> unit
val switch : string option -> unit
(** Switch to a new branch and update to the latest version of origin. *)

val sync : force_flag -> unit
Expand Down
10 changes: 8 additions & 2 deletions lib/status.ml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ let expand_renamed_paths (left : string) (right : string) : string =
let append_path (p1 : string) (p2 : string) =
if String.is_empty p1 then p2
else if String.is_empty p2 then p1
else if Char.( = ) p1.[String.length p1 - 1] '/' && Caml.( == ) p2.[0] '/'
else if Char.( = ) p1.[String.length p1 - 1] '/' && Stdlib.( == ) p2.[0] '/'
then p1 ^ String.drop_prefix p2 1
else p1 ^ p2
in
Expand Down Expand Up @@ -283,10 +283,16 @@ let parse_diff_details (stat_line : string) : diff_details option =
1 file changed, 5 insertions(+), 6 deletions(-)
```
*)

let get_git_base_dir =
Process.proc_stdout "git rev-parse --show-toplevel"
|> String.rstrip ~drop:(fun c -> Char.( = ) c '\n')

let get_file_diff_stat ~(commit : string) ~(file : string) : diff_details =
let diff_stat =
Process.proc_stdout
@@ Printf.sprintf "git diff %s --stat --color=never -- %s" commit file
@@ Printf.sprintf "git diff %s --stat --color=never -- %s" commit
(get_git_base_dir ^ "/" ^ file)
in
match String.split_lines diff_stat with
| stat_line :: _ ->
Expand Down