Get repository status.
(repo_path: &Path)
| 420 | |
| 421 | /// Get repository status. |
| 422 | pub fn get_status(repo_path: &Path) -> Result<RepoStatus> { |
| 423 | let (success, stdout, _) = run_git(repo_path, &["rev-parse", "--abbrev-ref", "HEAD"])?; |
| 424 | let branch = if success { |
| 425 | stdout.trim().to_string() |
| 426 | } else { |
| 427 | "(detached)".to_string() |
| 428 | }; |
| 429 | |
| 430 | let (_, commit, _) = run_git(repo_path, &["log", "--oneline", "-1", "--no-decorate"])?; |
| 431 | let commit = commit.trim().to_string(); |
| 432 | |
| 433 | let (_, git_dir, _) = run_git(repo_path, &["rev-parse", "--git-dir"])?; |
| 434 | let is_worktree = git_dir.trim().contains(".git/worktrees"); |
| 435 | |
| 436 | let (_, status_output, _) = run_git(repo_path, &["status", "--porcelain", "--short"])?; |
| 437 | let dirty_count = status_output.lines().filter(|l| !l.is_empty()).count(); |
| 438 | let is_dirty = dirty_count > 0; |
| 439 | |
| 440 | Ok(RepoStatus { |
| 441 | branch, |
| 442 | commit, |
| 443 | is_worktree, |
| 444 | is_dirty, |
| 445 | dirty_count, |
| 446 | }) |
| 447 | } |
| 448 | |
| 449 | /// Commit information for log display. |
| 450 | #[derive(Debug, Clone)] |