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 @@
11 version https://git-lfs.github.com/spec/v1
2−oid sha256:b1802bce6989853af220cc07b5f3f35324fb5d5c4f6df4eeeb3618ab00c7c0ef
3−size 10264
2+oid sha256:180bc7507bb13b56f26841ab6591582a1b021ae62f42a0b5a88098d2ad7b2fda
3+size 11076
git-repository/tests/fixtures/make_rev_spec_parse_repos.sh+26−4
@@ -11,7 +11,7 @@ function baseline() { · 10 unmodified lines
1111 }>> "$ROOT/baseline.git"
1212 }
1313
14−# based on https://github.com/git/git/blob/8168d5e9c23ed44ae3d604f392320d66556453c9/t/t1512-rev-parse-disambiguation.sh#L38
14+# The contents of this file is based on https://github.com/git/git/blob/8168d5e9c23ed44ae3d604f392320d66556453c9/t/t1512-rev-parse-disambiguation.sh#L38
1515 git init --bare blob.prefix
1616 (
1717 cd blob.prefix
@@ -31,6 +31,7 @@ git init --bare blob.bad · 13 unmodified lines
3131 (
3232 cd blob.bad
3333 # Both have the prefix "bad0"
34+ # Maybe one day we have a test to see how disambiguation reporting deals with this.
3435 echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally
3536 echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally
3637 baseline "bad0"
@@ -48,14 +49,35 @@ function oid_to_path() { · 11 unmodified lines
4849 git init --bare blob.corrupt
4950 (
5051 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
5255 oid=$(echo bmwsjxzi | git hash-object -w --stdin)
5356 oidf=objects/$(oid_to_path "$oid")
5457 chmod 755 $oidf
5558 echo broken >$oidf
5659
57− baseline "cafe"
58− baseline "cafe^{object}"
60+ baseline "cafea"
61+ baseline "cafea^{object}"
5962 )
6063
64+# This function writes out its parameters, one per line
65+function write_lines () {
66+ printf "%s\n" "$@"
67+}
68+
69+git 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
6181
82+ baseline "0000000000"
83+)
git-repository/tests/rev_spec/mod.rs+16−4
@@ -60,7 +60,8 @@ mod from_bytes { · 59 unmodified lines
6060 let repo = repo("blob.prefix").unwrap();
6161 assert_eq!(
6262 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"
6465 );
6566 assert_eq!(
6667 parse_spec("beef", &repo).unwrap_err().to_string(),
@@ -73,10 +74,21 @@ mod from_bytes { · 6 unmodified lines
7374 assert_eq!(
7475 parse_spec("bad0", &repo).unwrap_err().to_string(),
7576 "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"
7778 );
7879 }
7980 }
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+ }
8092 }
8193
8294 #[test]
@@ -98,13 +110,13 @@ mod from_bytes { · 15 unmodified lines
98110
99111 {
100112 let repo = repo("blob.corrupt").unwrap();
101− let spec = parse_spec("cafe", &repo).unwrap();
113+ let spec = parse_spec("cafea", &repo).unwrap();
102114 assert_eq!(
103115 spec,
104116 RevSpec::from_id(hex_to_id("cafea31147e840161a1860c50af999917ae1536b").attach(&repo))
105117 );
106118 assert_eq!(
107− &format!("{:?}", parse_spec("cafe^{object}", &repo).unwrap_err())[..80],
119+ &format!("{:?}", parse_spec("cafea^{object}", &repo).unwrap_err())[..80],
108120 r#"FindObject(Find(Loose(DecompressFile { source: Inflate(DecompressError(General {"#
109121 );
110122 }

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