Skip to content

Commit

Permalink
more push-spec restrictions (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 7, 2022
1 parent 57a6e69 commit bb992ac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion git-refspec/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(crate) mod function {
*spec = "HEAD".into();
}
}
let (src, src_had_pattern) = validated(src, operation == Operation::Push)?;
let (src, src_had_pattern) = validated(src, operation == Operation::Push && dst.is_some())?;
let (dst, dst_had_pattern) = validated(dst, false)?;
if !dst_had_pattern && looks_like_object_hash(dst.unwrap_or_default()) {
return Err(Error::InvalidFetchDestination);
Expand Down
Git LFS file not shown
4 changes: 4 additions & 0 deletions git-refspec/tests/fixtures/make_baseline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ baseline push '^'

baseline fetch '^refs/heads/qa/*/*'
baseline push '^refs/heads/qa/*/*'
baseline push 'main~1'
baseline fetch 'main~1'
baseline push 'main~1:other~1'
baseline push ':main~1'

baseline push 'refs/heads/*:refs/remotes/frotz'
baseline push 'refs/heads:refs/remotes/frotz/*'
Expand Down
36 changes: 36 additions & 0 deletions git-refspec/tests/parse/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,42 @@ fn negative_unsupported() {
}
}

#[test]
fn revspecs_with_ref_name_destination() {
assert_parse(
"main~1:b",
Instruction::Push(Push::Matching {
src: b("main~1"),
dst: b("b"),
allow_non_fast_forward: false,
}),
);
assert_parse(
"+main~1:b",
Instruction::Push(Push::Matching {
src: b("main~1"),
dst: b("b"),
allow_non_fast_forward: true,
}),
);
}

#[test]
fn destinations_must_be_ref_names() {
assert!(matches!(
try_parse("a~1:b~1", Operation::Push).unwrap_err(),
Error::ReferenceName(_)
));
}

#[test]
fn single_refs_must_be_refnames() {
assert!(matches!(
try_parse("a~1", Operation::Push).unwrap_err(),
Error::ReferenceName(_)
));
}

#[test]
fn ampersand_is_resolved_to_head() {
assert_parse(
Expand Down

0 comments on commit bb992ac

Please sign in to comment.