…which should make it possible to adapt the previous one.
Showing the changes to git-diff (2 of 3 files). Show all
Unified · Split
| @@ -1,12 +1,18 @@ | ||
| 1 | 1 | #!/bin/bash |
| 2 | 2 | set -eu -o pipefail |
| 3 | 3 | |
| 4 | + | |
| 4 | 5 | git init -q |
| 5 | 6 | git config commit.gpgsign false |
| 6 | 7 | git config core.autocrlf false |
| 7 | 8 | |
| 8 | 9 | git checkout -q -b main |
| 9 | 10 | |
| 11 | +if [ -n "${1:-}" ]; then | |
| 12 | + mkdir "$1" | |
| 13 | + cd "$1" | |
| 14 | +fi | |
| 15 | + | |
| 10 | 16 | touch f |
| 11 | 17 | git add f |
| 12 | 18 | git commit -qm 'f added' |
| @@ -6,9 +6,9 @@ mod changes { · 5 unmodified lines | ||
| 6 | 6 | use git_object::{bstr::ByteSlice, tree::EntryMode}; |
| 7 | 7 | use git_odb::{linked, pack, Locate}; |
| 8 | 8 | |
| 9 | − fn db() -> crate::Result<linked::Db> { | |
| 9 | + fn db(args: impl IntoIterator<Item = &'static str>) -> crate::Result<linked::Db> { | |
| 10 | 10 | linked::Db::at( |
| 11 | − test_tools::scripted_fixture_repo_read_only("make_diff_repo.sh")? | |
| 11 | + test_tools::scripted_fixture_repo_read_only_with_args("make_diff_repo.sh", args)? | |
| 12 | 12 | .join(".git") |
| 13 | 13 | .join("objects"), |
| 14 | 14 | ) |
| @@ -92,7 +92,7 @@ mod changes { · 77 unmodified lines | ||
| 92 | 92 | |
| 93 | 93 | #[test] |
| 94 | 94 | fn many_different_states() -> crate::Result { |
| 95 | − let db = db()?; | |
| 95 | + let db = db(None)?; | |
| 96 | 96 | let all_commits = all_commits(&db); |
| 97 | 97 | assert_eq!( |
| 98 | 98 | diff_with_previous_commit_from(&db, &all_commits[0])?, |
| @@ -395,5 +395,29 @@ mod changes { · 296 unmodified lines | ||
| 395 | 395 | ); |
| 396 | 396 | Ok(()) |
| 397 | 397 | } |
| 398 | + | |
| 399 | + #[test] | |
| 400 | + fn many_different_states_nested() -> crate::Result { | |
| 401 | + let db = db(["a"].iter().copied())?; | |
| 402 | + let all_commits = all_commits(&db); | |
| 403 | + | |
| 404 | + assert_eq!( | |
| 405 | + diff_with_previous_commit_from(&db, &all_commits[0])?, | |
| 406 | + vec![ | |
| 407 | + recorder::Change::Addition { | |
| 408 | + entry_mode: EntryMode::Tree, | |
| 409 | + oid: hex_to_id("3d5a503f4062d198b443db5065ca727f8354e7df"), | |
| 410 | + path: "a".into() | |
| 411 | + }, | |
| 412 | + recorder::Change::Addition { | |
| 413 | + entry_mode: EntryMode::Blob, | |
| 414 | + oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"), | |
| 415 | + path: "a/f".into() | |
| 416 | + } | |
| 417 | + ], | |
| 418 | + ":000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A a/f" | |
| 419 | + ); | |
| 420 | + Ok(()) | |
| 421 | + } | |
| 398 | 422 | } |
| 399 | 423 | } |