@@ -31,7 +31,10 @@ fn baseline() {
31
31
match res {
32
32
Ok ( res) => match ( res. is_ok ( ) , err_code == 0 ) {
33
33
( true , true ) | ( false , false ) => { }
34
- _ => mismatch += 1 ,
34
+ _ => {
35
+ eprintln ! ( "{res:?} {err_code}" ) ;
36
+ mismatch += 1 ;
37
+ }
35
38
} ,
36
39
Err ( _) => {
37
40
panics += 1 ;
@@ -40,8 +43,11 @@ fn baseline() {
40
43
}
41
44
if panics != 0 || mismatch != 0 {
42
45
panic ! (
43
- "Out of {} baseline entries, got {} mismatches and {} panics" ,
44
- count, mismatch, panics
46
+ "Out of {} baseline entries, got {} right, ({} mismatches and {} panics)" ,
47
+ count,
48
+ count - ( mismatch + panics) ,
49
+ mismatch,
50
+ panics
45
51
) ;
46
52
}
47
53
}
@@ -68,11 +74,51 @@ mod invalid {
68
74
}
69
75
}
70
76
71
- mod fetch { }
77
+ mod fetch {
78
+ use crate :: parse:: { assert_parse, b} ;
79
+ use git_refspec:: { Fetch , Instruction } ;
80
+
81
+ #[ test]
82
+ fn empty_lhs_colon_rhs_fetches_head_to_destination ( ) {
83
+ assert_parse (
84
+ ":a" ,
85
+ Instruction :: Fetch ( Fetch :: AndUpdateSingle {
86
+ src : b ( "HEAD" ) ,
87
+ dst : b ( "a" ) ,
88
+ allow_non_fast_forward : false ,
89
+ } ) ,
90
+ ) ;
91
+
92
+ assert_parse (
93
+ "+:a" ,
94
+ Instruction :: Fetch ( Fetch :: AndUpdateSingle {
95
+ src : b ( "HEAD" ) ,
96
+ dst : b ( "a" ) ,
97
+ allow_non_fast_forward : true ,
98
+ } ) ,
99
+ ) ;
100
+ }
101
+
102
+ #[ test]
103
+ fn colon_alone_is_for_fetching_into_fetchhead ( ) {
104
+ assert_parse (
105
+ ":" ,
106
+ Instruction :: Fetch ( Fetch :: AllMatchingBranches {
107
+ allow_non_fast_forward : false ,
108
+ } ) ,
109
+ ) ;
110
+ assert_parse (
111
+ "+:" ,
112
+ Instruction :: Fetch ( Fetch :: AllMatchingBranches {
113
+ allow_non_fast_forward : true ,
114
+ } ) ,
115
+ ) ;
116
+ }
117
+ }
72
118
73
119
mod push {
74
- use crate :: parse:: assert_parse;
75
- use git_refspec:: { Instruction , Push } ;
120
+ use crate :: parse:: { assert_parse, b } ;
121
+ use git_refspec:: { Instruction , Mode , Push } ;
76
122
77
123
#[ test]
78
124
fn colon_alone_is_for_pushing_matching_refs ( ) {
@@ -89,23 +135,35 @@ mod invalid {
89
135
} ) ,
90
136
) ;
91
137
}
138
+
139
+ #[ test]
140
+ fn delete ( ) {
141
+ assert_parse ( ":a" , Instruction :: Push ( Push :: Delete { ref_or_pattern : b ( "a" ) } ) ) ;
142
+ let spec = assert_parse ( "+:a" , Instruction :: Push ( Push :: Delete { ref_or_pattern : b ( "a" ) } ) ) ;
143
+ assert_eq ! (
144
+ spec. mode( ) ,
145
+ Mode :: Force ,
146
+ "force is set, even though it has no effect in the actual instruction"
147
+ ) ;
148
+ }
92
149
}
93
150
}
94
151
95
152
mod util {
96
153
use git_refspec:: { Instruction , Operation , RefSpecRef } ;
97
154
98
- // pub fn b(input: &str) -> &bstr::BStr {
99
- // input.into()
100
- // }
155
+ pub fn b ( input : & str ) -> & bstr:: BStr {
156
+ input. into ( )
157
+ }
101
158
102
159
pub fn try_parse ( spec : & str , op : Operation ) -> Result < RefSpecRef < ' _ > , git_refspec:: parse:: Error > {
103
160
git_refspec:: parse ( spec. into ( ) , op)
104
161
}
105
162
106
- pub fn assert_parse ( spec : & str , expected : Instruction < ' _ > ) {
163
+ pub fn assert_parse < ' a > ( spec : & ' a str , expected : Instruction < ' _ > ) -> RefSpecRef < ' a > {
107
164
let spec = try_parse ( spec, expected. operation ( ) ) . expect ( "no error" ) ;
108
- assert_eq ! ( spec. instruction( ) , expected)
165
+ assert_eq ! ( spec. instruction( ) , expected) ;
166
+ spec
109
167
}
110
168
}
111
169
pub use util:: * ;
0 commit comments