Skip to main content

Git

Struct Git 

Source
pub struct Git { /* private fields */ }
Expand description

git 调用上下文:锚定仓库根目录,verbose 时回显执行的命令。

Implementations§

Source§

impl Git

Source

pub fn discover(dir: &Path, verbose: bool) -> Result<Self, GitError>

从指定目录探测 git 仓库根并构造上下文。

Source

pub fn top(&self) -> &Path

仓库根目录。

Source

pub fn run(&self, args: &[&str]) -> Result<Output, GitError>

执行 git 命令并捕获输出(不检查退出码,交给调用方判断)。

Source

pub fn run_ok(&self, args: &[&str]) -> Result<Output, GitError>

执行 git 命令,非零退出码视为错误。

Source

pub fn run_inherit(&self, args: &[&str]) -> Result<ExitStatus, GitError>

以透传模式执行 git:输出直接接到用户终端, 用于发起 merge / rebase / pull(保留 git 自身的进度显示)。

Source

pub fn state(&self) -> Result<RepoState, GitError>

探测仓库当前的合并状态。

Source

pub fn conflicted_files(&self) -> Result<Vec<ConflictedFile>, GitError>

列出所有处于冲突状态的文件。

Source

pub fn read_stage(&self, path: &str, stage: u8) -> Result<Vec<u8>, GitError>

读取冲突文件某个 stage 的完整内容(1=base,2=ours,3=theirs)。

Source

pub fn list_branches(&self) -> Result<Vec<String>, GitError>

列出可作为 merge / rebase 目标的分支:本地 + 远程跟踪, 排除当前分支与 HEAD 符号引用。

Source

pub fn recent_commits( &self, others_only: bool, limit: usize, ) -> Result<Vec<String>, GitError>

最近提交列表(--oneline 行,首列为短 hash),提交选择器用。

others_only 为 true 时只列不在当前分支上的提交(cherry-pick 候选), 否则列当前分支的最近提交(revert 候选)。 空仓库等无提交可列的场景返回空列表而非报错。

Source

pub fn vitals(&self) -> Result<RepoVitals, GitError>

探测仓库体征:分支、改动数、贮藏数、待推送数与提交总数。

均为廉价的本地查询;ahead / level 在无上游 / 空仓库时 查询会非零退出,分别归一化为 None / 0 而非报错。

Source

pub fn stage_resolved(&self, path: &str, content: &[u8]) -> Result<(), GitError>

将解决后的内容写入工作区文件并 git add

Source

pub fn continue_op(&self, state: RepoState) -> Result<ExitStatus, GitError>

继续当前 merge / rebase(冲突全部解决后调用)。

以透传模式执行:git 与钩子的输出(含颜色)实时流向用户终端。 返回退出码而非直接判错:rebase –continue 在下一个 commit 冲突时也会非零退出,是否算失败由调用方结合冲突探测决定。

Source

pub fn abort_op(&self, state: RepoState) -> Result<(), GitError>

中止当前 merge / rebase。

Auto Trait Implementations§

§

impl Freeze for Git

§

impl RefUnwindSafe for Git

§

impl Send for Git

§

impl Sync for Git

§

impl Unpin for Git

§

impl UnsafeUnpin for Git

§

impl UnwindSafe for Git

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.