File tree 2 files changed +23
-2
lines changed
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ pub enum Error {
6
6
NegativeWithDestination ,
7
7
#[ error( "Negative specs must not be empty" ) ]
8
8
NegativeEmpty ,
9
+ #[ error( "Negative specs must be object hashes" ) ]
10
+ NegativeObjectHash ,
9
11
#[ error( "Cannot push into an empty destination" ) ]
10
12
PushToEmpty ,
11
13
#[ error( "glob patterns may only involved a single '*' character, found {pattern:?}" ) ]
@@ -88,8 +90,17 @@ pub(crate) mod function {
88
90
}
89
91
} ;
90
92
91
- if mode == Mode :: Negative && src. is_none ( ) {
92
- return Err ( Error :: NegativeEmpty ) ;
93
+ if mode == Mode :: Negative {
94
+ match src {
95
+ Some ( spec) => {
96
+ if spec. len ( ) >= git_hash:: Kind :: shortest ( ) . len_in_hex ( )
97
+ && spec. iter ( ) . all ( |b| b. is_ascii_hexdigit ( ) )
98
+ {
99
+ return Err ( Error :: NegativeObjectHash ) ;
100
+ }
101
+ }
102
+ None => return Err ( Error :: NegativeEmpty ) ,
103
+ }
93
104
}
94
105
95
106
if let Some ( spec) = src. as_mut ( ) {
Original file line number Diff line number Diff line change @@ -13,6 +13,16 @@ fn negative_must_not_be_empty() {
13
13
}
14
14
}
15
15
16
+ #[ test]
17
+ fn negative_must_not_be_object_hash ( ) {
18
+ for op in [ Operation :: Fetch , Operation :: Push ] {
19
+ assert ! ( matches!(
20
+ try_parse( "^e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" , op) . unwrap_err( ) ,
21
+ Error :: NegativeObjectHash
22
+ ) ) ;
23
+ }
24
+ }
25
+
16
26
#[ test]
17
27
fn negative_with_destination ( ) {
18
28
for op in [ Operation :: Fetch , Operation :: Push ] {
You can’t perform that action at this time.
0 commit comments