MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / require_clean_git_index

Function require_clean_git_index

atomic-cli/src/commands/git/shim.rs:3005–3037  ·  view source on GitHub ↗
(git: &GitRepository)

Source from the content-addressed store, hash-verified

3003}
3004
3005fn require_clean_git_index(git: &GitRepository) -> CliResult<()> {
3006 let index = git
3007 .index()
3008 .map_err(|error| git_error(format!("cannot read Git index: {error}")))?;
3009 if index.has_conflicts() {
3010 return Err(git_error("Git index contains unresolved conflicts"));
3011 }
3012 let mut options = GitStatusOptions::new();
3013 options
3014 .include_untracked(false)
3015 .recurse_untracked_dirs(false);
3016 let statuses = git
3017 .statuses(Some(&mut options))
3018 .map_err(|error| git_error(format!("cannot inspect Git status: {error}")))?;
3019 let staged: Vec<String> = statuses
3020 .iter()
3021 .filter(|entry| staged_delta(entry.status()))
3022 .map(|entry| {
3023 format!(
3024 "{:?} {}",
3025 entry.status(),
3026 entry.path().unwrap_or("<unnamed>")
3027 )
3028 })
3029 .collect();
3030 if !staged.is_empty() {
3031 return Err(git_error(format!(
3032 "Git index has staged changes: {}",
3033 staged.join("; ")
3034 )));
3035 }
3036 Ok(())
3037}
3038
3039fn staged_delta(status: Status) -> bool {
3040 status.intersects(

Callers 2

switch_transactionFunction · 0.85
project_atomic_to_gitFunction · 0.85

Calls 9

staged_deltaFunction · 0.85
include_untrackedMethod · 0.80
git_errorFunction · 0.70
indexMethod · 0.45
has_conflictsMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
statusMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected