History

Add test which shows that we don't allow disambiguation of by type yet (#427)

Implementing this would mean some work but also it seems git doesn't implement this very well as it only seems to partially work. Let's leave this for another day.

Sebastian Thiel committed 4 years ago

Commit 9d2e1eb1 parent 7c8e3f23 files · +44 −10Browse files

Unified · Split

3 files
  1. git-repository/tests/fixtures/generated-archives/make_rev_spec_parse_repos.tar.xz +2 −2
  2. git-repository/tests/fixtures/make_rev_spec_parse_repos.sh +26 −4
  3. git-repository/tests/rev_spec/mod.rs +16 −4
git-repository/tests/fixtures/generated-archives/make_rev_spec_parse_repos.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:b1802bce6989853af220cc07b5f3f35324fb5d5c4f6df4eeeb3618ab00c7c0ef2oid sha256:180bc7507bb13b56f26841ab6591582a1b021ae62f42a0b5a88098d2ad7b2fda
3size 102643size 11076
git-repository/tests/fixtures/make_rev_spec_parse_repos.sh+26−4
@@ -11,7 +11,7 @@ function baseline() { · 10 unmodified lines
11 }>> "$ROOT/baseline.git"11 }>> "$ROOT/baseline.git"
12}12}
13 13
14# based on https://github.com/git/git/blob/8168d5e9c23ed44ae3d604f392320d66556453c9/t/t1512-rev-parse-disambiguation.sh#L3814# The contents of this file is based on https://github.com/git/git/blob/8168d5e9c23ed44ae3d604f392320d66556453c9/t/t1512-rev-parse-disambiguation.sh#L38
15git init --bare blob.prefix15git init --bare blob.prefix
16(16(
17 cd blob.prefix17 cd blob.prefix
@@ -31,6 +31,7 @@ git init --bare blob.bad · 13 unmodified lines
31(31(
32 cd blob.bad32 cd blob.bad
33 # Both have the prefix "bad0"33 # Both have the prefix "bad0"
34 # Maybe one day we have a test to see how disambiguation reporting deals with this.
34 echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally35 echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally
35 echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally36 echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally
36 baseline "bad0"37 baseline "bad0"
@@ -48,14 +49,35 @@ function oid_to_path() { · 11 unmodified lines
48git init --bare blob.corrupt49git init --bare blob.corrupt
49(50(
50 cd blob.corrupt51 cd blob.corrupt
51 # Both have the prefix "cafe"52 # Both have the prefix "cafe".
53 # Maybe one day we have a test to see how disambiguation reporting deals with this.
54 echo bnkxmdwz | git hash-object -w --stdin
52 oid=$(echo bmwsjxzi | git hash-object -w --stdin)55 oid=$(echo bmwsjxzi | git hash-object -w --stdin)
53 oidf=objects/$(oid_to_path "$oid")56 oidf=objects/$(oid_to_path "$oid")
54 chmod 755 $oidf57 chmod 755 $oidf
55 echo broken >$oidf58 echo broken >$oidf
56 59
57 baseline "cafe"60 baseline "cafea"
58 baseline "cafe^{object}"61 baseline "cafea^{object}"
59)62)
60 63
64# This function writes out its parameters, one per line
65function write_lines () {
66 printf "%s\n" "$@"
67}
68
69git init ambiguous_blob_and_tree
70(
71 cd ambiguous_blob_and_tree
72 (
73 write_lines 0 1 2 3 4 5 6 7 8 9
74 echo
75 echo b1rwzyc3
76 ) >a0blgqsjc
77 # create one blob 0000000000b36
78 git add a0blgqsjc
79 # create one tree 0000000000cdc
80 git write-tree
61 81
82 baseline "0000000000"
83)
git-repository/tests/rev_spec/mod.rs+16−4
@@ -60,7 +60,8 @@ mod from_bytes { · 59 unmodified lines
60 let repo = repo("blob.prefix").unwrap();60 let repo = repo("blob.prefix").unwrap();
61 assert_eq!(61 assert_eq!(
62 parse_spec("dead", &repo).unwrap_err().to_string(),62 parse_spec("dead", &repo).unwrap_err().to_string(),
63 "Found more than one object prefixed with dead\nThe ref partially named 'dead' could not be found"63 "Found more than one object prefixed with dead\nThe ref partially named 'dead' could not be found",
64 "our messages aren't yet as good for ambiguous objects as we don't provide additional information"
64 );65 );
65 assert_eq!(66 assert_eq!(
66 parse_spec("beef", &repo).unwrap_err().to_string(),67 parse_spec("beef", &repo).unwrap_err().to_string(),
@@ -73,10 +74,21 @@ mod from_bytes { · 6 unmodified lines
73 assert_eq!(74 assert_eq!(
74 parse_spec("bad0", &repo).unwrap_err().to_string(),75 parse_spec("bad0", &repo).unwrap_err().to_string(),
75 "Found more than one object prefixed with bad0\nThe ref partially named 'bad0' could not be found",76 "Found more than one object prefixed with bad0\nThe ref partially named 'bad0' could not be found",
76 "git is able to also detect that the object has an invalid type, but we are not because the type doesn't matter here"77 "git is able to also detect that the object has an invalid type because it tries to provide additional context, we don't"
77 );78 );
78 }79 }
79 }80 }
81
82 #[test]
83 fn blob_and_tree_can_be_disambiguated_by_type_some_day() {
84 let repo = repo("ambiguous_blob_and_tree").unwrap();
85 assert_eq!(
86 parse_spec("0000000000", &repo).unwrap_err().to_string(),
87 "Found more than one object prefixed with 0000000000\nThe ref partially named '0000000000' could not be found",
88 concat!("in theory one could disambiguate with 0000000000^{{tree}} (which works in git) or 0000000000^{{blob}} which doesn't work for some reason.",
89 "but to do that we would have to know the list of object candidates and a lot more logic which right now we don't.")
90 );
91 }
80 }92 }
81 93
82 #[test]94 #[test]
@@ -98,13 +110,13 @@ mod from_bytes { · 15 unmodified lines
98 110
99 {111 {
100 let repo = repo("blob.corrupt").unwrap();112 let repo = repo("blob.corrupt").unwrap();
101 let spec = parse_spec("cafe", &repo).unwrap();113 let spec = parse_spec("cafea", &repo).unwrap();
102 assert_eq!(114 assert_eq!(
103 spec,115 spec,
104 RevSpec::from_id(hex_to_id("cafea31147e840161a1860c50af999917ae1536b").attach(&repo))116 RevSpec::from_id(hex_to_id("cafea31147e840161a1860c50af999917ae1536b").attach(&repo))
105 );117 );
106 assert_eq!(118 assert_eq!(
107 &format!("{:?}", parse_spec("cafe^{object}", &repo).unwrap_err())[..80],119 &format!("{:?}", parse_spec("cafea^{object}", &repo).unwrap_err())[..80],
108 r#"FindObject(Find(Loose(DecompressFile { source: Inflate(DecompressError(General {"#120 r#"FindObject(Find(Loose(DecompressFile { source: Inflate(DecompressError(General {"#
109 );121 );
110 }122 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t