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
113113 *spec = "HEAD".into();
114114 }
115115 }
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())?;
117117 let (dst, dst_had_pattern) = validated(dst, false)?;
118118 if !dst_had_pattern && looks_like_object_hash(dst.unwrap_or_default()) {
119119 return Err(Error::InvalidFetchDestination);
git-refspec/tests/fixtures/generated-archives/make_baseline.tar.xz+2−2
@@ -1,3 +1,3 @@
11 version https://git-lfs.github.com/spec/v1
2−oid sha256:3fe4f4ca2f442e58b594faaa0f512c6fdf1df8f052995928eca9bede909794e9
3−size 9360
2+oid sha256:9d52f5fe25601c545187b0ac19b004f30488937b6907e8206333d2ba923c7b29
3+size 9372
git-refspec/tests/fixtures/make_baseline.sh+4−0
@@ -40,6 +40,10 @@ baseline push '^' · 39 unmodified lines
4040
4141 baseline fetch '^refs/heads/qa/*/*'
4242 baseline push '^refs/heads/qa/*/*'
43+baseline push 'main~1'
44+baseline fetch 'main~1'
45+baseline push 'main~1:other~1'
46+baseline push ':main~1'
4347
4448 baseline push 'refs/heads/*:refs/remotes/frotz'
4549 baseline push 'refs/heads:refs/remotes/frotz/*'
git-refspec/tests/parse/push.rs+36−0
@@ -11,6 +11,42 @@ fn negative_unsupported() { · 10 unmodified lines
1111 }
1212 }
1313
14+#[test]
15+fn 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]
35+fn 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]
43+fn single_refs_must_be_refnames() {
44+ assert!(matches!(
45+ try_parse("a~1", Operation::Push).unwrap_err(),
46+ Error::ReferenceName(_)
47+ ));
48+}
49+
1450 #[test]
1551 fn ampersand_is_resolved_to_head() {
1652 assert_parse(