feat(commit): add amend and undo last commit support
This change introduces new Tauri commands to amend the last commit with an optional message, fetch the last commit message, and undo the most recent commit safely. The UI now offers an amend toggle and an undo button only when the last commit hasn’t been pushed upstream, reducing the risk of rewriting shared history. - Add amend/undo/last-message git commands in Rust - Wire new operations into the Svelte commit panel UI - Add styling and state handling for amend mode
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { Check, LoaderCircle, Settings, Sparkles } from "@lucide/svelte";
|
||||
import { Check, LoaderCircle, RotateCcw, Settings, Sparkles } from "@lucide/svelte";
|
||||
import type { CommitAiPhase, CommitAiProvider } from "../types";
|
||||
|
||||
interface Props {
|
||||
@@ -13,10 +13,14 @@
|
||||
commitAiProvider: CommitAiProvider;
|
||||
commitAiPhase: CommitAiPhase;
|
||||
commitAiGenerating: boolean;
|
||||
canAmend: boolean;
|
||||
amendMode: boolean;
|
||||
onCommit: () => void;
|
||||
onCommitMessageChange: (msg: string) => void;
|
||||
onGenerateCommitMessage: () => void;
|
||||
onOpenAiSettings: () => void;
|
||||
onToggleAmend: (checked: boolean) => void;
|
||||
onUndoLastCommit: () => void;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -30,10 +34,14 @@
|
||||
commitAiProvider = "local",
|
||||
commitAiPhase = "idle",
|
||||
commitAiGenerating = false,
|
||||
canAmend = false,
|
||||
amendMode = false,
|
||||
onCommit = () => {},
|
||||
onCommitMessageChange = () => {},
|
||||
onGenerateCommitMessage = () => {},
|
||||
onOpenAiSettings = () => {},
|
||||
onToggleAmend = () => {},
|
||||
onUndoLastCommit = () => {},
|
||||
}: Props = $props();
|
||||
|
||||
function handleSubmit(event: SubmitEvent) {
|
||||
@@ -77,14 +85,37 @@
|
||||
{#if commitBlockReason}
|
||||
<p class="commit-block-reason">{commitBlockReason}</p>
|
||||
{/if}
|
||||
{#if canAmend}
|
||||
<div class="commit-amend-row">
|
||||
<label class="commit-amend-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={amendMode}
|
||||
disabled={isBusy}
|
||||
onchange={(e) => onToggleAmend((e.target as HTMLInputElement).checked)}
|
||||
/>
|
||||
Amend last commit
|
||||
</label>
|
||||
<button
|
||||
class="btn-secondary commit-undo-button"
|
||||
type="button"
|
||||
onclick={onUndoLastCommit}
|
||||
disabled={isBusy}
|
||||
title="Undo the last commit — its changes come back as uncommitted changes (not pushed yet, so safe)"
|
||||
>
|
||||
<RotateCcw size={13} aria-hidden="true" />
|
||||
Undo last commit
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="commit-actions-row flex-shrink-0">
|
||||
<button class="btn-primary flex-1" type="submit" disabled={!canCommit} title={commitBlockReason || "Commit staged changes"}>
|
||||
{#if operation === "Committing"}
|
||||
<button class="btn-primary flex-1" type="submit" disabled={!canCommit} title={commitBlockReason || (amendMode ? "Amend the last commit" : "Commit staged changes")}>
|
||||
{#if operation === "Committing" || operation === "Amending"}
|
||||
<LoaderCircle class="spin" size={16} aria-hidden="true" />
|
||||
{:else}
|
||||
<Check size={16} aria-hidden="true" />
|
||||
{/if}
|
||||
Commit
|
||||
{amendMode ? "Amend" : "Commit"}
|
||||
</button>
|
||||
<button
|
||||
class="btn-secondary commit-ai-button"
|
||||
|
||||
@@ -171,6 +171,18 @@ export function commit(path: string, message: string): Promise<GitStatus> {
|
||||
return invoke<GitStatus>("commit", { path, message });
|
||||
}
|
||||
|
||||
export function amendCommit(path: string, message?: string): Promise<GitStatus> {
|
||||
return invoke<GitStatus>("amend_commit", { path, message: message?.trim() ? message.trim() : null });
|
||||
}
|
||||
|
||||
export function lastCommitMessage(path: string): Promise<string | null> {
|
||||
return invoke<string | null>("last_commit_message", { path });
|
||||
}
|
||||
|
||||
export function undoLastCommit(path: string): Promise<GitStatus> {
|
||||
return invoke<GitStatus>("undo_last_commit", { path });
|
||||
}
|
||||
|
||||
export function stashPush(
|
||||
path: string,
|
||||
message?: string,
|
||||
|
||||
Reference in New Issue
Block a user