Skip to content

Commit e8b7a4e

Browse files
authored
Merge pull request #2057 from GitoxideLabs/improvements
various improvements
2 parents 52906fb + 427274b commit e8b7a4e

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

gix/src/remote/connection/ref_map.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ where
9090
progress: impl Progress,
9191
options: Options,
9292
) -> Result<(fetch::RefMap, gix_protocol::handshake::Outcome), Error> {
93-
let refmap = self.ref_map_by_ref(progress, options).await;
94-
let handshake = self.handshake.expect("refmap always performs handshake");
95-
refmap.map(|map| (map, handshake))
93+
let refmap = self.ref_map_by_ref(progress, options).await?;
94+
let handshake = self
95+
.handshake
96+
.expect("refmap always performs handshake and stores it if it succeeds");
97+
Ok((refmap, handshake))
9698
}
9799

98100
#[allow(clippy::result_large_err)]

gix/src/repository/config/branch.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ impl crate::Repository {
5252
self.config
5353
.resolved
5454
.string_by("branch", Some(short_name), Branch::MERGE.name)
55-
.map(|name| crate::config::tree::branch::Merge::try_into_fullrefname(name).map_err(Into::into))
55+
.map(|name| {
56+
if name.starts_with(b"refs/") {
57+
crate::config::tree::branch::Merge::try_into_fullrefname(name)
58+
} else {
59+
gix_ref::Category::LocalBranch
60+
.to_full_name(name.as_ref())
61+
.map(Cow::Owned)
62+
}
63+
.map_err(Into::into)
64+
})
5665
}
5766
remote::Direction::Push => {
5867
let remote = match self.branch_remote(name.shorten(), direction)? {

gix/tests/gix/repository/config/remote.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,21 @@ mod branch_remote {
131131
.as_ref(),
132132
"remote_repo"
133133
);
134+
assert_eq!(
135+
repo.branch_remote_name("broken", direction)
136+
.expect("Remote name exists")
137+
.as_ref(),
138+
"remote_repo"
139+
);
134140
}
135141

136-
let merge_branch_invalid_msg = "The configured name of the remote ref to merge wasn't valid";
137142
assert_eq!(
138143
repo.branch_remote_ref_name("refs/heads/broken".try_into()?, remote::Direction::Fetch)
139144
.expect("Remote Merge ref exists")
140-
.unwrap_err()
141-
.to_string(),
142-
merge_branch_invalid_msg
145+
.expect("merge ref is turned into a full-name")
146+
.as_bstr(),
147+
"refs/heads/not_a_valid_merge_ref",
148+
"short names are simply turned into branch names - this doesn't always work, but sometimes."
143149
);
144150
assert!(repo
145151
.branch_remote_ref_name("refs/heads/missing".try_into()?, remote::Direction::Fetch)
@@ -152,11 +158,11 @@ mod branch_remote {
152158
}
153159
assert_eq!(
154160
repo.branch_remote_tracking_ref_name("refs/heads/broken".try_into()?, remote::Direction::Fetch)
155-
.expect("err")
156-
.unwrap_err()
157-
.to_string(),
158-
"Could not get the remote reference to translate into the local tracking branch",
159-
"the merge ref is broken, hence there can't be a tracking ref",
161+
.expect("no error")
162+
.expect("valid result")
163+
.as_bstr(),
164+
"refs/remotes/remote_repo/not_a_valid_merge_ref",
165+
"the merge ref is broken, but we turned it into a full ref name from which everything else was derived",
160166
);
161167

162168
Ok(())
@@ -219,10 +225,9 @@ mod branch_remote {
219225
);
220226
}
221227

222-
assert_eq!(
223-
repo.branch_remote_tracking_ref_name("refs/heads/broken".try_into()?, remote::Direction::Push).expect("has err").unwrap_err().to_string(),
224-
"Could not get the remote reference to translate into the local tracking branch",
225-
"push.default = simple, hence we need to verify the merge-branch is the same as us, but retrieving it fails",
228+
assert!(
229+
repo.branch_remote_tracking_ref_name("refs/heads/broken".try_into()?, remote::Direction::Push).is_none(),
230+
"push.default = simple, hence we need to verify the merge-branch is the same as us, and retrieving it succeeds due to auto-fullnamification but then it doesn't match",
226231
);
227232

228233
Ok(())

0 commit comments

Comments
 (0)