Struct git2::Submodule

source ·
pub struct Submodule<'repo> { /* private fields */ }
Expand description

A structure to represent a git submodule

Implementations§

source§

impl<'repo> Submodule<'repo>

source

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

Get the submodule’s branch.

Returns None if the branch is not valid utf-8 or if the branch is not yet available.

source

pub fn branch_bytes(&self) -> Option<&[u8]>

Get the branch for the submodule.

Returns None if the branch is not yet available.

source

pub fn clone( &mut self, opts: Option<&mut SubmoduleUpdateOptions<'_>> ) -> Result<Repository, Error>

Perform the clone step for a newly created submodule.

This performs the necessary git_clone to setup a newly-created submodule.

source

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

Get the submodule’s URL.

Returns None if the URL is not valid utf-8 or if the URL isn’t present

source

pub fn opt_url_bytes(&self) -> Option<&[u8]>

Get the URL for the submodule.

Returns None if the URL isn’t present

source

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

Get the submodule’s name.

Returns None if the name is not valid utf-8

source

pub fn name_bytes(&self) -> &[u8]

Get the name for the submodule.

source

pub fn path(&self) -> &Path

Get the path for the submodule.

source

pub fn head_id(&self) -> Option<Oid>

Get the OID for the submodule in the current HEAD tree.

source

pub fn index_id(&self) -> Option<Oid>

Get the OID for the submodule in the index.

source

pub fn workdir_id(&self) -> Option<Oid>

Get the OID for the submodule in the current working directory.

This returns the OID that corresponds to looking up ‘HEAD’ in the checked out submodule. If there are pending changes in the index or anything else, this won’t notice that.

source

pub fn ignore_rule(&self) -> SubmoduleIgnore

Get the ignore rule that will be used for the submodule.

source

pub fn update_strategy(&self) -> SubmoduleUpdate

Get the update rule that will be used for the submodule.

source

pub fn init(&mut self, overwrite: bool) -> Result<(), Error>

Copy submodule info into “.git/config” file.

Just like “git submodule init”, this copies information about the submodule into “.git/config”. You can use the accessor functions above to alter the in-memory git_submodule object and control what is written to the config, overriding what is in .gitmodules.

By default, existing entries will not be overwritten, but passing true for overwrite forces them to be updated.

source

pub fn repo_init(&mut self, use_gitlink: bool) -> Result<Repository, Error>

Set up the subrepository for a submodule in preparation for clone.

This function can be called to init and set up a submodule repository from a submodule in preparation to clone it from its remote. use_gitlink: Should the workdir contain a gitlink to the repo in .git/modules vs. repo directly in workdir.

source

pub fn open(&self) -> Result<Repository, Error>

Open the repository for a submodule.

This will only work if the submodule is checked out into the working directory.

source

pub fn reload(&mut self, force: bool) -> Result<(), Error>

Reread submodule info from config, index, and HEAD.

Call this to reread cached submodule information for this submodule if you have reason to believe that it has changed.

If force is true, then data will be reloaded even if it doesn’t seem out of date

source

pub fn sync(&mut self) -> Result<(), Error>

Copy submodule remote info into submodule repo.

This copies the information about the submodules URL into the checked out submodule config, acting like “git submodule sync”. This is useful if you have altered the URL for the submodule (or it has been altered by a fetch of upstream changes) and you need to update your local repo.

source

pub fn add_to_index(&mut self, write_index: bool) -> Result<(), Error>

Add current submodule HEAD commit to index of superproject.

If write_index is true, then the index file will be immediately written. Otherwise you must explicitly call write() on an Index later on.

source

pub fn add_finalize(&mut self) -> Result<(), Error>

Resolve the setup of a new git submodule.

This should be called on a submodule once you have called add setup and done the clone of the submodule. This adds the .gitmodules file and the newly cloned submodule to the index to be ready to be committed (but doesn’t actually do the commit).

source

pub fn update( &mut self, init: bool, opts: Option<&mut SubmoduleUpdateOptions<'_>> ) -> Result<(), Error>

Update submodule.

This will clone a missing submodule and check out the subrepository to the commit specified in the index of the containing repository. If the submodule repository doesn’t contain the target commit, then the submodule is fetched using the fetch options supplied in opts.

init indicates if the submodule should be initialized first if it has not been initialized yet.

Trait Implementations§

source§

impl<'repo> Drop for Submodule<'repo>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'repo> RefUnwindSafe for Submodule<'repo>

§

impl<'repo> !Send for Submodule<'repo>

§

impl<'repo> !Sync for Submodule<'repo>

§

impl<'repo> Unpin for Submodule<'repo>

§

impl<'repo> UnwindSafe for Submodule<'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> 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.