History

fix: `HEAD` may now return itself as prefix in `RefSpecRef::prefix()` and `expanded_prefix()`. (#450)

Previously, the expanded prefix would be a list of possibilities, even though it's such a common case that we really want to avoid spamming the remote about it when asking for HEAD during clone for instance.

Sebastian Thiel committed 4 years ago

Commit d53ddcd1 parent 9d0f31e2 files · +13 −6Browse files

Unified · Split

2 files
  1. git-refspec/src/spec.rs +3 −0
  2. git-refspec/tests/spec/mod.rs +10 −6
git-refspec/src/spec.rs+3−0
@@ -134,6 +134,9 @@ impl<'a> RefSpecRef<'a> { · 133 unmodified lines
134134 Operation::Fetch => self.source(),
135135 Operation::Push => self.destination(),
136136 }?;
137+ if source == "HEAD" {
138+ return source.into();
139+ }
137140 let suffix = source.strip_prefix(b"refs/")?;
138141 let slash_pos = suffix.find_byte(b'/')?;
139142 let prefix = source[..="refs/".len() + slash_pos].as_bstr();
git-refspec/tests/spec/mod.rs+10−6
@@ -1,6 +1,11 @@
11 mod prefix {
22 use git_refspec::{parse::Operation, RefSpec};
33
4+ #[test]
5+ fn head_is_specifically_known() {
6+ assert_eq!(parse("HEAD").to_ref().prefix().unwrap(), "HEAD");
7+ }
8+
49 #[test]
510 fn partial_refs_have_no_prefix() {
611 assert_eq!(parse("main").to_ref().prefix(), None);
@@ -58,14 +63,13 @@ mod prefix { · 51 unmodified lines
5863 mod expand_prefixes {
5964 use git_refspec::parse::Operation;
6065
66+ #[test]
67+ fn head_is_specifically_known() {
68+ assert_eq!(parse("HEAD"), ["HEAD"]);
69+ }
70+
6171 #[test]
6272 fn partial_refs_have_many_prefixes() {
63− // "%.*s",
64− // "refs/%.*s",
65− // "refs/tags/%.*s",
66− // "refs/heads/%.*s",
67− // "refs/remotes/%.*s",
68− // "refs/remotes/%.*s/HEAD",
6973 assert_eq!(
7074 parse("main"),
7175 [