History

more push-spec restrictions (#450)

Sebastian Thiel committed 4 years ago

Commit bb992ac1 parent 57a6e694 files · +43 −3Browse files

Unified · Split

4 files
  1. git-refspec/src/parse.rs +1 −1
  2. git-refspec/tests/fixtures/generated-archives/make_baseline.tar.xz +2 −2
  3. git-refspec/tests/fixtures/make_baseline.sh +4 −0
  4. git-refspec/tests/parse/push.rs +36 −0
git-refspec/src/parse.rs+1−1
@@ -113,7 +113,7 @@ pub(crate) mod function { · 112 unmodified lines
113 *spec = "HEAD".into();113 *spec = "HEAD".into();
114 }114 }
115 }115 }
116 let (src, src_had_pattern) = validated(src, operation == Operation::Push)?;116 let (src, src_had_pattern) = validated(src, operation == Operation::Push && dst.is_some())?;
117 let (dst, dst_had_pattern) = validated(dst, false)?;117 let (dst, dst_had_pattern) = validated(dst, false)?;
118 if !dst_had_pattern && looks_like_object_hash(dst.unwrap_or_default()) {118 if !dst_had_pattern && looks_like_object_hash(dst.unwrap_or_default()) {
119 return Err(Error::InvalidFetchDestination);119 return Err(Error::InvalidFetchDestination);
git-refspec/tests/fixtures/generated-archives/make_baseline.tar.xz+2−2
@@ -1,3 +1,3 @@
1version https://git-lfs.github.com/spec/v11version https://git-lfs.github.com/spec/v1
2oid sha256:3fe4f4ca2f442e58b594faaa0f512c6fdf1df8f052995928eca9bede909794e92oid sha256:9d52f5fe25601c545187b0ac19b004f30488937b6907e8206333d2ba923c7b29
3size 93603size 9372
git-refspec/tests/fixtures/make_baseline.sh+4−0
@@ -40,6 +40,10 @@ baseline push '^' · 39 unmodified lines
40 40
41baseline fetch '^refs/heads/qa/*/*'41baseline fetch '^refs/heads/qa/*/*'
42baseline push '^refs/heads/qa/*/*'42baseline push '^refs/heads/qa/*/*'
43baseline push 'main~1'
44baseline fetch 'main~1'
45baseline push 'main~1:other~1'
46baseline push ':main~1'
43 47
44baseline push 'refs/heads/*:refs/remotes/frotz'48baseline push 'refs/heads/*:refs/remotes/frotz'
45baseline push 'refs/heads:refs/remotes/frotz/*'49baseline push 'refs/heads:refs/remotes/frotz/*'
git-refspec/tests/parse/push.rs+36−0
@@ -11,6 +11,42 @@ fn negative_unsupported() { · 10 unmodified lines
11 }11 }
12}12}
13 13
14#[test]
15fn revspecs_with_ref_name_destination() {
16 assert_parse(
17 "main~1:b",
18 Instruction::Push(Push::Matching {
19 src: b("main~1"),
20 dst: b("b"),
21 allow_non_fast_forward: false,
22 }),
23 );
24 assert_parse(
25 "+main~1:b",
26 Instruction::Push(Push::Matching {
27 src: b("main~1"),
28 dst: b("b"),
29 allow_non_fast_forward: true,
30 }),
31 );
32}
33
34#[test]
35fn destinations_must_be_ref_names() {
36 assert!(matches!(
37 try_parse("a~1:b~1", Operation::Push).unwrap_err(),
38 Error::ReferenceName(_)
39 ));
40}
41
42#[test]
43fn single_refs_must_be_refnames() {
44 assert!(matches!(
45 try_parse("a~1", Operation::Push).unwrap_err(),
46 Error::ReferenceName(_)
47 ));
48}
49
14#[test]50#[test]
15fn ampersand_is_resolved_to_head() {51fn ampersand_is_resolved_to_head() {
16 assert_parse(52 assert_parse(