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.
Unified · Split
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | version https://git-lfs.github.com/spec/v1 |
| 2 | −oid sha256:b1802bce6989853af220cc07b5f3f35324fb5d5c4f6df4eeeb3618ab00c7c0ef | |
| 3 | −size 10264 | |
| 2 | +oid sha256:180bc7507bb13b56f26841ab6591582a1b021ae62f42a0b5a88098d2ad7b2fda | |
| 3 | +size 11076 | |
| @@ -11,7 +11,7 @@ function baseline() { · 10 unmodified lines | ||
| 11 | 11 | }>> "$ROOT/baseline.git" |
| 12 | 12 | } |
| 13 | 13 | |
| 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 | |
| 15 | 15 | git init --bare blob.prefix |
| 16 | 16 | ( |
| 17 | 17 | cd blob.prefix |
| @@ -31,6 +31,7 @@ git init --bare blob.bad · 13 unmodified lines | ||
| 31 | 31 | ( |
| 32 | 32 | cd blob.bad |
| 33 | 33 | # Both have the prefix "bad0" |
| 34 | + # Maybe one day we have a test to see how disambiguation reporting deals with this. | |
| 34 | 35 | echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally |
| 35 | 36 | echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally |
| 36 | 37 | baseline "bad0" |
| @@ -48,14 +49,35 @@ function oid_to_path() { · 11 unmodified lines | ||
| 48 | 49 | git init --bare blob.corrupt |
| 49 | 50 | ( |
| 50 | 51 | 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 | 55 | oid=$(echo bmwsjxzi | git hash-object -w --stdin) |
| 53 | 56 | oidf=objects/$(oid_to_path "$oid") |
| 54 | 57 | chmod 755 $oidf |
| 55 | 58 | echo broken >$oidf |
| 56 | 59 | |
| 57 | − baseline "cafe" | |
| 58 | − baseline "cafe^{object}" | |
| 60 | + baseline "cafea" | |
| 61 | + baseline "cafea^{object}" | |
| 59 | 62 | ) |
| 60 | 63 | |
| 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 | |
| 61 | 81 | |
| 82 | + baseline "0000000000" | |
| 83 | +) | |
| @@ -60,7 +60,8 @@ mod from_bytes { · 59 unmodified lines | ||
| 60 | 60 | let repo = repo("blob.prefix").unwrap(); |
| 61 | 61 | assert_eq!( |
| 62 | 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 | 66 | assert_eq!( |
| 66 | 67 | parse_spec("beef", &repo).unwrap_err().to_string(), |
| @@ -73,10 +74,21 @@ mod from_bytes { · 6 unmodified lines | ||
| 73 | 74 | assert_eq!( |
| 74 | 75 | parse_spec("bad0", &repo).unwrap_err().to_string(), |
| 75 | 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 | 94 | #[test] |
| @@ -98,13 +110,13 @@ mod from_bytes { · 15 unmodified lines | ||
| 98 | 110 | |
| 99 | 111 | { |
| 100 | 112 | let repo = repo("blob.corrupt").unwrap(); |
| 101 | − let spec = parse_spec("cafe", &repo).unwrap(); | |
| 113 | + let spec = parse_spec("cafea", &repo).unwrap(); | |
| 102 | 114 | assert_eq!( |
| 103 | 115 | spec, |
| 104 | 116 | RevSpec::from_id(hex_to_id("cafea31147e840161a1860c50af999917ae1536b").attach(&repo)) |
| 105 | 117 | ); |
| 106 | 118 | assert_eq!( |
| 107 | − &format!("{:?}", parse_spec("cafe^{object}", &repo).unwrap_err())[..80], | |
| 119 | + &format!("{:?}", parse_spec("cafea^{object}", &repo).unwrap_err())[..80], | |
| 108 | 120 | r#"FindObject(Find(Loose(DecompressFile { source: Inflate(DecompressError(General {"# |
| 109 | 121 | ); |
| 110 | 122 | } |