Skip to content

Commit

Permalink
refactor: use git2 for branch status
Browse files Browse the repository at this point in the history
  • Loading branch information
altsem committed Feb 25, 2024
1 parent b71b52d commit 397de26
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 434 deletions.
118 changes: 0 additions & 118 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ git2 = "0.18.2"
insta = "1.35.1"
itertools = "0.12.0"
lazy_static = "1.4.0"
pest = "2.7.6"
pest_derive = "2.7.6"
ratatui = "0.26.1"
similar = { version = "2.4.0", features = ["unicode"] }
23 changes: 1 addition & 22 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ use self::{
};
use crate::{git2_opts, Res};
use std::{
error::Error,
fs,
io::ErrorKind,
path::Path,
process::Command,
str::{self, FromStr},
str::{self},
};

pub(crate) mod commit;
pub(crate) mod diff;
pub(crate) mod merge_status;
mod parse;
pub(crate) mod rebase_status;
pub(crate) mod remote;
pub(crate) mod status;

// TODO Check for.git/index.lock and block if it exists
// TODO Use only plumbing commands
Expand Down Expand Up @@ -176,10 +173,6 @@ pub(crate) fn diff_staged(repo: &Repository) -> Res<Diff> {
convert_diff(diff)
}

pub(crate) fn status(dir: &Path) -> Res<status::Status> {
run_git(dir, &["status", "--porcelain", "--branch"], &[])
}

pub(crate) fn show(repo: &Repository, reference: &str) -> Res<Diff> {
let object = &repo.revparse_single(reference)?;

Expand Down Expand Up @@ -318,20 +311,6 @@ pub(crate) fn checkout_ref_cmd(reference: &str) -> Command {
git(&["checkout", reference])
}

fn run_git<T: FromStr<Err = Box<dyn Error>>>(
dir: &Path,
args: &[&str],
meta_args: &[&str],
) -> Res<T> {
let out = Command::new("git")
.args(&[args, meta_args].concat())
.current_dir(dir)
.output()?
.stdout;

str::from_utf8(&out)?.parse()
}

fn git(args: &[&str]) -> Command {
let mut cmd = Command::new("git");
cmd.args(args);
Expand Down
1 change: 0 additions & 1 deletion src/git/parse/mod.rs

This file was deleted.

Loading

0 comments on commit 397de26

Please sign in to comment.