Skip to content

Commit 270322e

Browse files
committed
feat: Add Reference::remote_tracking_ref_name() and *::remote_ref_name().
These methods mirror their respective `Repository::branch_*` prefixed versions.
1 parent 4aa4b05 commit 270322e

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

gix/src/reference/remote.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
1+
use crate::repository::{branch_remote_ref_name, branch_remote_tracking_ref_name};
12
use crate::{remote, Reference};
3+
use gix_ref::FullNameRef;
4+
use std::borrow::Cow;
25

36
/// Remotes
47
impl<'repo> Reference<'repo> {
58
/// Find the name of our remote for `direction` as configured in `branch.<name>.remote|pushRemote` respectively.
6-
/// If `Some(<name>)` it can be used in [`Repository::find_remote(…)`][crate::Repository::find_remote()], or if `None` then
7-
/// [`Repository::remote_default_name()`][crate::Repository::remote_default_name()] could be used in its place.
8-
///
99
/// Return `None` if no remote is configured.
1010
///
11-
/// # Note
12-
///
13-
/// - it's recommended to use the [`remote(…)`][Self::remote()] method as it will configure the remote with additional
14-
/// information.
15-
/// - `branch.<name>.pushRemote` falls back to `branch.<name>.remote`.
11+
/// See also [`Repository::branch_remote_name()`](crate::Repository::branch_remote_name()) for more details.
1612
pub fn remote_name(&self, direction: remote::Direction) -> Option<remote::Name<'repo>> {
1713
self.repo.branch_remote_name(self.name().shorten(), direction)
1814
}
1915

20-
/// Like [`branch_remote(…)`](crate::Repository::branch_remote()), but automatically provides the reference name
21-
/// for configuration lookup.
16+
/// Find the remote along with all configuration associated with it suitable for handling this reference.
17+
///
18+
/// See also [`Repository::branch_remote()`](crate::Repository::branch_remote()) for more details.
2219
pub fn remote(
2320
&self,
2421
direction: remote::Direction,
2522
) -> Option<Result<crate::Remote<'repo>, remote::find::existing::Error>> {
2623
self.repo.branch_remote(self.name().shorten(), direction)
2724
}
25+
26+
/// Return the name of this reference on the remote side.
27+
///
28+
/// See [`Repository::branch_remote_ref_name()`](crate::Repository::branch_remote_ref_name()) for details.
29+
#[doc(alias = "upstream", alias = "git2")]
30+
pub fn remote_ref_name(
31+
&self,
32+
direction: remote::Direction,
33+
) -> Option<Result<Cow<'_, FullNameRef>, branch_remote_ref_name::Error>> {
34+
self.repo.branch_remote_ref_name(self.name(), direction)
35+
}
36+
37+
/// Return the name of the reference that tracks this reference on the remote side.
38+
///
39+
/// See [`Repository::branch_remote_tracking_ref_name()`](crate::Repository::branch_remote_tracking_ref_name()) for details.
40+
#[doc(alias = "upstream", alias = "git2")]
41+
pub fn remote_tracking_ref_name(
42+
&self,
43+
direction: remote::Direction,
44+
) -> Option<Result<Cow<'_, FullNameRef>, branch_remote_tracking_ref_name::Error>> {
45+
self.repo.branch_remote_tracking_ref_name(self.name(), direction)
46+
}
2847
}

gix/src/repository/config/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ mod branch {
228228
/// The value is also fast to retrieve compared to its tracking branch.
229229
/// Also note that a [remote::Direction] isn't used here as Git only supports (and requires) configuring
230230
/// the remote to fetch from, not the one to push to.
231+
///
232+
/// See also [`Reference::remote_ref_name()`](crate::Reference::remote_ref_name()).
231233
#[doc(alias = "branch_upstream_name", alias = "git2")]
232234
pub fn branch_remote_ref_name(
233235
&self,
@@ -295,6 +297,8 @@ mod branch {
295297
///
296298
/// Note that if there is an ambiguity, that is if `name` maps to multiple tracking branches, the first matching mapping
297299
/// is returned, according to the order in which the fetch or push refspecs occour in the configuration file.
300+
///
301+
/// See also [`Reference::remote_tracking_ref_name()`](crate::Reference::remote_tracking_ref_name()).
298302
#[doc(alias = "branch_upstream_name", alias = "git2")]
299303
pub fn branch_remote_tracking_ref_name(
300304
&self,
@@ -326,7 +330,7 @@ mod branch {
326330
/// * if `direction` is [remote::Direction::Push], the push remote will be queried by means of `branch.<short_name>.pushRemote`
327331
/// or `remote.pushDefault` as fallback.
328332
///
329-
/// See also [`Reference::remote_name()`][crate::Reference::remote_name()] for a more typesafe version
333+
/// See also [`Reference::remote_name()`](crate::Reference::remote_name()) for a more typesafe version
330334
/// to be used when a `Reference` is available.
331335
///
332336
/// `short_branch_name` can typically be obtained by [shortening a full branch name](FullNameRef::shorten()).
@@ -352,6 +356,8 @@ mod branch {
352356
/// Like [`branch_remote_name(…)`](Self::branch_remote_name()), but returns a [Remote](crate::Remote).
353357
/// `short_branch_name` is the name to use for looking up `branch.<short_branch_name>.*` values in the
354358
/// configuration.
359+
///
360+
/// See also [`Reference::remote()`](crate::Reference::remote()).
355361
pub fn branch_remote<'a>(
356362
&self,
357363
short_branch_name: impl Into<&'a BStr>,

0 commit comments

Comments
 (0)