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
1 change: 0 additions & 1 deletion apps/desktop/src/components/commit/CommitView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
await stackService.uncommit({
projectId,
stackId: targetStackId,
branchName,
commitId: commitKey.commitId,
});
},
Expand Down
1 change: 0 additions & 1 deletion apps/desktop/src/components/views/BranchCommitList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
await stackService.uncommit({
projectId,
stackId: targetStackId,
branchName,
commitId,
});
});
Expand Down
35 changes: 35 additions & 0 deletions apps/desktop/src/lib/stacks/stackEndpoints.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { buildStackEndpoints } from "$lib/stacks/stackEndpoints";
import { describe, expect, test } from "vitest";
import type { BackendEndpointBuilder } from "$lib/state/backendApi";

function createEndpointBuilder(): BackendEndpointBuilder {
return {
mutation: (definition) => definition,
query: (definition) => definition,
} as BackendEndpointBuilder;
}

describe("buildStackEndpoints", () => {
test("maps uncommit to commit_undo with the new request shape", () => {
const endpoints = buildStackEndpoints(createEndpointBuilder());
const query = endpoints.uncommit.query;

expect(endpoints.uncommit.extraOptions).toEqual({
command: "commit_undo",
actionName: "Uncommit",
});
expect(query).toBeDefined();
expect(
query?.({
projectId: "project-1",
stackId: "stack-1",
commitId: "commit-1",
}),
).toEqual({
projectId: "project-1",
subjectCommitId: "commit-1",
assignTo: "stack-1",
dryRun: false,
});
});
});
15 changes: 12 additions & 3 deletions apps/desktop/src/lib/stacks/stackEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type {
CommitRewordResult,
CommitInsertBlankResult,
RejectionReason,
CommitUndoResult,
} from "@gitbutler/but-sdk";

export type BranchParams = {
Expand Down Expand Up @@ -469,12 +470,20 @@ export function buildStackEndpoints(build: BackendEndpointBuilder) {
invalidatesList(ReduxTag.BranchListing),
],
}),
uncommit: build.mutation<void, { projectId: string; stackId: string; commitId: string }>({
uncommit: build.mutation<
CommitUndoResult,
{ projectId: string; stackId: string; commitId: string }
>({
extraOptions: {
command: "undo_commit",
command: "commit_undo",
actionName: "Uncommit",
},
query: (args) => args,
query: ({ projectId, stackId, commitId }) => ({
projectId,
subjectCommitId: commitId,
assignTo: stackId,
dryRun: false,
}),
invalidatesTags: (_result, _error, args) => [
invalidatesItem(ReduxTag.BranchChanges, args.stackId),
invalidatesList(ReduxTag.WorktreeChanges),
Expand Down
7 changes: 1 addition & 6 deletions apps/desktop/src/lib/stacks/stackService.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,7 @@ export class StackService {
return this.backendApi.endpoints.newBranch.useMutation();
}

async uncommit(args: {
projectId: string;
stackId: string;
branchName: string;
commitId: string;
}) {
async uncommit(args: { projectId: string; stackId: string; commitId: string }) {
const result = await this.backendApi.endpoints.uncommit.mutate(args);
const selection = this.uiState.lane(args.stackId).selection;
if (args.commitId === selection.current?.commitId) {
Expand Down
69 changes: 69 additions & 0 deletions apps/desktop/src/lib/stacks/stackService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { StackService } from "$lib/stacks/stackService.svelte";
import { describe, expect, test, vi } from "vitest";
import type { BackendApi } from "$lib/state/backendApi";
import type { StackSelection, UiState } from "$lib/state/uiState.svelte";

function makeMockUiState(initialSelection: StackSelection | undefined): {
uiState: UiState;
getSelection: () => StackSelection | undefined;
} {
let selection = initialSelection;
const laneState = {
selection: {
get current() {
return selection;
},
set: (value: StackSelection | undefined) => {
selection = value;
},
},
};

return {
uiState: {
lane: () => laneState,
} as unknown as UiState,
getSelection: () => selection,
};
}

describe("StackService.uncommit", () => {
test("clears the selected commit after a successful uncommit", async () => {
const mutate = vi.fn().mockResolvedValue({
undoneCommit: "commit-1",
workspace: {
headInfo: {
reference: "refs/heads/branch",
workspaceChanges: [],
},
replacedCommits: {},
},
});
const { uiState, getSelection } = makeMockUiState({
branchName: "branch",
commitId: "commit-1",
previewOpen: true,
});
const backendApi = {
endpoints: {
uncommit: {
mutate,
},
},
} as unknown as BackendApi;
const service = new StackService(backendApi, {} as never, {} as never, uiState);

await service.uncommit({
projectId: "project-1",
stackId: "stack-1",
commitId: "commit-1",
});

expect(mutate).toHaveBeenCalledWith({
projectId: "project-1",
stackId: "stack-1",
commitId: "commit-1",
});
expect(getSelection()).toBeUndefined();
});
});
1 change: 1 addition & 0 deletions crates/but-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ pub async fn run(config: Config) -> anyhow::Result<()> {
"/commit_uncommit_changes",
but_post(commit::uncommit::commit_uncommit_changes_cmd),
)
.route("/commit_undo", but_post(commit::undo::commit_undo_cmd))
.route("/build_type", but_post(platform::build_type_cmd));

// IRC commands — only registered when the `irc` feature is enabled.
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/permissions/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ commands.allow = [
"commit_insert_blank",
"commit_move_changes_between",
"commit_reword",
"commit_undo",
"commit_uncommit_changes",
"create_branch",
"create_commit_from_worktree_changes",
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ fn main() -> anyhow::Result<()> {
commit::amend::tauri_commit_amend::commit_amend,
commit::move_changes::tauri_commit_move_changes_between::commit_move_changes_between,
commit::uncommit::tauri_commit_uncommit_changes::commit_uncommit_changes,
commit::undo::tauri_commit_undo::commit_undo,
platform::tauri_build_type::build_type,
])
.menu(move |handle| menu::build(handle, &app_settings_for_menu))
Expand Down
Loading