Struct rustgit::Repository
source · pub struct Repository { /* private fields */ }
Expand description
Local repository residing in memory
Implementations§
source§impl Repository
impl Repository
sourcepub fn for_each_entry<F: FnMut(&str, Mode, Hash)>(
&self,
path: &str,
entry_type: EntryType,
callback: F
) -> Result<(), Error>
pub fn for_each_entry<F: FnMut(&str, Mode, Hash)>( &self, path: &str, entry_type: EntryType, callback: F ) -> Result<(), Error>
Returns an iterator on the contents of a directory that was staged or commited before.
Returns PathError
if the path leads to nowhere.
This can write-lock an internal RwLock for cache.
sourcepub fn read_file(&self, path: &str) -> Result<&[u8], Error>
pub fn read_file(&self, path: &str) -> Result<&[u8], Error>
Returns the content of a file that was staged or commited before.
Returns PathError
if the path leads to nowhere.
This can write-lock an internal RwLock for cache.
sourcepub fn file_exists(&self, path: &str) -> Result<bool, Error>
pub fn file_exists(&self, path: &str) -> Result<bool, Error>
Returns the content of a file that was staged or commited before.
Returns PathError
if the path leads to nowhere.
This can write-lock an internal RwLock for cache.
sourcepub fn read_text(&self, path: &str) -> Result<&str, Error>
pub fn read_text(&self, path: &str) -> Result<&str, Error>
Returns the content of a textual file that was staged or commited before.
Returns PathError
if the path leads to nowhere.
Returns InvalidObject
if the file contains non-utf-8 bytes.
This can write-lock an internal RwLock for cache.
sourcepub fn stage(
&mut self,
path: &str,
data: Option<(Vec<u8>, FileType)>
) -> Result<(), Error>
pub fn stage( &mut self, path: &str, data: Option<(Vec<u8>, FileType)> ) -> Result<(), Error>
Place a new file in the workspace, which will be staged
until the next call to Self::commit
.
- Missing directories are created as needed.
- If
data
isNone
, any existing file at thispath
will be staged as deleted. If this leads to directories becoming empty, they will be deleted as well.
Should only fail if the repository was already corrupted.
sourcepub fn commit(
&mut self,
message: &str,
author: (&str, &str),
committer: (&str, &str),
timestamp: Option<u64>
) -> Result<Hash, Error>
pub fn commit( &mut self, message: &str, author: (&str, &str), committer: (&str, &str), timestamp: Option<u64> ) -> Result<Hash, Error>
Creates a new commit which saves staged files into the repository.
- If
timestamp
isNone
, the current time will be used instead. - If one of the strings in
author
&committer
contain invalid characters (<
,>
or\n
), this returnsInvalidObject
immediately.
sourcepub fn discard_commits(&mut self)
pub fn discard_commits(&mut self)
Resets the current commit to the branch head in upstream
Changes from the discarded commits are still present (staged).
sourcepub fn discard_changes(&mut self)
pub fn discard_changes(&mut self)
Discard changes that weren’t commited
source§impl Repository
impl Repository
sourcepub fn clone(
&mut self,
remote: &Remote,
reference: Reference<'_>,
depth: Option<usize>
) -> Result<(), Error>
pub fn clone( &mut self, remote: &Remote, reference: Reference<'_>, depth: Option<usize> ) -> Result<(), Error>
Imports objects from a remote repository based on a reference
Note: Can return Err(GitProtocolError)
when an invalid Commit
reference is specified (one which doesn’t exist on the remote end).
pub fn import_packfile( &mut self, packfile: Vec<u8>, head: Option<Hash> ) -> Result<(), Error>
source§impl Repository
impl Repository
sourcepub fn push(
&mut self,
remote: &Remote,
updated_heads: &[(&str, Hash)],
force_push: bool
) -> Result<(), Error>
pub fn push( &mut self, remote: &Remote, updated_heads: &[(&str, Hash)], force_push: bool ) -> Result<(), Error>
Push committed changes upstream