Skip to content

Commit 7a3e783

Browse files
10ne1claude
andcommitted
gix: test rejection of objectFormat on version-0 repositories
Add fixtures with sha1 and sha256 variants and an open() test asserting that a version-0 repository setting extensions.objectFormat is rejected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
1 parent ccec5f5 commit 7a3e783

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

88.5 KB
Binary file not shown.
Binary file not shown.

gix/tests/fixtures/make_config_repos.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ mkdir not-a-repo-with-files;
165165
touch this that
166166
)
167167

168+
# objectFormat is a v1-only extension; a version-0 repo that sets it is invalid (even for sha1).
169+
# Reach that state with git config independently of the fixture's default hash: first make a valid
170+
# v1+objectFormat repo, then flip the version to 0 as the last write. The flip must come last because
171+
# git config refuses to run once the repo is already invalid (v0 with a v1-only extension).
172+
git init objectformat-without-v1-sha256
173+
(cd objectformat-without-v1-sha256
174+
git config core.repositoryFormatVersion 1
175+
git config extensions.objectFormat sha256
176+
git config core.repositoryFormatVersion 0
177+
)
178+
179+
git init objectformat-without-v1-sha1
180+
(cd objectformat-without-v1-sha1
181+
git config core.repositoryFormatVersion 1
182+
git config extensions.objectFormat sha1
183+
git config core.repositoryFormatVersion 0
184+
)
185+
168186
git init ssl-verify-disabled
169187
(cd ssl-verify-disabled
170188
git config http.sslVerify false

gix/tests/gix/repository/open.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,27 @@ mod not_a_repository {
354354
}
355355
}
356356

357+
mod object_format_extension {
358+
use crate::util::named_subrepo_opts;
359+
360+
#[test]
361+
fn rejects_object_format_on_v0_repo() -> crate::Result {
362+
// objectFormat on a version-0 repo is rejected, even for sha1, matching git.
363+
for name in ["objectformat-without-v1-sha256", "objectformat-without-v1-sha1"] {
364+
let err = named_subrepo_opts("make_config_repos.sh", name, gix::open::Options::isolated())
365+
.expect_err("a v0 repository setting extensions.objectFormat must be rejected");
366+
assert!(
367+
matches!(
368+
err,
369+
gix::open::Error::Config(gix::config::Error::ObjectFormatRequiresV1)
370+
),
371+
"objectFormat on a v0 repository must be rejected, got {err:?} for {name}"
372+
);
373+
}
374+
Ok(())
375+
}
376+
}
377+
357378
mod open_path_as_is {
358379

359380
use crate::util::{named_subrepo_opts, repo_opts};

0 commit comments

Comments
 (0)