Struct magoo::git::GitContext
source · pub struct GitContext { /* private fields */ }Expand description
Context for running git commands
Implementations§
source§impl GitContext
impl GitContext
Implementation for basic operations
sourcepub fn try_from<S>(working_dir: S) -> Result<Self, GitError>
pub fn try_from<S>(working_dir: S) -> Result<Self, GitError>
Create a new GitContext for running git commands in the given working directory
sourcepub fn lock(&self) -> Result<Guard, GitError>
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.
sourcepub fn print_version_info(&self) -> Result<(), GitError>
pub fn print_version_info(&self) -> Result<(), GitError>
Print the supported git version info and current git version into
sourcepub fn git_dir(&self) -> Result<&PathBuf, GitError>
pub fn git_dir(&self) -> Result<&PathBuf, GitError>
Get the absolute path to the .git directory
sourcepub fn git_dir_raw(&self) -> Result<Option<String>, GitError>
pub fn git_dir_raw(&self) -> Result<Option<String>, GitError>
Return the raw output of git rev-parse --git-dir
sourcepub fn top_level_dir(&self) -> Result<&PathBuf, GitError>
pub fn top_level_dir(&self) -> Result<&PathBuf, GitError>
Get the absolute path to the top level directory
source§impl GitContext
impl GitContext
Wrapper implementation for git commands
sourcepub fn ls_files(&self, extra_args: &[&str]) -> Result<Vec<String>, GitError>
pub fn ls_files(&self, extra_args: &[&str]) -> Result<Vec<String>, GitError>
Run git -C top_level ls-files ...
sourcepub fn describe(&self, commit: &str) -> Option<String>
pub fn describe(&self, commit: &str) -> Option<String>
Run git describe --all <commit> and return the first output
sourcepub fn get_config<S>(
&self,
config_path: S,
key: &str
) -> Result<Option<String>, GitError>
pub fn get_config<S>( &self, config_path: S, key: &str ) -> Result<Option<String>, GitError>
Run git config -f config_path --get key
The config path is resolved relative to the working directory of this context.
sourcepub fn get_config_regexp<S>(
&self,
config_path: S,
regexp: &str
) -> Result<Vec<(String, String)>, GitError>
pub fn get_config_regexp<S>( &self, config_path: S, regexp: &str ) -> Result<Vec<(String, String)>, GitError>
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.
sourcepub fn set_config<S>(
&self,
config_path: S,
key: &str,
value: Option<&str>
) -> Result<(), GitError>
pub fn set_config<S>( &self, config_path: S, key: &str, value: Option<&str> ) -> Result<(), GitError>
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.
sourcepub fn remove_config_section<S>(
&self,
config_path: S,
section: &str
) -> Result<(), GitError>
pub fn remove_config_section<S>( &self, config_path: S, section: &str ) -> Result<(), GitError>
Remove a config section from a config file.
The config path is resolved relative to the working directory of this context.
sourcepub fn remove_from_index(&self, path: &str) -> Result<(), GitError>
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
sourcepub fn submodule_deinit(
&self,
path: Option<&str>,
force: bool
) -> Result<(), GitError>
pub fn submodule_deinit( &self, path: Option<&str>, force: bool ) -> Result<(), GitError>
Runs git submodule deinit [-- <path>]. Path should be from top level
sourcepub fn submodule_init(&self, path: Option<&str>) -> Result<(), GitError>
pub fn submodule_init(&self, path: Option<&str>) -> Result<(), GitError>
Runs git submodule init [-- <path>]. Path should be from top level
sourcepub fn submodule_sync(&self, path: Option<&str>) -> Result<(), GitError>
pub fn submodule_sync(&self, path: Option<&str>) -> Result<(), GitError>
Runs git submodule sync [-- <path>]. Path should be from top level
sourcepub fn submodule_set_branch(
&self,
path: &str,
branch: Option<&str>
) -> Result<(), GitError>
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.
sourcepub fn submodule_set_url(&self, path: &str, url: &str) -> Result<(), GitError>
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.