Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions windows/tauri/src-tauri/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,41 @@ fn translate(command: &str, args: Value) -> Result<(String, Value), String> {
);
"git.checkoutPreflight"
}
"git_merge" | "git_rebase" => {
let branch = take_text(&mut payload, "branchName")?;
payload.insert(
"reference".into(),
json!(local_branch_reference(&branch)),
);
payload.insert(
"operation".into(),
json!(if command == "git_merge" {
"merge"
} else {
"rebase"
}),
);
"git.write"
}
"git_integration_preflight" => {
let branch = take_text(&mut payload, "branchName")?;
payload.insert(
"reference".into(),
json!(local_branch_reference(&branch)),
);
"git.integrationPreflight"
}
"git_operation_state" => "git.operationState",
"git_operation_continue" | "git_operation_abort" | "git_operation_skip" => {
let operation = match command {
"git_operation_continue" => "operationContinue",
"git_operation_abort" => "operationAbort",
_ => "operationSkip",
};
payload.insert("operation".into(), json!(operation));
"git.write"
}
"git_conflict_markers" => "git.conflictMarkers",
"git_create_stash" => {
payload.insert("operation".into(), json!("stashPush"));
"git.write"
Expand Down Expand Up @@ -500,6 +535,89 @@ mod tests {
);
}

#[test]
fn translates_merge_and_rebase_to_qualified_references() {
let (merge_command, merge_payload) = translate(
"git_merge",
json!({ "repoPath": "C:/work", "branchName": "feature/demo" }),
)
.unwrap();
assert_eq!(merge_command, "git.write");
assert_eq!(
merge_payload,
json!({
"root": "C:/work",
"operation": "merge",
"reference": "refs/heads/feature/demo"
})
);

let (rebase_command, rebase_payload) = translate(
"git_rebase",
json!({ "repoPath": "C:/work", "branchName": "main" }),
)
.unwrap();
assert_eq!(rebase_command, "git.write");
assert_eq!(
rebase_payload,
json!({
"root": "C:/work",
"operation": "rebase",
"reference": "refs/heads/main"
})
);
}

#[test]
fn translates_integration_preflight_operation() {
let (command, payload) = translate(
"git_integration_preflight",
json!({ "repoPath": "C:/work", "branchName": "main", "operation": "rebase" }),
)
.unwrap();

assert_eq!(command, "git.integrationPreflight");
assert_eq!(
payload,
json!({
"root": "C:/work",
"reference": "refs/heads/main",
"operation": "rebase"
})
);
}

#[test]
fn translates_operation_state_and_resolution_commands() {
let (state_command, state_payload) =
translate("git_operation_state", json!({ "repoPath": "C:/work" })).unwrap();
assert_eq!(state_command, "git.operationState");
assert_eq!(state_payload, json!({ "root": "C:/work" }));

for (compat, operation) in [
("git_operation_continue", "operationContinue"),
("git_operation_abort", "operationAbort"),
("git_operation_skip", "operationSkip"),
] {
let (command, payload) =
translate(compat, json!({ "repoPath": "C:/work" })).unwrap();
assert_eq!(command, "git.write");
assert_eq!(
payload,
json!({ "root": "C:/work", "operation": operation })
);
}
}

#[test]
fn translates_conflict_markers_request() {
let (command, payload) =
translate("git_conflict_markers", json!({ "repoPath": "C:/work" })).unwrap();

assert_eq!(command, "git.conflictMarkers");
assert_eq!(payload, json!({ "root": "C:/work" }));
}

#[test]
fn translates_delete_branch_to_qualified_reference() {
let (command, payload) = translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ const CommandPaletteContent = ({ commandPaletteInitialView }: CommandPaletteCont
activeRepoPath,
setIsSidebarVisible,
setActiveView,
setIsBottomPaneVisible,
setBottomPaneActiveTab,
showToast,
gitOperations: {
stageAllFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface GitActionsParams {
activeRepoPath?: string | null;
setIsSidebarVisible: (v: boolean) => void;
setActiveView: (view: "files" | "git" | "github-prs") => void;
setIsBottomPaneVisible: (visible: boolean) => void;
setBottomPaneActiveTab: (tab: "gitLog") => void;
showToast: (params: { message: string; type: "success" | "error" | "info" }) => void;
gitOperations: {
stageAllFiles: (path: string) => Promise<boolean>;
Expand All @@ -38,6 +40,8 @@ export const createGitActions = (params: GitActionsParams): Action[] => {
activeRepoPath,
setIsSidebarVisible,
setActiveView,
setIsBottomPaneVisible,
setBottomPaneActiveTab,
showToast,
gitOperations,
onClose,
Expand Down Expand Up @@ -155,6 +159,18 @@ export const createGitActions = (params: GitActionsParams): Action[] => {
category: "Git",
action: () => openGitAction({ type: "show-tab", tab: "history" }),
},
{
id: "git-open-log",
label: "Git: Open Log",
description: "Open the full Git Log tool window",
icon: <ClockCounterClockwise />,
category: "Git",
action: () => {
setBottomPaneActiveTab("gitLog");
setIsBottomPaneVisible(true);
onClose();
},
},
{
id: "git-manage-remotes",
label: "Git: Manage Remotes",
Expand Down
29 changes: 27 additions & 2 deletions windows/tauri/src/features/git/api/git-commits-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { invoke as tauriInvoke } from "@/platform/tauri-core";
import type { GitCommit, GitHistorySnapshot } from "../types/git.types";
import type { GitCommit, GitCommitFile, GitHistorySnapshot } from "../types/git.types";
import { emitGitChanged } from "../events/git-events";
import { runGitRead } from "../runtime/git-read-coordinator";
import {
Expand Down Expand Up @@ -27,17 +27,19 @@ export const commitChanges = async (repoPath: string, message: string): Promise<
export const getGitHistory = async (
repoPath: string,
limit = 50,
reference?: string,
): Promise<GitHistorySnapshot | null> => {
try {
const resolvedRepoPath = await resolveRepositoryPath(repoPath);
if (!resolvedRepoPath) {
return null;
}

return await runGitRead(resolvedRepoPath, `log:${limit}`, () =>
return await runGitRead(resolvedRepoPath, `log:${reference ?? "all"}:${limit}`, () =>
tauriInvoke<GitHistorySnapshot>("git_log", {
repoPath: resolvedRepoPath,
limit,
...(reference ? { reference } : {}),
}),
);
} catch (error) {
Expand All @@ -50,3 +52,26 @@ export const getGitHistory = async (

export const getGitLog = async (repoPath: string, limit = 50): Promise<GitCommit[]> =>
(await getGitHistory(repoPath, limit))?.commits ?? [];

export const getCommitFiles = async (
repoPath: string,
commitHash: string,
): Promise<GitCommitFile[] | null> => {
try {
const resolvedRepoPath = await resolveRepositoryPath(repoPath);
if (!resolvedRepoPath) return null;

const result = await runGitRead(resolvedRepoPath, `commit-files:${commitHash}`, () =>
tauriInvoke<{ files: GitCommitFile[] }>("git.commitFiles", {
repoPath: resolvedRepoPath,
commit: commitHash,
}),
);
return result.files ?? [];
} catch (error) {
if (!isNotGitRepositoryError(error)) {
console.error("Failed to get files for commit:", error);
}
return null;
}
};
82 changes: 82 additions & 0 deletions windows/tauri/src/features/git/api/git-integration-api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { beforeEach, describe, expect, mock, test } from "bun:test";
import type { GitOperationState } from "../types/git.types";

const invoke = mock(async (_command: string, _args?: unknown): Promise<unknown> => null);
const emitGitChanged = mock((_change: unknown) => {});
const resolveRepositoryPathOrThrow = mock(async (repoPath: string) => repoPath);

mock.module("@/platform/tauri-core", () => ({ invoke }));
mock.module("../events/git-events", () => ({ emitGitChanged }));
mock.module("./git-repo-api", () => ({ resolveRepositoryPathOrThrow }));

const { getConflictMarkerPaths, getOperationState, mergeBranch, rebaseOntoBranch } = await import(
"./git-integration-api"
);

const operationState = (
kind: GitOperationState["kind"],
conflictedPaths: string[] = [],
): GitOperationState => ({
kind,
reference: null,
conflictedPaths,
step: null,
total: null,
});

beforeEach(() => {
invoke.mockReset();
emitGitChanged.mockReset();
resolveRepositoryPathOrThrow.mockReset();
resolveRepositoryPathOrThrow.mockImplementation(async (repoPath: string) => repoPath);
});

describe("Git integration state", () => {
test("reports a stopped rebase even when no conflicted paths remain", async () => {
invoke.mockImplementation(async (command: string) => {
if (command === "git_integration_preflight") {
return { blockingPaths: [], blocksEntirely: false };
}
if (command === "git_rebase") throw new Error("rebase stopped");
if (command === "git_operation_state") return operationState("rebase");
return null;
});

await expect(rebaseOntoBranch("C:/repo", "main")).resolves.toEqual({ status: "stopped" });
expect(emitGitChanged).toHaveBeenCalledWith({
repoPath: "C:/repo",
scopes: ["working-tree", "history", "refs"],
source: "rebase-rejected",
});
});

test("reports conflicted paths when a merge stops on conflicts", async () => {
invoke.mockImplementation(async (command: string) => {
if (command === "git_integration_preflight") {
return { blockingPaths: [], blocksEntirely: false };
}
if (command === "git_merge") throw new Error("merge stopped");
if (command === "git_operation_state") {
return operationState("merge", ["src/app.ts"]);
}
return null;
});

await expect(mergeBranch("C:/repo", "feature")).resolves.toEqual({
status: "conflicts",
conflictedPaths: ["src/app.ts"],
});
});

test("propagates operation state query failures", async () => {
invoke.mockRejectedValue(new Error("Core unavailable"));

await expect(getOperationState("C:/repo")).rejects.toThrow("Core unavailable");
});

test("propagates conflict marker query failures so commits fail closed", async () => {
invoke.mockRejectedValue(new Error("Core unavailable"));

await expect(getConflictMarkerPaths("C:/repo")).rejects.toThrow("Core unavailable");
});
});
Loading
Loading