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
134 Operation::Fetch => self.source(),134 Operation::Fetch => self.source(),
135 Operation::Push => self.destination(),135 Operation::Push => self.destination(),
136 }?;136 }?;
137 if source == "HEAD" {
138 return source.into();
139 }
137 let suffix = source.strip_prefix(b"refs/")?;140 let suffix = source.strip_prefix(b"refs/")?;
138 let slash_pos = suffix.find_byte(b'/')?;141 let slash_pos = suffix.find_byte(b'/')?;
139 let prefix = source[..="refs/".len() + slash_pos].as_bstr();142 let prefix = source[..="refs/".len() + slash_pos].as_bstr();
git-refspec/tests/spec/mod.rs+10−6
@@ -1,6 +1,11 @@
1mod prefix {1mod prefix {
2 use git_refspec::{parse::Operation, RefSpec};2 use git_refspec::{parse::Operation, RefSpec};
3 3
4 #[test]
5 fn head_is_specifically_known() {
6 assert_eq!(parse("HEAD").to_ref().prefix().unwrap(), "HEAD");
7 }
8
4 #[test]9 #[test]
5 fn partial_refs_have_no_prefix() {10 fn partial_refs_have_no_prefix() {
6 assert_eq!(parse("main").to_ref().prefix(), None);11 assert_eq!(parse("main").to_ref().prefix(), None);
@@ -58,14 +63,13 @@ mod prefix { · 51 unmodified lines
58mod expand_prefixes {63mod expand_prefixes {
59 use git_refspec::parse::Operation;64 use git_refspec::parse::Operation;
60 65
66 #[test]
67 fn head_is_specifically_known() {
68 assert_eq!(parse("HEAD"), ["HEAD"]);
69 }
70
61 #[test]71 #[test]
62 fn partial_refs_have_many_prefixes() {72 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",
69 assert_eq!(73 assert_eq!(
70 parse("main"),74 parse("main"),
71 [75 [