docs: update readme with new installation methods and cli options

This commit is contained in:
2026-02-01 13:50:09 +00:00
parent dba6d94eab
commit bfc1812ebf
8 changed files with 531 additions and 86 deletions

View File

@@ -157,28 +157,19 @@ impl GitRepo {
/// Get staged diff
pub fn get_staged_diff(&self) -> Result<String> {
let head = self.repo.head().ok();
let head_tree = head.as_ref()
.and_then(|h| h.peel_to_tree().ok());
// Use git CLI to get staged diff for better compatibility
let output = std::process::Command::new("git")
.args(&["diff", "--cached"])
.current_dir(&self.path)
.output()
.with_context(|| "Failed to get staged diff with git command")?;
let mut index = self.repo.index()?;
let index_tree = index.write_tree()?;
let index_tree = self.repo.find_tree(index_tree)?;
let diff = if let Some(head) = head_tree {
self.repo.diff_tree_to_index(Some(&head), Some(&index), None)?
} else {
self.repo.diff_tree_to_index(None, Some(&index), None)?
};
let mut diff_text = String::new();
diff.print(git2::DiffFormat::Patch, |_delta, _hunk, line| {
if let Ok(content) = std::str::from_utf8(line.content()) {
diff_text.push_str(content);
}
true
})?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
bail!("Failed to get staged diff: {}", stderr);
}
let diff_text = String::from_utf8_lossy(&output.stdout).to_string();
Ok(diff_text)
}
@@ -277,6 +268,9 @@ impl GitRepo {
bail!("Failed to stage changes: {}", stderr);
}
// Force refresh the git2 index to pick up changes from git CLI
let _ = self.repo.index()?.write();
Ok(())
}
@@ -562,33 +556,50 @@ impl GitRepo {
/// Get repository status summary
pub fn status_summary(&self) -> Result<StatusSummary> {
let statuses = self.repo.statuses(Some(StatusOptions::new().include_untracked(true)))?;
// Use git CLI for more reliable status detection
let output = std::process::Command::new("git")
.args(&["status", "--porcelain"])
.current_dir(&self.path)
.output()
.with_context(|| "Failed to get status with git command")?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
bail!("Failed to get status: {}", stderr);
}
let stdout = String::from_utf8_lossy(&output.stdout);
let mut staged = 0;
let mut unstaged = 0;
let mut untracked = 0;
let mut conflicted = 0;
for entry in statuses.iter() {
let status = entry.status();
for line in stdout.lines() {
if line.len() >= 2 {
let index_status = line.chars().next().unwrap();
let worktree_status = line.chars().nth(1).unwrap();
if status.is_index_new() || status.is_index_modified() ||
status.is_index_deleted() || status.is_index_renamed() ||
status.is_index_typechange() {
staged += 1;
}
// Staged changes (first column not space)
if index_status != ' ' && index_status != '?' {
staged += 1;
}
if status.is_wt_modified() || status.is_wt_deleted() ||
status.is_wt_renamed() || status.is_wt_typechange() {
unstaged += 1;
}
// Unstaged changes (second column not space)
if worktree_status != ' ' && worktree_status != '?' {
unstaged += 1;
}
if status.is_wt_new() {
untracked += 1;
}
// Untracked files (both columns are ?)
if index_status == '?' && worktree_status == '?' {
untracked += 1;
}
if status.is_conflicted() {
conflicted += 1;
// Conflicted files (both columns are U or DD, AA, etc.)
if (index_status == 'U' || worktree_status == 'U') ||
(index_status == 'A' && worktree_status == 'A') ||
(index_status == 'D' && worktree_status == 'D') {
conflicted += 1;
}
}
}