almost
This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
"allow": [
|
"allow": [
|
||||||
"Bash(cargo build *)",
|
"Bash(cargo build *)",
|
||||||
"Bash(npm run *)",
|
"Bash(npm run *)",
|
||||||
"Bash(kill %1)"
|
"Bash(kill %1)",
|
||||||
|
"Bash(perl -0pi -e 's/\\\\{line \\\\|\\\\| \" \"\\\\}/{displayLine\\(line\\) || \" \"}/g' src/App.svelte)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+143
-2
@@ -82,6 +82,15 @@ pub struct GitCommitComparison {
|
|||||||
pub patch: String,
|
pub patch: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||||
|
pub struct ConflictFile {
|
||||||
|
pub path: String,
|
||||||
|
pub content: String,
|
||||||
|
pub ours: Option<String>,
|
||||||
|
pub theirs: Option<String>,
|
||||||
|
pub base: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||||
pub struct GitRepositoryFile {
|
pub struct GitRepositoryFile {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
@@ -260,8 +269,39 @@ pub fn merge_branch(path: String, branch: String) -> Result<GitStatus, String> {
|
|||||||
return Err("Branch-Name darf nicht leer sein.".to_string());
|
return Err("Branch-Name darf nicht leer sein.".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
run_git(&repo, ["merge", "--no-edit", branch])?;
|
let output = Command::new("git")
|
||||||
status_for_repo(&repo)
|
.arg("-C")
|
||||||
|
.arg(&repo)
|
||||||
|
.args(["merge", "--no-edit", branch])
|
||||||
|
.output()
|
||||||
|
.map_err(|err| format!("Git konnte nicht gestartet werden. Ist Git installiert? {err}"))?;
|
||||||
|
|
||||||
|
if output.status.success() {
|
||||||
|
return status_for_repo(&repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A merge that stops on conflicts leaves unmerged paths in the work tree.
|
||||||
|
// Surface those through the status so the UI can offer conflict resolution
|
||||||
|
// instead of treating the conflict as a hard error.
|
||||||
|
let status = status_for_repo(&repo)?;
|
||||||
|
if status.files.iter().any(|file| {
|
||||||
|
matches!(file.staged, Some(FileStatusKind::Conflicted))
|
||||||
|
|| matches!(file.unstaged, Some(FileStatusKind::Conflicted))
|
||||||
|
}) {
|
||||||
|
return Ok(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
|
let details = if !stderr.trim().is_empty() {
|
||||||
|
stderr.trim()
|
||||||
|
} else if !stdout.trim().is_empty() {
|
||||||
|
stdout.trim()
|
||||||
|
} else {
|
||||||
|
"unbekannter Fehler"
|
||||||
|
};
|
||||||
|
|
||||||
|
Err(format!("Merge fehlgeschlagen: {details}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -435,6 +475,56 @@ pub fn diff_file_against_working_tree(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn read_conflict(path: String, file: String) -> Result<ConflictFile, String> {
|
||||||
|
let repo = resolve_repo(&path)?;
|
||||||
|
validate_files(std::slice::from_ref(&file))?;
|
||||||
|
|
||||||
|
let content = std::fs::read_to_string(repo.join(&file))
|
||||||
|
.map_err(|err| format!("Konfliktdatei konnte nicht gelesen werden: {err}"))?;
|
||||||
|
|
||||||
|
Ok(ConflictFile {
|
||||||
|
base: read_index_stage(&repo, 1, &file),
|
||||||
|
ours: read_index_stage(&repo, 2, &file),
|
||||||
|
theirs: read_index_stage(&repo, 3, &file),
|
||||||
|
path: file,
|
||||||
|
content,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn resolve_conflict(path: String, file: String, content: String) -> Result<GitStatus, String> {
|
||||||
|
let repo = resolve_repo(&path)?;
|
||||||
|
validate_files(std::slice::from_ref(&file))?;
|
||||||
|
|
||||||
|
let target = repo.join(&file);
|
||||||
|
if let Some(parent) = target.parent() {
|
||||||
|
std::fs::create_dir_all(parent)
|
||||||
|
.map_err(|err| format!("Verzeichnis konnte nicht erstellt werden: {err}"))?;
|
||||||
|
}
|
||||||
|
std::fs::write(&target, content)
|
||||||
|
.map_err(|err| format!("Konfliktdatei konnte nicht geschrieben werden: {err}"))?;
|
||||||
|
|
||||||
|
run_git_with_paths(&repo, &["add"], std::slice::from_ref(&file))?;
|
||||||
|
status_for_repo(&repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_index_stage(repo: &Path, stage: u8, file: &str) -> Option<String> {
|
||||||
|
let spec = format!(":{stage}:{file}");
|
||||||
|
let output = Command::new("git")
|
||||||
|
.arg("-C")
|
||||||
|
.arg(repo)
|
||||||
|
.args(["show", spec.as_str()])
|
||||||
|
.output()
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
|
if output.status.success() {
|
||||||
|
Some(String::from_utf8_lossy(&output.stdout).to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn short_hash(hash: &str) -> String {
|
fn short_hash(hash: &str) -> String {
|
||||||
hash.chars().take(7).collect()
|
hash.chars().take(7).collect()
|
||||||
}
|
}
|
||||||
@@ -1505,6 +1595,57 @@ mod tests {
|
|||||||
assert!(comparison.patch.contains("working tree change"));
|
assert!(comparison.patch.contains("working tree change"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_and_resolve_conflict_round_trip() {
|
||||||
|
let repo = init_temp_repo("resolve_conflict");
|
||||||
|
fs::write(repo.path.join("file.txt"), "base\n").expect("base file should be written");
|
||||||
|
run_git_test(&repo.path, ["add", "file.txt"]);
|
||||||
|
run_git_test(&repo.path, ["commit", "-q", "-m", "base"]);
|
||||||
|
let main_branch = git_output_test(&repo.path, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
||||||
|
|
||||||
|
run_git_test(&repo.path, ["checkout", "-q", "-b", "feature"]);
|
||||||
|
fs::write(repo.path.join("file.txt"), "theirs change\n").expect("feature change");
|
||||||
|
run_git_test(&repo.path, ["commit", "-q", "-am", "feature change"]);
|
||||||
|
|
||||||
|
run_git_test(&repo.path, ["checkout", "-q", main_branch.as_str()]);
|
||||||
|
fs::write(repo.path.join("file.txt"), "ours change\n").expect("main change");
|
||||||
|
run_git_test(&repo.path, ["commit", "-q", "-am", "main change"]);
|
||||||
|
|
||||||
|
// The merge is expected to fail with a conflict, so run git directly.
|
||||||
|
let _ = Command::new("git")
|
||||||
|
.arg("-C")
|
||||||
|
.arg(&repo.path)
|
||||||
|
.args(["merge", "--no-edit", "feature"])
|
||||||
|
.output()
|
||||||
|
.expect("git merge should start");
|
||||||
|
|
||||||
|
let conflict =
|
||||||
|
read_conflict(repo.path.to_string_lossy().to_string(), "file.txt".to_string()).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
conflict.ours.unwrap().replace("\r\n", "\n"),
|
||||||
|
"ours change\n"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
conflict.theirs.unwrap().replace("\r\n", "\n"),
|
||||||
|
"theirs change\n"
|
||||||
|
);
|
||||||
|
assert!(conflict.content.contains("<<<<<<<"));
|
||||||
|
|
||||||
|
let status = resolve_conflict(
|
||||||
|
repo.path.to_string_lossy().to_string(),
|
||||||
|
"file.txt".to_string(),
|
||||||
|
"resolved\n".to_string(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(!status.files.iter().any(|file| {
|
||||||
|
matches!(file.staged, Some(FileStatusKind::Conflicted))
|
||||||
|
|| matches!(file.unstaged, Some(FileStatusKind::Conflicted))
|
||||||
|
}));
|
||||||
|
let contents = fs::read_to_string(repo.path.join("file.txt")).unwrap();
|
||||||
|
assert_eq!(contents.replace("\r\n", "\n"), "resolved\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn restore_staged_added_file_removes_it_from_index_and_worktree() {
|
fn restore_staged_added_file_removes_it_from_index_and_worktree() {
|
||||||
let repo = init_temp_repo("restore_staged_added_file");
|
let repo = init_temp_repo("restore_staged_added_file");
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ mod git;
|
|||||||
use git::{
|
use git::{
|
||||||
checkout_branch, commit, compare_commits, diff_file_against_working_tree, get_status,
|
checkout_branch, commit, compare_commits, diff_file_against_working_tree, get_status,
|
||||||
list_branches, list_commits, list_file_history, list_repository_files, merge_branch,
|
list_branches, list_commits, list_file_history, list_repository_files, merge_branch,
|
||||||
open_repository, pull, push, restore_file_from_commit, restore_files, restore_to_commit,
|
open_repository, pull, push, read_conflict, resolve_conflict, restore_file_from_commit,
|
||||||
stage_files, unstage_files,
|
restore_files, restore_to_commit, stage_files, unstage_files,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -29,7 +29,9 @@ fn main() {
|
|||||||
list_repository_files,
|
list_repository_files,
|
||||||
list_file_history,
|
list_file_history,
|
||||||
compare_commits,
|
compare_commits,
|
||||||
diff_file_against_working_tree
|
diff_file_against_working_tree,
|
||||||
|
read_conflict,
|
||||||
|
resolve_conflict
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|||||||
+451
@@ -35,6 +35,8 @@
|
|||||||
openRepository,
|
openRepository,
|
||||||
pull,
|
pull,
|
||||||
push,
|
push,
|
||||||
|
readConflict,
|
||||||
|
resolveConflict,
|
||||||
restoreFileFromCommit,
|
restoreFileFromCommit,
|
||||||
restoreFiles,
|
restoreFiles,
|
||||||
restoreToCommit,
|
restoreToCommit,
|
||||||
@@ -42,6 +44,7 @@
|
|||||||
unstageFiles,
|
unstageFiles,
|
||||||
} from "./lib/git";
|
} from "./lib/git";
|
||||||
import type {
|
import type {
|
||||||
|
ConflictFile,
|
||||||
FileStatusKind,
|
FileStatusKind,
|
||||||
GitBranch as GitBranchInfo,
|
GitBranch as GitBranchInfo,
|
||||||
GitCommit,
|
GitCommit,
|
||||||
@@ -65,6 +68,12 @@
|
|||||||
children: ExplorerNode[];
|
children: ExplorerNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConflictChoice = "ours" | "theirs" | "both-ot" | "both-to";
|
||||||
|
|
||||||
|
type ConflictPart =
|
||||||
|
| { kind: "text"; lines: string[] }
|
||||||
|
| { kind: "conflict"; index: number; oursLines: string[]; theirsLines: string[] };
|
||||||
|
|
||||||
let repoPath = "";
|
let repoPath = "";
|
||||||
let activeRepoPath = "";
|
let activeRepoPath = "";
|
||||||
let status: GitStatus | null = null;
|
let status: GitStatus | null = null;
|
||||||
@@ -83,6 +92,13 @@
|
|||||||
let comparison: GitCommitComparison | null = null;
|
let comparison: GitCommitComparison | null = null;
|
||||||
let compareDialogOpen = false;
|
let compareDialogOpen = false;
|
||||||
let selectedDiffPath = "";
|
let selectedDiffPath = "";
|
||||||
|
let resolveDialogOpen = false;
|
||||||
|
let conflictTarget = "";
|
||||||
|
let conflict: ConflictFile | null = null;
|
||||||
|
let resolveContent = "";
|
||||||
|
let conflictParts: ConflictPart[] = [];
|
||||||
|
let conflictChoices: (ConflictChoice | null)[] = [];
|
||||||
|
let manualMode = false;
|
||||||
|
|
||||||
$: isBusy = operation.length > 0;
|
$: isBusy = operation.length > 0;
|
||||||
$: hasRepository = activeRepoPath.length > 0 && status !== null;
|
$: hasRepository = activeRepoPath.length > 0 && status !== null;
|
||||||
@@ -96,6 +112,18 @@
|
|||||||
compareTo.length > 0 &&
|
compareTo.length > 0 &&
|
||||||
compareFrom !== compareTo &&
|
compareFrom !== compareTo &&
|
||||||
!isBusy;
|
!isBusy;
|
||||||
|
$: conflictedFiles = changedFiles.filter(
|
||||||
|
(file) => file.staged === "conflicted" || file.unstaged === "conflicted",
|
||||||
|
);
|
||||||
|
$: hasConflicts = conflictedFiles.length > 0;
|
||||||
|
$: conflictRegionCount = conflictParts.filter((part) => part.kind === "conflict").length;
|
||||||
|
$: unresolvedCount = manualMode
|
||||||
|
? 0
|
||||||
|
: conflictChoices.filter((choice) => choice == null).length;
|
||||||
|
$: resolvedContent = manualMode
|
||||||
|
? resolveContent
|
||||||
|
: buildResolution(conflictParts, conflictChoices);
|
||||||
|
$: resolveHasMarkers = /^<{7}/m.test(resolvedContent) || /^>{7}/m.test(resolvedContent);
|
||||||
$: diffByPath = comparison ? buildDiffByPath(comparison.patch) : new Map<string, string>();
|
$: diffByPath = comparison ? buildDiffByPath(comparison.patch) : new Map<string, string>();
|
||||||
$: selectedDiffFile = comparison?.files.find((file) => file.path === selectedDiffPath) ?? null;
|
$: selectedDiffFile = comparison?.files.find((file) => file.path === selectedDiffPath) ?? null;
|
||||||
$: selectedDiffPatch = selectedDiffFile ? diffByPath.get(selectedDiffFile.path) ?? "" : "";
|
$: selectedDiffPatch = selectedDiffFile ? diffByPath.get(selectedDiffFile.path) ?? "" : "";
|
||||||
@@ -353,6 +381,13 @@
|
|||||||
comparison = null;
|
comparison = null;
|
||||||
compareDialogOpen = false;
|
compareDialogOpen = false;
|
||||||
selectedDiffPath = "";
|
selectedDiffPath = "";
|
||||||
|
resolveDialogOpen = false;
|
||||||
|
conflictTarget = "";
|
||||||
|
conflict = null;
|
||||||
|
resolveContent = "";
|
||||||
|
conflictParts = [];
|
||||||
|
conflictChoices = [];
|
||||||
|
manualMode = false;
|
||||||
await refreshBranchList(activeRepoPath);
|
await refreshBranchList(activeRepoPath);
|
||||||
await refreshCommitHistory(activeRepoPath);
|
await refreshCommitHistory(activeRepoPath);
|
||||||
await refreshExplorerFiles(activeRepoPath);
|
await refreshExplorerFiles(activeRepoPath);
|
||||||
@@ -601,6 +636,215 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadConflict(file: string) {
|
||||||
|
conflictTarget = file;
|
||||||
|
conflict = await readConflict(activeRepoPath, file);
|
||||||
|
conflictParts = parseConflicts(conflict.content);
|
||||||
|
conflictChoices = conflictParts.filter((part) => part.kind === "conflict").map(() => null);
|
||||||
|
manualMode = false;
|
||||||
|
resolveContent = conflict.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseConflicts(content: string): ConflictPart[] {
|
||||||
|
const lines = content.split("\n");
|
||||||
|
const parts: ConflictPart[] = [];
|
||||||
|
let textLines: string[] = [];
|
||||||
|
let regionIndex = 0;
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
|
const flushText = () => {
|
||||||
|
if (textLines.length > 0) {
|
||||||
|
parts.push({ kind: "text", lines: textLines });
|
||||||
|
textLines = [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
while (index < lines.length) {
|
||||||
|
const line = lines[index];
|
||||||
|
|
||||||
|
if (line.startsWith("<<<<<<<")) {
|
||||||
|
flushText();
|
||||||
|
index += 1;
|
||||||
|
|
||||||
|
const oursLines: string[] = [];
|
||||||
|
while (
|
||||||
|
index < lines.length &&
|
||||||
|
!lines[index].startsWith("=======") &&
|
||||||
|
!lines[index].startsWith("|||||||")
|
||||||
|
) {
|
||||||
|
oursLines.push(lines[index]);
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip the diff3 base section (||||||| ... =======) if present.
|
||||||
|
if (index < lines.length && lines[index].startsWith("|||||||")) {
|
||||||
|
index += 1;
|
||||||
|
while (index < lines.length && !lines[index].startsWith("=======")) {
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < lines.length && lines[index].startsWith("=======")) {
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const theirsLines: string[] = [];
|
||||||
|
while (index < lines.length && !lines[index].startsWith(">>>>>>>")) {
|
||||||
|
theirsLines.push(lines[index]);
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < lines.length && lines[index].startsWith(">>>>>>>")) {
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
parts.push({ kind: "conflict", index: regionIndex, oursLines, theirsLines });
|
||||||
|
regionIndex += 1;
|
||||||
|
} else {
|
||||||
|
textLines.push(line);
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flushText();
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildResolution(parts: ConflictPart[], choices: (ConflictChoice | null)[]): string {
|
||||||
|
const out: string[] = [];
|
||||||
|
|
||||||
|
for (const part of parts) {
|
||||||
|
if (part.kind === "text") {
|
||||||
|
out.push(...part.lines);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const choice = choices[part.index];
|
||||||
|
|
||||||
|
if (choice === "ours") {
|
||||||
|
out.push(...part.oursLines);
|
||||||
|
} else if (choice === "theirs") {
|
||||||
|
out.push(...part.theirsLines);
|
||||||
|
} else if (choice === "both-ot") {
|
||||||
|
out.push(...part.oursLines, ...part.theirsLines);
|
||||||
|
} else if (choice === "both-to") {
|
||||||
|
out.push(...part.theirsLines, ...part.oursLines);
|
||||||
|
} else {
|
||||||
|
// Unresolved: keep the conflict markers so it stays clearly flagged.
|
||||||
|
out.push(
|
||||||
|
"<<<<<<< current",
|
||||||
|
...part.oursLines,
|
||||||
|
"=======",
|
||||||
|
...part.theirsLines,
|
||||||
|
">>>>>>> incoming",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function setConflictChoice(index: number, choice: ConflictChoice) {
|
||||||
|
const next = [...conflictChoices];
|
||||||
|
next[index] = choice;
|
||||||
|
conflictChoices = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAllConflicts(choice: ConflictChoice) {
|
||||||
|
conflictChoices = conflictParts
|
||||||
|
.filter((part) => part.kind === "conflict")
|
||||||
|
.map(() => choice);
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableManualEdit() {
|
||||||
|
resolveContent = buildResolution(conflictParts, conflictChoices);
|
||||||
|
manualMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableManualEdit() {
|
||||||
|
manualMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayLine(line: string): string {
|
||||||
|
// Strip a trailing CR for display only; the stored line keeps it so the
|
||||||
|
// rebuilt file preserves its original line endings.
|
||||||
|
return line.replace(/\r$/, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function oursActive(choice: ConflictChoice | null): boolean {
|
||||||
|
return choice === "ours" || choice === "both-ot" || choice === "both-to";
|
||||||
|
}
|
||||||
|
|
||||||
|
function theirsActive(choice: ConflictChoice | null): boolean {
|
||||||
|
return choice === "theirs" || choice === "both-ot" || choice === "both-to";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openResolveDialog() {
|
||||||
|
if (!hasConflicts || isBusy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const first = conflictedFiles[0].path;
|
||||||
|
await runOperation("Loading conflicts", async () => {
|
||||||
|
resolveDialogOpen = true;
|
||||||
|
await loadConflict(first);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function selectConflictFile(file: string) {
|
||||||
|
if (file === conflictTarget || isBusy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await runOperation(`Loading ${file}`, async () => {
|
||||||
|
await loadConflict(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveResolution() {
|
||||||
|
if (!activeRepoPath || !conflictTarget || isBusy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
resolveHasMarkers &&
|
||||||
|
!window.confirm(
|
||||||
|
"Conflict markers (<<<<<<< / >>>>>>>) are still present. Mark this file as resolved anyway?",
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedPath = conflictTarget;
|
||||||
|
const content = resolvedContent;
|
||||||
|
await runOperation(`Resolving ${resolvedPath}`, async () => {
|
||||||
|
const nextStatus = await resolveConflict(activeRepoPath, resolvedPath, content);
|
||||||
|
applyStatus(nextStatus);
|
||||||
|
await refreshExplorerFiles(activeRepoPath);
|
||||||
|
await refreshFileHistory(activeRepoPath);
|
||||||
|
|
||||||
|
const remaining = nextStatus.files.filter(
|
||||||
|
(file) => file.staged === "conflicted" || file.unstaged === "conflicted",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (remaining.length === 0) {
|
||||||
|
resolveDialogOpen = false;
|
||||||
|
conflict = null;
|
||||||
|
conflictTarget = "";
|
||||||
|
resolveContent = "";
|
||||||
|
conflictParts = [];
|
||||||
|
conflictChoices = [];
|
||||||
|
manualMode = false;
|
||||||
|
} else {
|
||||||
|
await loadConflict(remaining[0].path);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeResolveDialog() {
|
||||||
|
resolveDialogOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
function closeCompareDialog() {
|
function closeCompareDialog() {
|
||||||
compareDialogOpen = false;
|
compareDialogOpen = false;
|
||||||
}
|
}
|
||||||
@@ -835,6 +1079,19 @@
|
|||||||
</section>
|
</section>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if hasConflicts}
|
||||||
|
<section class="notice conflict" role="alert">
|
||||||
|
<GitMerge size={17} aria-hidden="true" />
|
||||||
|
<span>
|
||||||
|
{conflictedFiles.length}
|
||||||
|
{conflictedFiles.length === 1 ? "file has" : "files have"} merge conflicts.
|
||||||
|
</span>
|
||||||
|
<button type="button" onclick={openResolveDialog} disabled={isBusy}>
|
||||||
|
Resolve conflicts
|
||||||
|
</button>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<section class="workspace" aria-label="Git workspace">
|
<section class="workspace" aria-label="Git workspace">
|
||||||
<aside class="left-sidebar" aria-label="Repository navigation">
|
<aside class="left-sidebar" aria-label="Repository navigation">
|
||||||
<section class="branches" aria-label="Branches">
|
<section class="branches" aria-label="Branches">
|
||||||
@@ -1347,6 +1604,200 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if resolveDialogOpen}
|
||||||
|
<div
|
||||||
|
class="dialog-backdrop"
|
||||||
|
role="presentation"
|
||||||
|
onclick={(event) => {
|
||||||
|
if (event.target === event.currentTarget) {
|
||||||
|
closeResolveDialog();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="dialog"
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-label="Resolve merge conflicts"
|
||||||
|
tabindex="-1"
|
||||||
|
>
|
||||||
|
<header class="dialog-header">
|
||||||
|
<div>
|
||||||
|
<span class="eyebrow">Resolve</span>
|
||||||
|
<h2 class="dialog-title">Merge conflicts</h2>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="dialog-close" onclick={closeResolveDialog} title="Close">
|
||||||
|
<X size={18} aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{#if conflictedFiles.length === 0}
|
||||||
|
<div class="blank-state">All conflicts resolved. You can commit the merge now.</div>
|
||||||
|
{:else}
|
||||||
|
<div class="dialog-body">
|
||||||
|
<aside class="dialog-files" aria-label="Conflicted files">
|
||||||
|
{#each conflictedFiles as file (file.path)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class:active={conflictTarget === file.path}
|
||||||
|
class="dialog-file-row"
|
||||||
|
onclick={() => selectConflictFile(file.path)}
|
||||||
|
disabled={isBusy}
|
||||||
|
title={file.path}
|
||||||
|
>
|
||||||
|
<span class="status-badge conflicted">conflicted</span>
|
||||||
|
<strong>{file.path}</strong>
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<div class="resolve-editor" aria-label="Conflict editor">
|
||||||
|
{#if !conflict}
|
||||||
|
<div class="blank-state">Select a file to resolve.</div>
|
||||||
|
{:else}
|
||||||
|
<div class="resolve-toolbar">
|
||||||
|
{#if manualMode}
|
||||||
|
<button type="button" onclick={disableManualEdit} disabled={isBusy}>
|
||||||
|
Back to guided
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
<span class="resolve-toolbar-label">Apply to all:</span>
|
||||||
|
<button type="button" onclick={() => setAllConflicts("ours")} disabled={isBusy}>
|
||||||
|
Current
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick={() => setAllConflicts("theirs")} disabled={isBusy}>
|
||||||
|
Incoming
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick={() => setAllConflicts("both-ot")} disabled={isBusy}>
|
||||||
|
Both
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick={enableManualEdit} disabled={isBusy}>
|
||||||
|
Edit manually
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<span class="resolve-status">
|
||||||
|
{#if unresolvedCount > 0}
|
||||||
|
<AlertCircle size={14} aria-hidden="true" />
|
||||||
|
{unresolvedCount} of {conflictRegionCount} unresolved
|
||||||
|
{:else if resolveHasMarkers}
|
||||||
|
<AlertCircle size={14} aria-hidden="true" />
|
||||||
|
Conflict markers still present
|
||||||
|
{:else}
|
||||||
|
<Check size={14} aria-hidden="true" />
|
||||||
|
{conflictRegionCount}
|
||||||
|
{conflictRegionCount === 1 ? "conflict" : "conflicts"} resolved
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if manualMode}
|
||||||
|
<textarea
|
||||||
|
class="resolve-textarea"
|
||||||
|
bind:value={resolveContent}
|
||||||
|
spellcheck="false"
|
||||||
|
disabled={isBusy}
|
||||||
|
></textarea>
|
||||||
|
{:else}
|
||||||
|
<div class="resolve-structured">
|
||||||
|
{#each conflictParts as part, partIndex (partIndex)}
|
||||||
|
{#if part.kind === "text"}
|
||||||
|
{#if part.lines.length > 0}
|
||||||
|
<pre class="resolve-context">{#each part.lines as line}<span
|
||||||
|
class="resolve-line context">{displayLine(line) || " "}</span>{/each}</pre>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<div
|
||||||
|
class="resolve-conflict"
|
||||||
|
class:unresolved={conflictChoices[part.index] == null}
|
||||||
|
>
|
||||||
|
<div class="resolve-conflict-bar">
|
||||||
|
<span class="resolve-conflict-label">Conflict {part.index + 1}</span>
|
||||||
|
<div class="resolve-choice-buttons">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class:active={conflictChoices[part.index] === "ours"}
|
||||||
|
onclick={() => setConflictChoice(part.index, "ours")}
|
||||||
|
disabled={isBusy}
|
||||||
|
>
|
||||||
|
Current
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class:active={conflictChoices[part.index] === "theirs"}
|
||||||
|
onclick={() => setConflictChoice(part.index, "theirs")}
|
||||||
|
disabled={isBusy}
|
||||||
|
>
|
||||||
|
Incoming
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class:active={conflictChoices[part.index] === "both-ot"}
|
||||||
|
onclick={() => setConflictChoice(part.index, "both-ot")}
|
||||||
|
disabled={isBusy}
|
||||||
|
title="Keep both — current first"
|
||||||
|
>
|
||||||
|
Both C+I
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class:active={conflictChoices[part.index] === "both-to"}
|
||||||
|
onclick={() => setConflictChoice(part.index, "both-to")}
|
||||||
|
disabled={isBusy}
|
||||||
|
title="Keep both — incoming first"
|
||||||
|
>
|
||||||
|
Both I+C
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="resolve-side ours"
|
||||||
|
class:dimmed={!oursActive(conflictChoices[part.index])}
|
||||||
|
>
|
||||||
|
<span class="resolve-side-label">Current (ours)</span>
|
||||||
|
<pre class="resolve-lines">{#each part.oursLines as line}<span
|
||||||
|
class="resolve-line ours">{displayLine(line) || " "}</span>{/each}</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="resolve-side theirs"
|
||||||
|
class:dimmed={!theirsActive(conflictChoices[part.index])}
|
||||||
|
>
|
||||||
|
<span class="resolve-side-label">Incoming (theirs)</span>
|
||||||
|
<pre class="resolve-lines">{#each part.theirsLines as line}<span
|
||||||
|
class="resolve-line theirs">{displayLine(line) || " "}</span>{/each}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="resolve-actions">
|
||||||
|
<span class="resolve-path" title={conflictTarget}>{conflictTarget}</span>
|
||||||
|
<button
|
||||||
|
class="primary-button"
|
||||||
|
type="button"
|
||||||
|
onclick={saveResolution}
|
||||||
|
disabled={isBusy}
|
||||||
|
>
|
||||||
|
{#if operation.startsWith("Resolving")}
|
||||||
|
<LoaderCircle class="spin" size={16} aria-hidden="true" />
|
||||||
|
{:else}
|
||||||
|
<Check size={16} aria-hidden="true" />
|
||||||
|
{/if}
|
||||||
|
Save & mark resolved
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<svelte:window on:keydown={handleWindowKeydown} />
|
<svelte:window on:keydown={handleWindowKeydown} />
|
||||||
|
|||||||
+227
@@ -161,6 +161,23 @@ textarea {
|
|||||||
background: #edf8fd;
|
background: #edf8fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notice.conflict {
|
||||||
|
border-color: #e3b778;
|
||||||
|
color: #8a4c0e;
|
||||||
|
background: #fff6e7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice.conflict button {
|
||||||
|
margin-left: auto;
|
||||||
|
min-height: 30px;
|
||||||
|
padding: 0 12px;
|
||||||
|
border-color: #e3b778;
|
||||||
|
color: #8a4c0e;
|
||||||
|
background: #ffffff;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
.workspace {
|
.workspace {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 340px minmax(0, 1fr);
|
grid-template-columns: 340px minmax(0, 1fr);
|
||||||
@@ -937,6 +954,216 @@ textarea {
|
|||||||
max-height: none;
|
max-height: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dialog-title {
|
||||||
|
margin: 2px 0 0;
|
||||||
|
color: #202326;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-editor {
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: auto minmax(0, 1fr) auto;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 10px;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-toolbar button {
|
||||||
|
min-height: 32px;
|
||||||
|
padding: 0 10px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-toolbar-label {
|
||||||
|
color: #596670;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-status {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
margin-left: auto;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #8a4c0e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-textarea {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #c4ccd3;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #ffffff;
|
||||||
|
color: #202326;
|
||||||
|
font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
tab-size: 2;
|
||||||
|
resize: none;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-structured {
|
||||||
|
display: grid;
|
||||||
|
align-content: start;
|
||||||
|
gap: 8px;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 4px;
|
||||||
|
overflow: auto;
|
||||||
|
border: 1px solid #dce1e5;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-context {
|
||||||
|
margin: 0;
|
||||||
|
padding: 2px 8px;
|
||||||
|
overflow-x: auto;
|
||||||
|
font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
tab-size: 2;
|
||||||
|
color: #3a444c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-conflict {
|
||||||
|
display: grid;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #e3b778;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fffaf1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-conflict.unresolved {
|
||||||
|
border-color: #d98b8b;
|
||||||
|
background: #fff5f3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-conflict-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-conflict-label {
|
||||||
|
color: #8a4c0e;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-choice-buttons {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-choice-buttons button {
|
||||||
|
min-height: 26px;
|
||||||
|
padding: 0 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-choice-buttons button.active {
|
||||||
|
border-color: #2f6fb0;
|
||||||
|
color: #ffffff;
|
||||||
|
background: #2f6fb0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-side {
|
||||||
|
display: grid;
|
||||||
|
gap: 3px;
|
||||||
|
padding: 6px;
|
||||||
|
border: 1px solid #dce1e5;
|
||||||
|
border-radius: 6px;
|
||||||
|
border-left-width: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-side.ours {
|
||||||
|
border-left-color: #4aa777;
|
||||||
|
background: #f1faf4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-side.theirs {
|
||||||
|
border-left-color: #5a8bd0;
|
||||||
|
background: #f1f5fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-side.dimmed {
|
||||||
|
opacity: 0.45;
|
||||||
|
filter: grayscale(0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-side-label {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 800;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-side.ours .resolve-side-label {
|
||||||
|
color: #1f7a4d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-side.theirs .resolve-side-label {
|
||||||
|
color: #2f6fb0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-lines {
|
||||||
|
margin: 0;
|
||||||
|
overflow-x: auto;
|
||||||
|
font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
tab-size: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-line {
|
||||||
|
display: block;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-line.ours {
|
||||||
|
color: #176239;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-line.theirs {
|
||||||
|
color: #255b8b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-line.context {
|
||||||
|
color: #3a444c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resolve-path {
|
||||||
|
overflow: hidden;
|
||||||
|
color: #6c7882;
|
||||||
|
font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
.diff-counts {
|
.diff-counts {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
ConflictFile,
|
||||||
GitBranch,
|
GitBranch,
|
||||||
GitCommit,
|
GitCommit,
|
||||||
GitCommitComparison,
|
GitCommitComparison,
|
||||||
@@ -95,3 +96,15 @@ export function diffFileAgainstWorkingTree(
|
|||||||
): Promise<GitCommitComparison> {
|
): Promise<GitCommitComparison> {
|
||||||
return invoke<GitCommitComparison>("diff_file_against_working_tree", { path, commit, file });
|
return invoke<GitCommitComparison>("diff_file_against_working_tree", { path, commit, file });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function readConflict(path: string, file: string): Promise<ConflictFile> {
|
||||||
|
return invoke<ConflictFile>("read_conflict", { path, file });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveConflict(
|
||||||
|
path: string,
|
||||||
|
file: string,
|
||||||
|
content: string,
|
||||||
|
): Promise<GitStatus> {
|
||||||
|
return invoke<GitStatus>("resolve_conflict", { path, file, content });
|
||||||
|
}
|
||||||
|
|||||||
@@ -69,3 +69,11 @@ export interface GitCommitComparison {
|
|||||||
files: GitDiffFile[];
|
files: GitDiffFile[];
|
||||||
patch: string;
|
patch: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ConflictFile {
|
||||||
|
path: string;
|
||||||
|
content: string;
|
||||||
|
ours: string | null;
|
||||||
|
theirs: string | null;
|
||||||
|
base: string | null;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user