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:3049–3081  ·  view source on GitHub ↗
(git: &GitRepository)

Source from the content-addressed store, hash-verified

3047}
3048
3049fn require_clean_git_index(git: &GitRepository) -> CliResult<()> {
3050 let index = git
3051 .index()
3052 .map_err(|error| git_error(format!("cannot read Git index: {error}")))?;
3053 if index.has_conflicts() {
3054 return Err(git_error("Git index contains unresolved conflicts"));
3055 }
3056 let mut options = GitStatusOptions::new();
3057 options
3058 .include_untracked(false)
3059 .recurse_untracked_dirs(false);
3060 let statuses = git
3061 .statuses(Some(&mut options))
3062 .map_err(|error| git_error(format!("cannot inspect Git status: {error}")))?;
3063 let staged: Vec<String> = statuses
3064 .iter()
3065 .filter(|entry| staged_delta(entry.status()))
3066 .map(|entry| {
3067 format!(
3068 "{:?} {}",
3069 entry.status(),
3070 entry.path().unwrap_or("<unnamed>")
3071 )
3072 })
3073 .collect();
3074 if !staged.is_empty() {
3075 return Err(git_error(format!(
3076 "Git index has staged changes: {}",
3077 staged.join("; ")
3078 )));
3079 }
3080 Ok(())
3081}
3082
3083fn staged_delta(status: Status) -> bool {
3084 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