@@ -10,6 +10,8 @@ pub enum Error {
10
10
PatternUnsupported { pattern : bstr:: BString } ,
11
11
#[ error( "Both sides of the specification need a pattern, like 'a/*:b/*'" ) ]
12
12
PatternUnbalanced ,
13
+ #[ error( transparent) ]
14
+ Refname ( #[ from] git_validate:: refname:: Error ) ,
13
15
}
14
16
15
17
pub ( crate ) mod function {
@@ -19,6 +21,15 @@ pub(crate) mod function {
19
21
20
22
/// Parse `spec` for use in `operation` and return it if it is valid.
21
23
pub fn parse ( mut spec : & BStr , operation : Operation ) -> Result < RefSpecRef < ' _ > , Error > {
24
+ fn fetch_head_only ( mode : Mode ) -> RefSpecRef < ' static > {
25
+ RefSpecRef {
26
+ mode,
27
+ op : Operation :: Fetch ,
28
+ src : Some ( "HEAD" . into ( ) ) ,
29
+ dst : None ,
30
+ }
31
+ }
32
+
22
33
let mode = match spec. get ( 0 ) {
23
34
Some ( & b'^' ) => {
24
35
spec = & spec[ 1 ..] ;
@@ -32,12 +43,7 @@ pub(crate) mod function {
32
43
None => {
33
44
return match operation {
34
45
Operation :: Push => Err ( Error :: Empty ) ,
35
- Operation :: Fetch => Ok ( RefSpecRef {
36
- mode : Mode :: Normal ,
37
- op : operation,
38
- src : Some ( "HEAD" . into ( ) ) ,
39
- dst : None ,
40
- } ) ,
46
+ Operation :: Fetch => Ok ( fetch_head_only ( Mode :: Normal ) ) ,
41
47
}
42
48
}
43
49
} ;
@@ -68,7 +74,14 @@ pub(crate) mod function {
68
74
( Some ( src) , Some ( dst) ) => ( Some ( src) , Some ( dst) ) ,
69
75
}
70
76
}
71
- None => ( Some ( spec) , None ) ,
77
+ None => {
78
+ let src = ( !spec. is_empty ( ) ) . then ( || spec) ;
79
+ if Operation :: Fetch == operation && src. is_none ( ) {
80
+ return Ok ( fetch_head_only ( mode) ) ;
81
+ } else {
82
+ ( src, None )
83
+ }
84
+ }
72
85
} ;
73
86
74
87
let ( src, src_had_pattern) = validated ( src) ?;
@@ -91,6 +104,15 @@ pub(crate) mod function {
91
104
if glob_count == 2 {
92
105
return Err ( Error :: PatternUnsupported { pattern : spec. into ( ) } ) ;
93
106
}
107
+ if glob_count == 1 {
108
+ let mut buf = smallvec:: SmallVec :: < [ u8 ; 256 ] > :: with_capacity ( spec. len ( ) ) ;
109
+ buf. extend_from_slice ( & spec) ;
110
+ let glob_pos = buf. find_byte ( b'*' ) . expect ( "glob present" ) ;
111
+ buf[ glob_pos] = b'a' ;
112
+ git_validate:: reference:: name_partial ( buf. as_bstr ( ) ) ?;
113
+ } else {
114
+ git_validate:: reference:: name_partial ( spec) ?;
115
+ }
94
116
Ok ( ( Some ( spec) , glob_count == 1 ) )
95
117
}
96
118
None => Ok ( ( None , false ) ) ,
0 commit comments