Skip to content

Commit 42c977f

Browse files
committed
don't degenerate information about the unborn fetch ref's path. (#450)
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.
1 parent f1b5570 commit 42c977f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

git-protocol/src/fetch/refs/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ pub enum Ref {
7777
/// The hash of the object the `target` ref points to.
7878
object: git_hash::ObjectId,
7979
},
80-
/// `HEAD` is unborn on the remote and just points to the initial, unborn branch.
80+
/// A ref is unborn on the remote and just points to the initial, unborn branch, as is the case in a newly initialized repository
81+
/// or dangling symbolic refs.
8182
Unborn {
82-
/// The path of the ref the symbolic ref points to, like `refs/heads/main`.
83+
/// The name at which the ref is located, typically `HEAD`.
84+
full_ref_name: BString,
85+
/// The path of the ref the symbolic ref points to, like `refs/heads/main`, even though the `target` does not yet exist.
8386
target: BString,
8487
},
8588
}
@@ -100,7 +103,10 @@ impl Ref {
100103
tag: object,
101104
object: peeled,
102105
} => (full_ref_name.as_ref(), Some(object), Some(peeled)),
103-
Ref::Unborn { target: _ } => ("HEAD".into(), None, None),
106+
Ref::Unborn {
107+
full_ref_name,
108+
target: _,
109+
} => (full_ref_name.as_ref(), None, None),
104110
}
105111
}
106112
}

git-protocol/src/fetch/refs/shared.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ pub(in crate::fetch::refs) fn parse_v2(line: &str) -> Result<Ref, Error> {
207207
object: id,
208208
target: name.into(),
209209
},
210-
None => Ref::Unborn { target: name.into() },
210+
None => Ref::Unborn {
211+
full_ref_name: path.into(),
212+
target: name.into(),
213+
},
211214
},
212215
},
213216
_ => {

git-protocol/src/fetch/tests/refs.rs

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ async fn extract_references_from_v2_refs() {
88
let input = &mut "808e50d724f604f69ab93c6da2919c014667bedb HEAD symref-target:refs/heads/main
99
808e50d724f604f69ab93c6da2919c014667bedb MISSING_NAMESPACE_TARGET symref-target:(null)
1010
unborn HEAD symref-target:refs/heads/main
11+
unborn refs/heads/symbolic symref-target:refs/heads/target
1112
808e50d724f604f69ab93c6da2919c014667bedb refs/heads/main
1213
7fe1b98b39423b71e14217aa299a03b7c937d656 refs/tags/foo peeled:808e50d724f604f69ab93c6da2919c014667bedb
1314
7fe1b98b39423b71e14217aa299a03b7c937d6ff refs/tags/blaz
@@ -29,8 +30,13 @@ unborn HEAD symref-target:refs/heads/main
2930
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
3031
},
3132
Ref::Unborn {
33+
full_ref_name: "HEAD".into(),
3234
target: "refs/heads/main".into(),
3335
},
36+
Ref::Unborn {
37+
full_ref_name: "refs/heads/symbolic".into(),
38+
target: "refs/heads/target".into(),
39+
},
3440
Ref::Direct {
3541
full_ref_name: "refs/heads/main".into(),
3642
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")

0 commit comments

Comments
 (0)