Skip to content

Commit

Permalink
feat: Remote::repo() to obtain the underlying repository.
Browse files Browse the repository at this point in the history
For convenience.
  • Loading branch information
Byron committed Nov 13, 2022
1 parent f0cab31 commit 25f7aab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion git-repository/src/remote/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ use git_refspec::RefSpec;
use crate::{bstr::BStr, remote, Remote};

/// Access
impl Remote<'_> {
impl<'repo> Remote<'repo> {
/// Return the name of this remote or `None` if it wasn't persisted to disk yet.
pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}

/// Return our repository reference.
pub fn repo(&self) -> &'repo crate::Repository {
self.repo
}

/// Return the set of ref-specs used for `direction`, which may be empty, in order of occurrence in the configuration.
pub fn refspecs(&self, direction: remote::Direction) -> &[RefSpec] {
match direction {
Expand Down
15 changes: 15 additions & 0 deletions git-repository/tests/remote/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ pub(crate) fn repo(name: &str) -> git::Repository {
git::open_opts(repo_path(name), git::open::Options::isolated()).unwrap()
}

pub(crate) fn into_daemon_remote<'repo>(
remote: git::Remote<'repo>,
daemon_url: &str,
repo_path: &str,
) -> crate::Result<git::Remote<'repo>> {
let mut new_remote = remote.repo().remote_at(format!("{}/{}", daemon_url, repo_path))?;
for direction in [git::remote::Direction::Fetch, git::remote::Direction::Push] {
new_remote.replace_refspecs(
remote.refspecs(direction).iter().map(|s| s.to_ref().to_bstring()),
direction,
)?;
}
Ok(new_remote)
}

pub(crate) fn cow_str(s: &str) -> Cow<str> {
Cow::Borrowed(s)
}
Expand Down

0 comments on commit 25f7aab

Please sign in to comment.