Skip to content

Commit

Permalink
prepare test for handling the 'unborn' lsrefs extension (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 1, 2022
1 parent 02e37f0 commit 547e450
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
8 changes: 4 additions & 4 deletions git-repository/src/clone/fetch/util.rs
Expand Up @@ -59,7 +59,7 @@ pub fn update_head(
None => return Ok(()),
};

let name: git_ref::FullName = "HEAD".try_into().expect("valid");
let head: git_ref::FullName = "HEAD".try_into().expect("valid");
let reflog_message = || LogChange {
mode: RefLog::AndReference,
force_create_reflog: false,
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn update_head(
expected: PreviousValue::Any,
new: Target::Symbolic(referent),
},
name: name.clone(),
name: head.clone(),
deref: false,
},
],
Expand All @@ -116,7 +116,7 @@ pub fn update_head(
expected: PreviousValue::Any,
new: Target::Peeled(head_peeled_id.to_owned()),
},
name,
name: head,
deref: false,
})?;
}
Expand All @@ -127,7 +127,7 @@ pub fn update_head(
expected: PreviousValue::Any,
new: Target::Peeled(head_peeled_id.to_owned()),
},
name,
name: head,
deref: false,
})?;
}
Expand Down
1 change: 1 addition & 0 deletions git-repository/src/remote/fetch.rs
Expand Up @@ -53,6 +53,7 @@ impl Source {
match self {
Source::ObjectId(_) => None,
Source::Ref(r) => match r {
git_protocol::fetch::Ref::Unborn { target: _ } => Some("HEAD".into()),
git_protocol::fetch::Ref::Symbolic { full_ref_name, .. }
| git_protocol::fetch::Ref::Direct { full_ref_name, .. }
| git_protocol::fetch::Ref::Peeled { full_ref_name, .. } => Some(full_ref_name.as_ref()),
Expand Down
24 changes: 23 additions & 1 deletion git-repository/tests/clone/mod.rs
Expand Up @@ -193,19 +193,41 @@ mod blocking_io {
}

#[test]
#[ignore]
fn fetch_and_checkout_empty_remote_repo() -> crate::Result {
let tmp = git_testtools::tempfile::TempDir::new()?;
let mut prepare = git::prepare_clone(
git_testtools::scripted_fixture_repo_read_only("make_empty_repo.sh")?,
tmp.path(),
)?;
let (mut checkout, _out) = prepare
let (mut checkout, out) = prepare
.fetch_then_checkout(git::progress::Discard, &std::sync::atomic::AtomicBool::default())
.unwrap();
let (repo, _) = checkout.main_worktree(git::progress::Discard, &std::sync::atomic::AtomicBool::default())?;

assert!(!repo.index_path().is_file(), "newly initialized repos have no index");
assert!(repo.head()?.is_unborn());
if out
.ref_map
.handshake
.capabilities
.capability("ls-refs")
.expect("has ls-refs")
.supports("unborn")
== Some(true)
{
assert_eq!(
repo.head()?.referent_name().expect("present").as_bstr(),
"refs/heads/special",
"we pick up the name as present on the server, not the one we default to"
);
} else {
assert_eq!(
repo.head()?.referent_name().expect("present").as_bstr(),
"refs/heads/main",
"we simply keep our own post-init HEAD which defaults to the branch name we configured locally"
);
}

Ok(())
}
Expand Down
Git LFS file not shown
2 changes: 1 addition & 1 deletion git-repository/tests/fixtures/make_empty_repo.sh
@@ -1,4 +1,4 @@
#!/bin/bash
set -eu -o pipefail

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

0 comments on commit 547e450

Please sign in to comment.