GitBaby/src/merge/helper.rs
zhenyi 680411c4fb chore: initialize gitbaby repository
gitbaby is an asynchronous Rust library wrapping git operations, built on
gix + tokio + async-trait.

Module layout:
- archive, blame, blob, branch, cleanup, commit, compare, config,
  conflict, diff, merge, refs, remote, setup, share, submodule, tags,
  tree (feature modules)
- command: command scheduler (cmd/env/pipe/context/error)
- repo: RepositoryFacade trait (consumers implement, exposing a
  gix::Repository)

Features:
- async API on tokio 1.53
- order-preserving Env (Vec<(String, String)>)
- hand-written BabyError / CmdError, not using thiserror derive
- integration tests covering cmd_run / context / env / pipe (env keys
  prefixed for isolation)

CI: none, standard cargo build / test / clippy / fmt only
2026-08-14 18:10:04 +08:00

33 lines
1.1 KiB
Rust

use std::path::Path;
use crate::command::cmd::Cmd;
use crate::command::env::Env;
use crate::command::error::CmdError;
use crate::error::BabyError;
use crate::share;
pub const CALLER: &str = "gitbaby::merge";
pub fn build_merge_base_cmd(dir: &Path, env: Env, one: &str, two: &str) -> Cmd {
let args: Vec<String> = vec!["merge-base".into(), one.into(), two.into()];
share::git_cmd(CALLER, dir, env, None, args)
}
pub fn classify_stderr(stderr: &str, one: &str, two: &str) -> BabyError {
if stderr.trim().is_empty() {
return BabyError::MergeBaseNotFound(format!("{}..{}", one, two));
}
if stderr.contains("fatal: bad revision") {
return BabyError::RevisionNotFound(format!("{}..{}", one, two));
}
BabyError::Custom(format!("git merge-base failed: {}", stderr.trim()))
}
pub fn classify_cmd_error(err: CmdError, one: &str, two: &str) -> BabyError {
match err {
CmdError::NonZeroExit { stderr, .. } => classify_stderr(&stderr, one, two),
CmdError::Spawn { prog, source } => share::classify_spawn_error(prog, source),
other => BabyError::from(other),
}
}