Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73a7393

Browse files
committed
keep-going support on the command-line (#301)
That way it's possible to see all the errors that happened which may help with debugging certain issues.
1 parent ecebc55 commit 73a7393

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

gitoxide-core/src/index/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use anyhow::bail;
22
use std::path::{Path, PathBuf};
33

44
use git_repository as git;
5+
use git_repository::worktree::index::checkout;
56
use git_repository::{odb::FindExt, Progress};
67

78
pub struct Options {
@@ -106,6 +107,7 @@ pub mod checkout_exclusive {
106107
pub index: super::Options,
107108
/// If true, all files will be written with zero bytes despite having made an ODB lookup.
108109
pub empty_files: bool,
110+
pub keep_going: bool,
109111
}
110112
}
111113

@@ -117,6 +119,7 @@ pub fn checkout_exclusive(
117119
checkout_exclusive::Options {
118120
index: Options { object_hash, .. },
119121
empty_files,
122+
keep_going,
120123
}: checkout_exclusive::Options,
121124
) -> anyhow::Result<()> {
122125
let repo = repo
@@ -157,6 +160,7 @@ pub fn checkout_exclusive(
157160
// TODO: turn the two following flags into an enum
158161
destination_is_initially_empty: true,
159162
overwrite_existing: false,
163+
keep_going,
160164
..Default::default()
161165
};
162166

@@ -168,7 +172,7 @@ pub fn checkout_exclusive(
168172
bytes.init(None, git::progress::bytes());
169173

170174
let start = std::time::Instant::now();
171-
match &repo {
175+
let checkout::Outcome { errors, collisions } = match &repo {
172176
Some(repo) => git::worktree::index::checkout(
173177
&mut index,
174178
dest_directory,
@@ -209,5 +213,19 @@ pub fn checkout_exclusive(
209213
entries_for_checkout,
210214
repo.is_none().then(|| "empty").unwrap_or_default()
211215
));
216+
217+
if !(collisions.is_empty() && errors.is_empty()) {
218+
let mut messages = Vec::new();
219+
if !errors.is_empty() {
220+
messages.push(format!("kept going through {} errors(s)", errors.len()));
221+
}
222+
if !collisions.is_empty() {
223+
messages.push(format!("encountered {} collision(s)", collisions.len()));
224+
}
225+
bail!(
226+
"One or more errors occurred - checkout is incomplete: {}",
227+
messages.join(", ")
228+
);
229+
}
212230
Ok(())
213231
}

src/plumbing/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub fn main() -> Result<()> {
8282
directory,
8383
empty_files,
8484
repository,
85+
keep_going,
8586
} => prepare_and_run(
8687
"index-checkout",
8788
verbose,
@@ -97,6 +98,7 @@ pub fn main() -> Result<()> {
9798
core::index::checkout_exclusive::Options {
9899
index: core::index::Options { object_hash, format },
99100
empty_files,
101+
keep_going,
100102
},
101103
)
102104
},

src/plumbing/options.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ pub mod index {
413413
/// in the index. Use this measure the impact on extracting objects on overall performance.
414414
#[clap(long, short = 'r')]
415415
repository: Option<PathBuf>,
416+
/// Ignore errors and keep checking out as many files as possible, and report all errors at the end of the operation.
417+
#[clap(long, short = 'k')]
418+
keep_going: bool,
416419
/// Enable to query the object database yet write only empty files. This is useful to measure the overhead of ODB query
417420
/// compared to writing the bytes to disk.
418421
#[clap(long, short = 'e', requires = "repository")]

0 commit comments

Comments
 (0)