Struct Repo

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

Wrapper around git2::Repository.

Implementations§

Source§

impl Repo

Source

pub fn from_dir(path: &Path) -> Result<Self>

Get the Git repository associated with the given directory.

Source

pub fn from_current_dir() -> Result<Self>

Get the Git repository associated with the current directory.

Source

pub fn try_clone(&self) -> Result<Self>

Open a new copy of the repository.

Source

pub fn get_path(&self) -> &Path

Get the path to the .git directory for the repository.

Source

pub fn get_packed_refs_path(&self) -> PathBuf

Get the path to the packed-refs file for the repository.

Source

pub fn get_rebase_state_dir_path(&self) -> PathBuf

Get the path to the directory inside the .git directory which contains state used for the current rebase (if any).

Source

pub fn get_working_copy_path(&self) -> Option<PathBuf>

Get the path to the working copy for this repository. If the repository is bare (has no working copy), returns None.

Source

pub fn get_index(&self) -> Result<Index>

Get the index file for this repository.

Source

pub fn open_worktree_parent_repo(&self) -> Result<Option<Self>>

If this repository is a worktree for another “parent” repository, return a Repo object corresponding to that repository.

Source

pub fn get_readonly_config(&self) -> Result<impl ConfigRead>

Get the configuration object for the repository.

Warning: This object should only be used for read operations. Write operations should go to the config file under the .git/branchless directory.

Source

pub fn get_branchless_dir(&self) -> Result<PathBuf>

Get the directory where all repo-specific git-branchless state is stored.

Source

pub fn get_config_path(&self) -> Result<PathBuf>

Get the file where git-branchless-specific Git configuration is stored.

Source

pub fn get_dag_dir(&self) -> Result<PathBuf>

Get the directory where the DAG for the repository is stored.

Source

pub fn get_man_dir(&self) -> Result<PathBuf>

Get the directory to store man-pages. Note that this is the man directory, and not a subsection thereof. git-branchless man-pages must go into the man/man1 directory to be found by man.

Source

pub fn get_tempfile_dir(&self) -> Result<PathBuf>

Get a directory suitable for storing temporary files.

In particular, this directory is guaranteed to be on the same filesystem as the Git repository itself, so you can move files between them atomically. See https://github.com/arxanas/git-branchless/discussions/120.

Source

pub fn get_db_conn(&self) -> Result<Connection>

Get the connection to the SQLite database for this repository.

Source

pub fn resolve_reference( &self, reference: &Reference<'_>, ) -> Result<ResolvedReferenceInfo>

Get a snapshot of information about a given reference.

Source

pub fn get_head_info(&self) -> Result<ResolvedReferenceInfo>

Get the OID for the repository’s HEAD reference.

Source

pub fn reference_name_to_oid( &self, name: &ReferenceName, ) -> Result<MaybeZeroOid>

Get the OID for a given ReferenceName if it exists.

Source

pub fn set_head(&self, oid: NonZeroOid) -> Result<()>

Set the HEAD reference directly to the provided oid. Does not touch the working copy.

Source

pub fn detach_head(&self, head_info: &ResolvedReferenceInfo) -> Result<()>

Detach HEAD by making it point directly to its current OID, rather than to a branch. If HEAD is unborn, logs a warning.

Source

pub fn is_rebase_underway(&self) -> Result<bool>

Detect if an interactive rebase has started but not completed.

Git will send us spurious post-rewrite events marked as amend during an interactive rebase, indicating that some of the commits have been rewritten as part of the rebase plan, but not all of them. This function attempts to detect when an interactive rebase is underway, and if the current post-rewrite event is spurious.

There are two practical issues for users as a result of this Git behavior:

  • During an interactive rebase, we may see many “processing 1 rewritten commit” messages, and then a final “processing X rewritten commits” message once the rebase has concluded. This is potentially confusing for users, since the operation logically only rewrote the commits once, but we displayed the message multiple times.

  • During an interactive rebase, we may warn about abandoned commits, when the next operation in the rebase plan fixes up the abandoned commit. This can happen even if no conflict occurred and the rebase completed successfully without any user intervention.

Source

pub fn get_current_operation_type(&self) -> Option<&str>

Get the type current multi-step operation (such as rebase or cherry-pick) which is underway. Returns None if there is no such operation.

Source

pub fn find_merge_base( &self, lhs: NonZeroOid, rhs: NonZeroOid, ) -> Result<Option<NonZeroOid>>

Find the merge-base between two commits. Returns None if a merge-base could not be found.

Source

pub fn get_patch_for_commit( &self, effects: &Effects, commit: &Commit<'_>, ) -> Result<Option<Diff<'_>>>

Get the patch for a commit, i.e. the diff between that commit and its parent.

If the commit has more than one parent, returns None.

Source

pub fn get_diff_between_trees( &self, effects: &Effects, old_tree: Option<&Tree<'_>>, new_tree: &Tree<'_>, num_context_lines: usize, ) -> Result<Diff<'_>>

Get the diff between two trees. This is more performant than calling libgit2’s diff_tree_to_tree directly since it dehydrates commits before diffing them.

Source

pub fn get_staged_paths(&self) -> Result<HashSet<PathBuf>>

Returns the set of paths currently staged to the repository’s index.

Source

pub fn get_paths_touched_by_commit( &self, commit: &Commit<'_>, ) -> Result<HashSet<PathBuf>>

Get the file paths which were added, removed, or changed by the given commit.

If the commit has no parents, returns all of the file paths in that commit’s tree.

If the commit has more than one parent, returns all file paths changed with respect to any parent.

Source

pub fn get_patch_id( &self, effects: &Effects, commit: &Commit<'_>, ) -> Result<Option<PatchId>>

Get the patch ID for this commit.

Source

pub fn revparse_single_commit(&self, spec: &str) -> Result<Option<Commit<'_>>>

Attempt to parse the user-provided object descriptor.

Source

pub fn get_all_references(&self) -> Result<Vec<Reference<'_>>>

Find all references in the repository.

Source

pub fn has_changed_files( &self, effects: &Effects, git_run_info: &GitRunInfo, ) -> Result<bool>

Check if the repository has staged or unstaged changes. Untracked files are not included. This operation may take a while.

Source

pub fn get_status( &self, effects: &Effects, git_run_info: &GitRunInfo, index: &Index, head_info: &ResolvedReferenceInfo, event_tx_id: Option<EventTransactionId>, ) -> Result<(WorkingCopySnapshot<'_>, Vec<StatusEntry>)>

Returns the current status of the repo index and working copy.

Source

pub fn create_branch( &self, branch_name: &str, commit: &Commit<'_>, force: bool, ) -> Result<Branch<'_>>

Create a new branch or update an existing one. The provided name should be a branch name and not a reference name, i.e. it should not start with refs/heads/.

Source

pub fn create_reference( &self, name: &ReferenceName, oid: NonZeroOid, force: bool, log_message: &str, ) -> Result<Reference<'_>>

Create a new reference or update an existing one.

Source

pub fn get_all_remote_names(&self) -> Result<Vec<String>>

Get a list of all remote names.

Source

pub fn find_reference( &self, name: &ReferenceName, ) -> Result<Option<Reference<'_>>>

Look up a reference with the given name. Returns None if not found.

Source

pub fn get_all_local_branches(&self) -> Result<Vec<Branch<'_>>>

Get all local branches in the repository.

Source

pub fn find_branch( &self, name: &str, branch_type: BranchType, ) -> Result<Option<Branch<'_>>>

Look up the branch with the given name. Returns None if not found.

Source

pub fn find_commit(&self, oid: NonZeroOid) -> Result<Option<Commit<'_>>>

Look up a commit with the given OID. Returns None if not found.

Source

pub fn find_commit_or_fail(&self, oid: NonZeroOid) -> Result<Commit<'_>>

Like find_commit, but raises a generic error if the commit could not be found.

Source

pub fn find_blob(&self, oid: NonZeroOid) -> Result<Option<Blob<'_>>>

Look up a blob with the given OID. Returns None if not found.

Source

pub fn find_blob_or_fail(&self, oid: NonZeroOid) -> Result<Blob<'_>>

Like find_blob, but raises a generic error if the blob could not be found.

Source

pub fn friendly_describe_commit_from_oid( &self, glyphs: &Glyphs, oid: NonZeroOid, ) -> Result<StyledString>

Look up the commit with the given OID and render a friendly description of it, or render an error message if not found.

Source

pub fn create_blob_from_path(&self, path: &Path) -> Result<Option<NonZeroOid>>

Read a file from disk and create a blob corresponding to its contents. If the file doesn’t exist on disk, returns None instead.

Source

pub fn create_blob_from_contents(&self, contents: &[u8]) -> Result<NonZeroOid>

Create a blob corresponding to the provided byte slice.

Source

pub fn create_commit( &self, update_ref: Option<&str>, author: &Signature<'_>, committer: &Signature<'_>, message: &str, tree: &Tree<'_>, parents: Vec<&Commit<'_>>, ) -> Result<NonZeroOid>

Create a new commit.

Source

pub fn cherry_pick_commit( &self, cherry_pick_commit: &Commit<'_>, our_commit: &Commit<'_>, mainline: u32, ) -> Result<Index>

Cherry-pick a commit in memory and return the resulting index.

Source

pub fn cherry_pick_fast<'repo>( &'repo self, patch_commit: &'repo Commit<'_>, target_commit: &'repo Commit<'_>, options: &CherryPickFastOptions, ) -> Result<Tree<'repo>, CreateCommitFastError>

Cherry-pick a commit in memory and return the resulting tree.

The libgit2 routines operate on entire Indexes, which contain one entry per file in the repository. When operating on a large repository, this is prohibitively slow, as it takes several seconds just to write the index to disk. To improve performance, we reduce the size of the involved indexes by filtering out any unchanged entries from the input trees, then call into libgit2, then add back the unchanged entries to the output tree.

Source

pub fn find_tree(&self, oid: NonZeroOid) -> Result<Option<Tree<'_>>>

Look up the tree with the given OID. Returns None if not found.

Source

pub fn find_tree_or_fail(&self, oid: NonZeroOid) -> Result<Tree<'_>>

Like find_tree, but raises a generic error if the commit could not be found.

Source

pub fn write_index_to_tree(&self, index: &mut Index) -> Result<NonZeroOid>

Write the provided in-memory index as a tree into Git`s object database. There must be no merge conflicts in the index.

Source

pub fn amend_fast( &self, parent_commit: &Commit<'_>, opts: &AmendFastOptions<'_>, ) -> Result<Tree<'_>, CreateCommitFastError>

Amends the provided parent commit in memory and returns the resulting tree.

Only amends the files provided in the options, and only supports amending from either the working tree or the index, but not both.

See Repo::cherry_pick_fast for motivation for performing the operation in-memory.

Trait Implementations§

Source§

impl Debug for Repo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl RepoExt for Repo

Source§

fn get_main_branch(&self) -> Result<Branch<'_>>

Get the Branch for the main branch for the repository.
Source§

fn get_main_branch_oid(&self) -> Result<NonZeroOid>

Get the OID corresponding to the main branch.
Source§

fn get_branch_oid_to_names( &self, ) -> Result<HashMap<NonZeroOid, HashSet<ReferenceName>>>

Get a mapping from OID to the names of branches which point to that OID. Read more
Source§

fn get_references_snapshot(&self) -> Result<RepoReferencesSnapshot>

Get the positions of references in the repository.
Source§

fn get_default_push_remote(&self) -> Result<Option<String>>

Get the default remote to push to for new branches in this repository.

Auto Trait Implementations§

§

impl Freeze for Repo

§

impl RefUnwindSafe for Repo

§

impl Send for Repo

§

impl !Sync for Repo

§

impl Unpin for Repo

§

impl UnwindSafe for Repo

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> With for T

Source§

fn wrap_with<U, F>(self, f: F) -> U
where F: FnOnce(Self) -> U,

Calls the given closure and return the result. Read more
Source§

fn with<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure on self.
Source§

fn try_with<E, F>(self, f: F) -> Result<Self, E>
where F: FnOnce(&mut Self) -> Result<(), E>,

Calls the given closure on self.
Source§

fn with_if<F>(self, condition: bool, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure if condition == true.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Erased for T

Source§

impl<T> Erased for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,