(git: &GitRepository)
| 3047 | } |
| 3048 | |
| 3049 | fn 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 | |
| 3083 | fn staged_delta(status: Status) -> bool { |
| 3084 | status.intersects( |
no test coverage detected