Skip to content

Commit 547e450

Browse files
committed
prepare test for handling the 'unborn' lsrefs extension (#450)
1 parent 02e37f0 commit 547e450

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

git-repository/src/clone/fetch/util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn update_head(
5959
None => return Ok(()),
6060
};
6161

62-
let name: git_ref::FullName = "HEAD".try_into().expect("valid");
62+
let head: git_ref::FullName = "HEAD".try_into().expect("valid");
6363
let reflog_message = || LogChange {
6464
mode: RefLog::AndReference,
6565
force_create_reflog: false,
@@ -98,7 +98,7 @@ pub fn update_head(
9898
expected: PreviousValue::Any,
9999
new: Target::Symbolic(referent),
100100
},
101-
name: name.clone(),
101+
name: head.clone(),
102102
deref: false,
103103
},
104104
],
@@ -116,7 +116,7 @@ pub fn update_head(
116116
expected: PreviousValue::Any,
117117
new: Target::Peeled(head_peeled_id.to_owned()),
118118
},
119-
name,
119+
name: head,
120120
deref: false,
121121
})?;
122122
}
@@ -127,7 +127,7 @@ pub fn update_head(
127127
expected: PreviousValue::Any,
128128
new: Target::Peeled(head_peeled_id.to_owned()),
129129
},
130-
name,
130+
name: head,
131131
deref: false,
132132
})?;
133133
}

git-repository/src/remote/fetch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl Source {
5353
match self {
5454
Source::ObjectId(_) => None,
5555
Source::Ref(r) => match r {
56+
git_protocol::fetch::Ref::Unborn { target: _ } => Some("HEAD".into()),
5657
git_protocol::fetch::Ref::Symbolic { full_ref_name, .. }
5758
| git_protocol::fetch::Ref::Direct { full_ref_name, .. }
5859
| git_protocol::fetch::Ref::Peeled { full_ref_name, .. } => Some(full_ref_name.as_ref()),

git-repository/tests/clone/mod.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,41 @@ mod blocking_io {
193193
}
194194

195195
#[test]
196+
#[ignore]
196197
fn fetch_and_checkout_empty_remote_repo() -> crate::Result {
197198
let tmp = git_testtools::tempfile::TempDir::new()?;
198199
let mut prepare = git::prepare_clone(
199200
git_testtools::scripted_fixture_repo_read_only("make_empty_repo.sh")?,
200201
tmp.path(),
201202
)?;
202-
let (mut checkout, _out) = prepare
203+
let (mut checkout, out) = prepare
203204
.fetch_then_checkout(git::progress::Discard, &std::sync::atomic::AtomicBool::default())
204205
.unwrap();
205206
let (repo, _) = checkout.main_worktree(git::progress::Discard, &std::sync::atomic::AtomicBool::default())?;
206207

207208
assert!(!repo.index_path().is_file(), "newly initialized repos have no index");
208209
assert!(repo.head()?.is_unborn());
210+
if out
211+
.ref_map
212+
.handshake
213+
.capabilities
214+
.capability("ls-refs")
215+
.expect("has ls-refs")
216+
.supports("unborn")
217+
== Some(true)
218+
{
219+
assert_eq!(
220+
repo.head()?.referent_name().expect("present").as_bstr(),
221+
"refs/heads/special",
222+
"we pick up the name as present on the server, not the one we default to"
223+
);
224+
} else {
225+
assert_eq!(
226+
repo.head()?.referent_name().expect("present").as_bstr(),
227+
"refs/heads/main",
228+
"we simply keep our own post-init HEAD which defaults to the branch name we configured locally"
229+
);
230+
}
209231

210232
Ok(())
211233
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:8c88c509ad1df376844b8a80b003a01c78de79284c4b0cf72fe661ca41f6d303
2+
oid sha256:875f0aa4a343935bc881d6c595efffeb34063a460239178cf2264e5e44163c2d
33
size 9068
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
set -eu -o pipefail
33

4-
git init -q
4+
git -c init.defaultBranch=special init -q

0 commit comments

Comments
 (0)