Struct magoo::git::GitContext

source ·
pub struct GitContext { /* private fields */ }
Expand description

Context for running git commands

Implementations§

source§

impl GitContext

Implementation for basic operations

source

pub fn try_from<S>(working_dir: S) -> Result<Self, GitError>
where S: AsRef<Path>,

Create a new GitContext for running git commands in the given working directory

source

pub fn lock(&self) -> Result<Guard, GitError>

Return a guard that locks the repository until dropped. Other magoo processes cannot access the repository while the guard is alive.

source

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

Print the supported git version info and current git version into

source

pub fn git_dir(&self) -> Result<&PathBuf, GitError>

Get the absolute path to the .git directory

source

pub fn git_dir_raw(&self) -> Result<Option<String>, GitError>

Return the raw output of git rev-parse --git-dir

source

pub fn top_level_dir(&self) -> Result<&PathBuf, GitError>

Get the absolute path to the top level directory

source

pub fn get_top_level_switch(&self) -> Result<Option<String>, GitError>

Get the path in git -C <path> ... to run the command in the top level directory

source§

impl GitContext

Wrapper implementation for git commands

source

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

Run git status and print the status

source

pub fn ls_files(&self, extra_args: &[&str]) -> Result<Vec<String>, GitError>

Run git -C top_level ls-files ...

source

pub fn describe(&self, commit: &str) -> Option<String>

Run git describe --all <commit> and return the first output

source

pub fn head(&self) -> Result<Option<String>, GitError>

Run git rev-parse HEAD

source

pub fn get_config<S>( &self, config_path: S, key: &str ) -> Result<Option<String>, GitError>
where S: AsRef<Path>,

Run git config -f config_path --get key

The config path is resolved relative to the working directory of this context.

source

pub fn get_config_regexp<S>( &self, config_path: S, regexp: &str ) -> Result<Vec<(String, String)>, GitError>
where S: AsRef<Path>,

Calls git config -f config_path ... --get-regexp regexp to get (key, value) pairs in the config file

The config path is resolved relative to the working directory of this context.

source

pub fn set_config<S>( &self, config_path: S, key: &str, value: Option<&str> ) -> Result<(), GitError>
where S: AsRef<Path>,

Calls git config to set or remove a config from a config file.

The config path is resolved relative to the working directory of this context.

source

pub fn remove_config_section<S>( &self, config_path: S, section: &str ) -> Result<(), GitError>
where S: AsRef<Path>,

Remove a config section from a config file.

The config path is resolved relative to the working directory of this context.

source

pub fn remove_from_index(&self, path: &str) -> Result<(), GitError>

Remove an object from the index and stage the change. The path should be relative from repo top level

source

pub fn add(&self, path: &str) -> Result<(), GitError>

Run git add

source

pub fn submodule_deinit( &self, path: Option<&str>, force: bool ) -> Result<(), GitError>

Runs git submodule deinit [-- <path>]. Path should be from top level

source

pub fn submodule_init(&self, path: Option<&str>) -> Result<(), GitError>

Runs git submodule init [-- <path>]. Path should be from top level

source

pub fn submodule_sync(&self, path: Option<&str>) -> Result<(), GitError>

Runs git submodule sync [-- <path>]. Path should be from top level

source

pub fn submodule_set_branch( &self, path: &str, branch: Option<&str> ) -> Result<(), GitError>

Runs git submodule set-branch. Path should be from top level

Note: Pre git 2.43, there’s a bug treating the argument as name instead of path.

source

pub fn submodule_set_url(&self, path: &str, url: &str) -> Result<(), GitError>

Runs git submodule set-url.

Note: Pre git 2.43, there’s a bug treating the argument as name instead of path.

source

pub fn submodule_update( &self, path: Option<&str>, force: bool, remote: bool ) -> Result<(), GitError>

Runs git submodule update [-- <path>]. Path should be from top level

source

pub fn submodule_add( &self, url: &str, path: Option<&str>, branch: Option<&str>, name: Option<&str>, depth: Option<usize>, force: bool ) -> Result<(), GitError>

Runs git submodule add. Path should be from top level

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.