(git: &GitRepository)
| 3003 | } |
| 3004 | |
| 3005 | fn 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 | |
| 3039 | fn staged_delta(status: Status) -> bool { |
| 3040 | status.intersects( |
no test coverage detected