Skip to content

Commit

Permalink
gitcompat: add call_git to capture output
Browse files Browse the repository at this point in the history
Summary:
This handles some error cases like non-zero exit code with a nicer error
message than the stdlib default.

Reviewed By: muirdm

Differential Revision: D54218742

fbshipit-source-id: afc3747007ce378b9506ba06365088578517e131
  • Loading branch information
quark-zju authored and facebook-github-bot committed Mar 18, 2024
1 parent bc6f7a6 commit e81132e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions eden/scm/lib/gitcompat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ edition = "2021"
configmodel = { version = "0.1.0", path = "../config/model" }
fs-err = { version = "2.6.0", features = ["tokio"] }
identity = { version = "0.1.0", path = "../identity" }
spawn-ext = { version = "0.1.0", path = "../spawn-ext" }
1 change: 1 addition & 0 deletions eden/scm/lib/gitcompat/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ rust_library(
"fbsource//third-party/rust:fs-err",
"//eden/scm/lib/config/model:configmodel",
"//eden/scm/lib/identity:identity",
"//eden/scm/lib/spawn-ext:spawn-ext",
],
)
16 changes: 16 additions & 0 deletions eden/scm/lib/gitcompat/src/rungit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
* GNU General Public License version 2.
*/

use std::io;
use std::path::PathBuf;
use std::process::Command;
use std::process::ExitStatus;
use std::process::Output;

use configmodel::Config;
use configmodel::ConfigExt;
use spawn_ext::CommandExt;

/// Options used by `run_git`.
#[derive(Default, Clone)]
Expand Down Expand Up @@ -57,6 +61,18 @@ impl RunGitOptions {
let args = args.iter().map(ToString::to_string).collect();
git_cmd_impl(cmd_name, args, self)
}

/// Call `git`. Check exit code. Capture output.
pub fn call(&self, cmd_name: &str, args: &[impl ToString]) -> io::Result<Output> {
let mut cmd = self.git_cmd(cmd_name, args);
cmd.checked_output()
}

/// Run `git`. Check exit code.
pub fn run(&self, cmd_name: &str, args: &[impl ToString]) -> io::Result<ExitStatus> {
let mut cmd = self.git_cmd(cmd_name, args);
cmd.checked_run()
}
}

const GIT: &str = "git";
Expand Down

0 comments on commit e81132e

Please sign in to comment.