Skip to content

Commit

Permalink
don't degenerate information about the unborn fetch ref's path. (#450)
Browse files Browse the repository at this point in the history
Previously we assumed this could only happen for `HEAD`, but in fact
dangling symrefs are possible and they might end up in the server
response that way.
  • Loading branch information
Byron committed Nov 2, 2022
1 parent f1b5570 commit 42c977f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 9 additions & 3 deletions git-protocol/src/fetch/refs/mod.rs
Expand Up @@ -77,9 +77,12 @@ pub enum Ref {
/// The hash of the object the `target` ref points to.
object: git_hash::ObjectId,
},
/// `HEAD` is unborn on the remote and just points to the initial, unborn branch.
/// A ref is unborn on the remote and just points to the initial, unborn branch, as is the case in a newly initialized repository
/// or dangling symbolic refs.
Unborn {
/// The path of the ref the symbolic ref points to, like `refs/heads/main`.
/// The name at which the ref is located, typically `HEAD`.
full_ref_name: BString,
/// The path of the ref the symbolic ref points to, like `refs/heads/main`, even though the `target` does not yet exist.
target: BString,
},
}
Expand All @@ -100,7 +103,10 @@ impl Ref {
tag: object,
object: peeled,
} => (full_ref_name.as_ref(), Some(object), Some(peeled)),
Ref::Unborn { target: _ } => ("HEAD".into(), None, None),
Ref::Unborn {
full_ref_name,
target: _,
} => (full_ref_name.as_ref(), None, None),
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion git-protocol/src/fetch/refs/shared.rs
Expand Up @@ -207,7 +207,10 @@ pub(in crate::fetch::refs) fn parse_v2(line: &str) -> Result<Ref, Error> {
object: id,
target: name.into(),
},
None => Ref::Unborn { target: name.into() },
None => Ref::Unborn {
full_ref_name: path.into(),
target: name.into(),
},
},
},
_ => {
Expand Down
6 changes: 6 additions & 0 deletions git-protocol/src/fetch/tests/refs.rs
Expand Up @@ -8,6 +8,7 @@ async fn extract_references_from_v2_refs() {
let input = &mut "808e50d724f604f69ab93c6da2919c014667bedb HEAD symref-target:refs/heads/main
808e50d724f604f69ab93c6da2919c014667bedb MISSING_NAMESPACE_TARGET symref-target:(null)
unborn HEAD symref-target:refs/heads/main
unborn refs/heads/symbolic symref-target:refs/heads/target
808e50d724f604f69ab93c6da2919c014667bedb refs/heads/main
7fe1b98b39423b71e14217aa299a03b7c937d656 refs/tags/foo peeled:808e50d724f604f69ab93c6da2919c014667bedb
7fe1b98b39423b71e14217aa299a03b7c937d6ff refs/tags/blaz
Expand All @@ -29,8 +30,13 @@ unborn HEAD symref-target:refs/heads/main
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
},
Ref::Unborn {
full_ref_name: "HEAD".into(),
target: "refs/heads/main".into(),
},
Ref::Unborn {
full_ref_name: "refs/heads/symbolic".into(),
target: "refs/heads/target".into(),
},
Ref::Direct {
full_ref_name: "refs/heads/main".into(),
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
Expand Down

0 comments on commit 42c977f

Please sign in to comment.