Skip to content

Commit b123b4c

Browse files
cruesslerByron
authored andcommitted
feat! add object_hash to gix::create::Options
Use `GIX_TEST_FIXTURE_HASH` for `gix` tests
1 parent 575113d commit b123b4c

32 files changed

Lines changed: 201 additions & 135 deletions

gix/src/create.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ pub struct Options {
117117
/// If set, use these filesystem capabilities to populate the respective git-config fields.
118118
/// If `None`, the directory will be probed.
119119
pub fs_capabilities: Option<gix_fs::Capabilities>,
120+
/// If set to `Some(Sha256)`, initialize the repository with SHA-256.
121+
/// Otherwise, no object hash will be explicitly set for the repository.
122+
pub object_hash: Option<gix_hash::Kind>,
120123
}
121124

122125
/// Create a new `.git` repository of `kind` within the possibly non-existing `directory`
@@ -130,6 +133,7 @@ pub fn into(
130133
Options {
131134
fs_capabilities,
132135
destination_must_be_empty,
136+
object_hash,
133137
}: Options,
134138
) -> Result<gix_discover::repository::Path, Error> {
135139
let mut dot_git = directory.into();
@@ -214,13 +218,30 @@ pub fn into(
214218
let caps = fs_capabilities.unwrap_or_else(|| gix_fs::Capabilities::probe(&dot_git));
215219
let mut core = config.new_section("core", None).expect("valid section name");
216220

217-
core.push(key("repositoryformatversion"), Some("0".into()));
218221
core.push(key("filemode"), Some(bool(caps.executable_bit).into()));
219222
core.push(key("bare"), Some(bool(bare).into()));
220223
core.push(key("logallrefupdates"), Some(bool(!bare).into()));
221224
core.push(key("symlinks"), Some(bool(caps.symlink).into()));
222225
core.push(key("ignorecase"), Some(bool(caps.ignore_case).into()));
223226
core.push(key("precomposeunicode"), Some(bool(caps.precompose_unicode).into()));
227+
228+
match object_hash {
229+
#[cfg(feature = "sha256")]
230+
Some(gix_hash::Kind::Sha256) => {
231+
core.push(key("repositoryformatversion"), Some("1".into()));
232+
233+
let mut extensions = config.new_section("extensions", None).expect("valid section name");
234+
235+
extensions.push(
236+
key("objectformat"),
237+
Some(gix_hash::Kind::Sha256.to_string().as_bytes().into()),
238+
);
239+
}
240+
_ => {
241+
core.push(key("repositoryformatversion"), Some("0".into()));
242+
}
243+
}
244+
224245
caps
225246
};
226247
config_file

gix/tests/fixtures/generated-archives/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,48 @@
88
# `git worktree add` writes absolute paths into `.git/worktrees/<name>/gitdir`
99
# and the worktree's `.git` pointer file; both shared with the `_bare` variant.
1010
/make_worktree_repo.tar
11+
/make_worktree_repo_sha256.tar
1112
/make_worktree_repo_bare.tar
13+
/make_worktree_repo_bare_sha256.tar
1214
# Same as above, plus per-worktree config created via `extensions.worktreeConfig`.
1315
/make_worktree_repo_with_configs.tar
16+
/make_worktree_repo_with_configs_sha256.tar
1417
# `git clone --shared file://$PWD/base` records the host-absolute alternates
1518
# path; numerous sub-clones inherit that reference.
1619
/make_remote_repos.tar
20+
/make_remote_repos_sha256.tar
1721
# Shallow clone created with `file://$remote`; `.git/shallow` and the alternates
1822
# record the host path of the source repo (this is the fixture called out in
1923
# issue #2316 / PR #2229 as a candidate for future commitment if those host
2024
# paths can be removed).
2125
/make_complex_shallow_repo.tar
26+
/make_complex_shallow_repo_sha256.tar
2227
# Clones from a host-supplied base repo path (`$1`); the resulting alternates
2328
# embed that absolute path.
2429
/make_fetch_repos.tar
30+
/make_fetch_repos_sha256.tar
2531
# Sets `core.worktree` to `$PWD/worktree` (an absolute path) on multiple
2632
# clones to test relative-vs-absolute worktree resolution.
2733
/make_core_worktree_repo.tar
34+
/make_core_worktree_repo_sha256.tar
2835
# Writes `global.config`/`system.config` files whose absolute paths the test
2936
# injects via `GIT_CONFIG_GLOBAL`/`GIT_CONFIG_SYSTEM`; the path layout must
3037
# match the host running the test.
3138
/make_signatures_repo.tar
39+
/make_signatures_repo_sha256.tar
3240
# Reads tree blobs/messages from `$ROOT/assets/...` (a host-absolute path) via
3341
# `git update-index --index-info` to build commits.
3442
/make_diff_repos.tar
43+
/make_diff_repos_sha256.tar
3544
# `git submodule add` with relative path produces `.git/modules/<name>/config`
3645
# entries containing host-absolute worktree paths; also adds a worktree.
3746
/make_submodule_with_worktree.tar
47+
/make_submodule_with_worktree_sha256.tar
3848
# Uses `mkfifo`, `ln -s`, executable-bit changes, and adds a submodule —
3949
# none of which round-trip cleanly through a committed tar across platforms.
4050
/repo_with_untracked_files.tar
51+
/repo_with_untracked_files_sha256.tar
4152
# Adds a linked worktree (host-absolute paths in `.git/worktrees/<name>/gitdir`)
4253
# alongside `.git/info/exclude` content.
4354
/make_worktree_repo_with_info_exclude.tar
55+
/make_worktree_repo_with_info_exclude_sha256.tar
91 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
318 KB
Binary file not shown.

0 commit comments

Comments
 (0)