Skip to content

Commit 1ac2c21

Browse files
committed
Add 'index verify' subcommand to 'gix' (#293)
1 parent 2d101eb commit 1ac2c21

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

gitoxide-core/src/index/mod.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,43 @@ mod entries;
1111

1212
pub mod information;
1313

14-
#[cfg_attr(not(feature = "serde1"), allow(unused_variables))]
14+
pub fn verify(
15+
index_path: impl AsRef<Path>,
16+
mut out: impl std::io::Write,
17+
Options { object_hash, format }: Options,
18+
) -> anyhow::Result<()> {
19+
let file = parse_file(index_path, object_hash)?;
20+
file.verify_integrity()?;
21+
file.verify_entries()?;
22+
#[cfg_attr(not(feature = "serde1"), allow(irrefutable_let_patterns))]
23+
if let crate::OutputFormat::Human = format {
24+
writeln!(out, "OK").ok();
25+
}
26+
Ok(())
27+
}
28+
29+
#[cfg_attr(not(feature = "serde1"), allow(unused_variables, unused_mut))]
1530
pub fn information(
1631
index_path: impl AsRef<Path>,
1732
out: impl std::io::Write,
33+
mut err: impl std::io::Write,
1834
information::Options {
19-
index: Options { object_hash, format },
35+
index: Options {
36+
object_hash,
37+
mut format,
38+
},
2039
extension_details,
2140
}: information::Options,
2241
) -> anyhow::Result<()> {
2342
use crate::OutputFormat::*;
43+
#[cfg(feature = "serde1")]
44+
if let Human = format {
45+
writeln!(err, "Defaulting to JSON printing as nothing else will be implemented.").ok();
46+
format = Json;
47+
}
2448
match format {
2549
Human => {
26-
anyhow::bail!("Only JSON output is implemented");
50+
anyhow::bail!("Cannot print information using 'human' format.")
2751
}
2852
#[cfg(feature = "serde1")]
2953
Json => {

src/plumbing/main.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ pub fn main() -> Result<()> {
8484
progress,
8585
progress_keep_open,
8686
None,
87-
move |_progress, out, _err| {
87+
move |_progress, out, err| {
8888
core::index::information(
8989
index_path,
9090
out,
91+
err,
9192
core::index::information::Options {
9293
index: core::index::Options { object_hash, format },
9394
extension_details: !no_details,
@@ -105,6 +106,16 @@ pub fn main() -> Result<()> {
105106
core::index::entries(index_path, out, core::index::Options { object_hash, format })
106107
},
107108
),
109+
index::Subcommands::Verify => prepare_and_run(
110+
"index-verify",
111+
verbose,
112+
progress,
113+
progress_keep_open,
114+
None,
115+
move |_progress, out, _err| {
116+
core::index::verify(index_path, out, core::index::Options { object_hash, format })
117+
},
118+
),
108119
},
109120
Subcommands::Repository(subcommands) => match subcommands {
110121
repo::Subcommands::Verify {

src/plumbing/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ pub mod index {
353353

354354
#[derive(Debug, clap::Subcommand)]
355355
pub enum Subcommands {
356+
/// Validate constraints and assumptions of an index along with its integrity.
357+
Verify,
356358
/// Print all entries to standard output
357359
Entries,
358360
/// Print information about the index structure

0 commit comments

Comments
 (0)