Skip to content

Commit 89dcc8f

Browse files
o2shByron
andauthored
don't fail when computing diff on partial clones (#1093)
* Skip commit when computing diff if blob missing * add integration test * Assure that `changes()` don't track rewrites which accesses blobs; make filter=blob:none work. We reproduce the issue by triggering rename detection, which means a change happens on top of a rename. This tries to access blobs, and that doesn't always work. It's a good idea to disable rewrite tracking and an oversight in the initial implementation, and one might say it's tricky given that `gitoxide` automatically does what git does, which may be surprising sometimes and be a hidden cost even if it doesn't fail. --------- Co-authored-by: Sebastian Thiel <[email protected]>
1 parent 44651a1 commit 89dcc8f

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/info/git/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ fn compute_diff_with_parent(
249249
.into_tree()
250250
.changes()?
251251
.track_path()
252+
.track_rewrites(None)
252253
.for_each_to_obtain_tree(&commit.tree()?, |change| {
253254
let is_file_change = match change.event {
254255
Event::Addition { entry_mode, .. } | Event::Modification { entry_mode, .. } => {

tests/fixtures/make_partial_repo.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
mkdir base
5+
(cd base
6+
git init -q
7+
git checkout -b main
8+
touch code.rs
9+
git add code.rs
10+
git commit -q -m c1
11+
echo hello >> code.rs
12+
git add code.rs
13+
git commit -q -m c2
14+
echo world >> code.rs
15+
git add code.rs
16+
git commit -q -m c3
17+
echo something >> code.rs
18+
git add code.rs
19+
git commit -q -m c4
20+
echo more >> code.rs
21+
git mv code.rs renamed.rs
22+
echo change >> renamed.rs
23+
git commit -q -am c5
24+
25+
git config uploadpack.allowfilter true
26+
)
27+
28+
git clone --filter=blob:none file://$PWD/base partial
29+
(cd partial
30+
git config diff.renames true
31+
)

tests/repo.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ use onefetch::cli::{CliOptions, InfoCliOptions, TextForamttingCliOptions};
44
use onefetch::info::{build_info, get_work_dir};
55

66
fn repo(name: &str) -> Result<Repository> {
7-
let name = name.to_string();
87
let repo_path = gix_testtools::scripted_fixture_read_only(name).unwrap();
98
let safe_repo = ThreadSafeRepository::open_opts(repo_path, open::Options::isolated())?;
109
Ok(safe_repo.to_thread_local())
1110
}
1211

12+
pub fn named_repo(fixture: &str, name: &str) -> Result<Repository> {
13+
let repo_path = gix_testtools::scripted_fixture_read_only(fixture)
14+
.unwrap()
15+
.join(name);
16+
let safe_repo = ThreadSafeRepository::open_opts(repo_path, open::Options::isolated())?;
17+
Ok(safe_repo.to_thread_local())
18+
}
19+
1320
#[test]
1421
fn test_bare_repo() -> Result<()> {
1522
let repo = repo("bare_repo.sh")?;
@@ -65,3 +72,14 @@ fn test_repo_without_remote() -> Result<()> {
6572

6673
Ok(())
6774
}
75+
76+
#[test]
77+
fn test_partial_repo() -> Result<()> {
78+
let repo = named_repo("make_partial_repo.sh", "partial")?;
79+
let config: CliOptions = CliOptions {
80+
input: repo.path().to_path_buf(),
81+
..Default::default()
82+
};
83+
let _info = build_info(&config).expect("no error");
84+
Ok(())
85+
}

0 commit comments

Comments
 (0)