pub struct Proxy<'repo> { /* private fields */ }
Expand description

A stand-in to a worktree as result of a worktree iteration.

It provides access to typical worktree state, but may not actually point to a valid checkout as the latter has been moved or deleted.

Implementations§

Read the location of the checkout, the base of the work tree. Note that the location might not exist.

Examples found in repository?
src/worktree/proxy.rs (line 83)
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    pub fn into_repo_with_possibly_inaccessible_worktree(self) -> Result<Repository, crate::open::Error> {
        let base = self.base().ok();
        let repo = ThreadSafeRepository::open_from_paths(self.git_dir, base, self.parent.options.clone())?;
        Ok(repo.into())
    }

    /// Like `into_repo_with_possibly_inaccessible_worktree()` but will fail if the `base()` cannot be read or
    /// if the worktree doesn't exist.
    ///
    /// Note that it won't fail if the worktree doesn't exist.
    pub fn into_repo(self) -> Result<Repository, into_repo::Error> {
        let base = self.base()?;
        if !base.is_dir() {
            return Err(into_repo::Error::MissingWorktree { base });
        }
        let repo = ThreadSafeRepository::open_from_paths(self.git_dir, base.into(), self.parent.options.clone())?;
        Ok(repo.into())
    }

The git directory for the work tree, typically contained within the parent git dir.

The name of the worktree, which is derived from its folder within the worktrees directory within the parent .git folder.

Return true if the worktree cannot be pruned, moved or deleted, which is useful if it is located on an external storage device.

Examples found in repository?
src/worktree/mod.rs (line 42)
41
42
43
    pub fn is_locked(&self) -> bool {
        Proxy::new(self.parent, self.parent.git_dir()).is_locked()
    }

Provide a reason for the locking of this worktree, if it is locked at all.

Note that we squelch errors in case the file cannot be read in which case the reason is an empty string.

Examples found in repository?
src/worktree/mod.rs (line 50)
49
50
51
    pub fn lock_reason(&self) -> Option<BString> {
        Proxy::new(self.parent, self.parent.git_dir()).lock_reason()
    }

Transform this proxy into a Repository while ignoring issues reading base() and ignoring that it might not exist.

Most importantly, the Repository might be initialized with a non-existing work tree directory as the checkout was removed or moved in the mean time or is unavailable for other reasons. The caller will encounter io errors if it’s used like the work tree is guaranteed to be present, but can still access a lot of information if work tree access is avoided.

Examples found in repository?
src/remote/connection/fetch/update_refs/mod.rs (line 264)
258
259
260
261
262
263
264
265
266
267
268
269
270
fn worktree_branches(repo: &Repository) -> Result<BTreeMap<git_ref::FullName, PathBuf>, update::Error> {
    let mut map = BTreeMap::new();
    if let Some((wt_dir, head_ref)) = repo.work_dir().zip(repo.head_ref().ok().flatten()) {
        map.insert(head_ref.inner.name, wt_dir.to_owned());
    }
    for proxy in repo.worktrees()? {
        let repo = proxy.into_repo_with_possibly_inaccessible_worktree()?;
        if let Some((wt_dir, head_ref)) = repo.work_dir().zip(repo.head_ref().ok().flatten()) {
            map.insert(head_ref.inner.name, wt_dir.to_owned());
        }
    }
    Ok(map)
}

Like into_repo_with_possibly_inaccessible_worktree() but will fail if the base() cannot be read or if the worktree doesn’t exist.

Note that it won’t fail if the worktree doesn’t exist.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.