From c23a21d3e50e62d29bef4e638049b0398d3fb20e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 6 Aug 2022 20:10:15 +0800 Subject: [PATCH] tests causing all instrucitons (#450) --- git-refspec/src/spec.rs | 7 +++ git-refspec/tests/parse/mod.rs | 86 +++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/git-refspec/src/spec.rs b/git-refspec/src/spec.rs index d7c46c9c16..25e1ce5c74 100644 --- a/git-refspec/src/spec.rs +++ b/git-refspec/src/spec.rs @@ -17,6 +17,13 @@ impl RefSpecRef<'_> { match self.op { Operation::Fetch => match (self.mode, self.src, self.dst) { (Mode::Normal | Mode::Force, Some(src), None) => Instruction::Fetch(Fetch::Only { src }), + (Mode::Normal | Mode::Force, Some(src), Some(dst)) if has_pattern(src) => { + Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob { + src, + dst, + allow_non_fast_forward: matches!(self.mode, Mode::Force), + }) + } (Mode::Normal | Mode::Force, Some(src), Some(dst)) => Instruction::Fetch(Fetch::AndUpdateSingle { src, dst, diff --git a/git-refspec/tests/parse/mod.rs b/git-refspec/tests/parse/mod.rs index 2c2fa80126..6b2cdac8db 100644 --- a/git-refspec/tests/parse/mod.rs +++ b/git-refspec/tests/parse/mod.rs @@ -31,7 +31,11 @@ fn baseline() { let res = catch_unwind(|| try_parse(spec.to_str().unwrap(), op)); match res { Ok(res) => match (res.is_ok(), err_code == 0) { - (true, true) | (false, false) => {} + (true, true) | (false, false) => { + if let Ok(spec) = res { + spec.instruction(); // should not panic + } + } _ => { eprintln!("{err_code} {res:?} {} {:?}", kind.as_bstr(), spec.as_bstr()); mismatch += 1; @@ -132,6 +136,46 @@ mod fetch { ); } + #[test] + fn lhs_colon_rhs_updates_single_ref() { + assert_parse( + "a:b", + Instruction::Fetch(Fetch::AndUpdateSingle { + src: b("a"), + dst: b("b"), + allow_non_fast_forward: false, + }), + ); + assert_parse( + "+a:b", + Instruction::Fetch(Fetch::AndUpdateSingle { + src: b("a"), + dst: b("b"), + allow_non_fast_forward: true, + }), + ); + } + + #[test] + fn lhs_colon_rhs_with_glob_updates_multiple_refs() { + assert_parse( + "a/*:b/*", + Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob { + src: b("a/*"), + dst: b("b/*"), + allow_non_fast_forward: false, + }), + ); + assert_parse( + "+a/*:b/*", + Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob { + src: b("a/*"), + dst: b("b/*"), + allow_non_fast_forward: true, + }), + ); + } + #[test] fn empty_lhs_colon_rhs_fetches_head_to_destination() { assert_parse( @@ -180,6 +224,46 @@ mod push { assert_parse("^a*", Instruction::Push(Push::ExcludeMultipleWithGlob { src: b("a*") })); } + #[test] + fn lhs_colon_rhs_pushes_single_ref() { + assert_parse( + "a:b", + Instruction::Push(Push::Single { + src: b("a"), + dst: b("b"), + allow_non_fast_forward: false, + }), + ); + assert_parse( + "+a:b", + Instruction::Push(Push::Single { + src: b("a"), + dst: b("b"), + allow_non_fast_forward: true, + }), + ); + } + + #[test] + fn lhs_colon_rhs_with_glob_pushes_multiple_refs() { + assert_parse( + "a/*:b/*", + Instruction::Push(Push::MultipleWithGlob { + src: b("a/*"), + dst: b("b/*"), + allow_non_fast_forward: false, + }), + ); + assert_parse( + "+a/*:b/*", + Instruction::Push(Push::MultipleWithGlob { + src: b("a/*"), + dst: b("b/*"), + allow_non_fast_forward: true, + }), + ); + } + #[test] fn colon_alone_is_for_pushing_matching_refs() { assert_parse(