feat(git): add rebase workflow with UI state handling
This introduces Git rebase commands (start, continue, abort) and exposes whether a rebase is currently in progress via the status payload. The UI now blocks committing during an active rebase and shows a dedicated rebase notice with continue/abort actions. - Add tauri commands for rebase operations and status detection - Update frontend to render rebase state and controls - Adjust conflict/resolution messaging and related UI styling
This commit is contained in:
@@ -47,6 +47,7 @@ pub struct GitStatus {
|
||||
pub behind: u32,
|
||||
pub files: Vec<GitFileStatus>,
|
||||
pub clean: bool,
|
||||
pub rebase_in_progress: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
@@ -1119,6 +1120,72 @@ pub fn merge_branch(path: String, branch: String) -> Result<GitStatus, String> {
|
||||
Err(format!("Merge failed: {details}"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn rebase_branch(path: String, branch: String) -> Result<GitStatus, String> {
|
||||
let repo = resolve_repo(&path)?;
|
||||
let branch = branch.trim();
|
||||
if branch.is_empty() {
|
||||
return Err("Branch name must not be empty.".to_string());
|
||||
}
|
||||
|
||||
let output = git_command()
|
||||
.arg("-C")
|
||||
.arg(&repo)
|
||||
.args(["rebase", branch])
|
||||
.output()
|
||||
.map_err(|err| format!("Could not start Git. Is Git installed? {err}"))?;
|
||||
|
||||
rebase_status_or_error(&repo, output, "Rebase failed", true)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn rebase_continue(path: String) -> Result<GitStatus, String> {
|
||||
let repo = resolve_repo(&path)?;
|
||||
if !rebase_in_progress(&repo) {
|
||||
return Err("No rebase is currently in progress.".to_string());
|
||||
}
|
||||
|
||||
let output = git_command()
|
||||
.arg("-C")
|
||||
.arg(&repo)
|
||||
.args(["rebase", "--continue"])
|
||||
.env("GIT_EDITOR", "true")
|
||||
.output()
|
||||
.map_err(|err| format!("Could not start Git. Is Git installed? {err}"))?;
|
||||
|
||||
rebase_status_or_error(&repo, output, "Rebase continue failed", false)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn rebase_abort(path: String) -> Result<GitStatus, String> {
|
||||
let repo = resolve_repo(&path)?;
|
||||
if !rebase_in_progress(&repo) {
|
||||
return Err("No rebase is currently in progress.".to_string());
|
||||
}
|
||||
|
||||
run_git(&repo, ["rebase", "--abort"])?;
|
||||
status_for_repo(&repo)
|
||||
}
|
||||
|
||||
fn rebase_status_or_error(
|
||||
repo: &Path,
|
||||
output: Output,
|
||||
context: &str,
|
||||
ok_if_rebase_in_progress: bool,
|
||||
) -> Result<GitStatus, String> {
|
||||
if output.status.success() {
|
||||
return status_for_repo(repo);
|
||||
}
|
||||
|
||||
let status = status_for_repo(repo)?;
|
||||
if has_unresolved_conflicts(&status) || (ok_if_rebase_in_progress && status.rebase_in_progress)
|
||||
{
|
||||
return Ok(status);
|
||||
}
|
||||
|
||||
Err(format!("{context}: {}", command_output_details(&output)))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn list_commits(path: String, limit: Option<u32>) -> Result<Vec<GitCommit>, String> {
|
||||
let repo = resolve_repo(&path)?;
|
||||
@@ -1953,9 +2020,30 @@ fn status_for_repo(repo: &Path) -> Result<GitStatus, String> {
|
||||
behind: branch.behind,
|
||||
clean: files.is_empty(),
|
||||
files,
|
||||
rebase_in_progress: rebase_in_progress(repo),
|
||||
})
|
||||
}
|
||||
|
||||
fn rebase_in_progress(repo: &Path) -> bool {
|
||||
git_path_exists(repo, "rebase-merge") || git_path_exists(repo, "rebase-apply")
|
||||
}
|
||||
|
||||
fn git_path_exists(repo: &Path, name: &str) -> bool {
|
||||
let Ok(output) = run_git(repo, ["rev-parse", "--git-path", name]) else {
|
||||
return false;
|
||||
};
|
||||
let value = String::from_utf8_lossy(&output).trim().to_string();
|
||||
if value.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let path = PathBuf::from(value);
|
||||
if path.is_absolute() {
|
||||
path.exists()
|
||||
} else {
|
||||
repo.join(path).exists()
|
||||
}
|
||||
}
|
||||
|
||||
// `git status` only auto-detects renames between HEAD and the index (staged changes).
|
||||
// A file renamed on disk but not yet `git add`ed shows up as a plain delete + untracked
|
||||
// pair instead. We detect that case ourselves by comparing content hashes: if an unstaged
|
||||
|
||||
Reference in New Issue
Block a user