Skip to content

Commit c23a21d

Browse files
committed
tests causing all instrucitons (#450)
1 parent c4499ce commit c23a21d

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

git-refspec/src/spec.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ impl RefSpecRef<'_> {
1717
match self.op {
1818
Operation::Fetch => match (self.mode, self.src, self.dst) {
1919
(Mode::Normal | Mode::Force, Some(src), None) => Instruction::Fetch(Fetch::Only { src }),
20+
(Mode::Normal | Mode::Force, Some(src), Some(dst)) if has_pattern(src) => {
21+
Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob {
22+
src,
23+
dst,
24+
allow_non_fast_forward: matches!(self.mode, Mode::Force),
25+
})
26+
}
2027
(Mode::Normal | Mode::Force, Some(src), Some(dst)) => Instruction::Fetch(Fetch::AndUpdateSingle {
2128
src,
2229
dst,

git-refspec/tests/parse/mod.rs

+85-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ fn baseline() {
3131
let res = catch_unwind(|| try_parse(spec.to_str().unwrap(), op));
3232
match res {
3333
Ok(res) => match (res.is_ok(), err_code == 0) {
34-
(true, true) | (false, false) => {}
34+
(true, true) | (false, false) => {
35+
if let Ok(spec) = res {
36+
spec.instruction(); // should not panic
37+
}
38+
}
3539
_ => {
3640
eprintln!("{err_code} {res:?} {} {:?}", kind.as_bstr(), spec.as_bstr());
3741
mismatch += 1;
@@ -132,6 +136,46 @@ mod fetch {
132136
);
133137
}
134138

139+
#[test]
140+
fn lhs_colon_rhs_updates_single_ref() {
141+
assert_parse(
142+
"a:b",
143+
Instruction::Fetch(Fetch::AndUpdateSingle {
144+
src: b("a"),
145+
dst: b("b"),
146+
allow_non_fast_forward: false,
147+
}),
148+
);
149+
assert_parse(
150+
"+a:b",
151+
Instruction::Fetch(Fetch::AndUpdateSingle {
152+
src: b("a"),
153+
dst: b("b"),
154+
allow_non_fast_forward: true,
155+
}),
156+
);
157+
}
158+
159+
#[test]
160+
fn lhs_colon_rhs_with_glob_updates_multiple_refs() {
161+
assert_parse(
162+
"a/*:b/*",
163+
Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob {
164+
src: b("a/*"),
165+
dst: b("b/*"),
166+
allow_non_fast_forward: false,
167+
}),
168+
);
169+
assert_parse(
170+
"+a/*:b/*",
171+
Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob {
172+
src: b("a/*"),
173+
dst: b("b/*"),
174+
allow_non_fast_forward: true,
175+
}),
176+
);
177+
}
178+
135179
#[test]
136180
fn empty_lhs_colon_rhs_fetches_head_to_destination() {
137181
assert_parse(
@@ -180,6 +224,46 @@ mod push {
180224
assert_parse("^a*", Instruction::Push(Push::ExcludeMultipleWithGlob { src: b("a*") }));
181225
}
182226

227+
#[test]
228+
fn lhs_colon_rhs_pushes_single_ref() {
229+
assert_parse(
230+
"a:b",
231+
Instruction::Push(Push::Single {
232+
src: b("a"),
233+
dst: b("b"),
234+
allow_non_fast_forward: false,
235+
}),
236+
);
237+
assert_parse(
238+
"+a:b",
239+
Instruction::Push(Push::Single {
240+
src: b("a"),
241+
dst: b("b"),
242+
allow_non_fast_forward: true,
243+
}),
244+
);
245+
}
246+
247+
#[test]
248+
fn lhs_colon_rhs_with_glob_pushes_multiple_refs() {
249+
assert_parse(
250+
"a/*:b/*",
251+
Instruction::Push(Push::MultipleWithGlob {
252+
src: b("a/*"),
253+
dst: b("b/*"),
254+
allow_non_fast_forward: false,
255+
}),
256+
);
257+
assert_parse(
258+
"+a/*:b/*",
259+
Instruction::Push(Push::MultipleWithGlob {
260+
src: b("a/*"),
261+
dst: b("b/*"),
262+
allow_non_fast_forward: true,
263+
}),
264+
);
265+
}
266+
183267
#[test]
184268
fn colon_alone_is_for_pushing_matching_refs() {
185269
assert_parse(

0 commit comments

Comments
 (0)