diff --git a/cptr/frontend/src/lib/apis/index.ts b/cptr/frontend/src/lib/apis/index.ts index 77c1994..c4d81d5 100644 --- a/cptr/frontend/src/lib/apis/index.ts +++ b/cptr/frontend/src/lib/apis/index.ts @@ -23,7 +23,7 @@ export async function fetchJSON(path: string, init?: RequestInit): const res = await fetchHandler(path, init); if (!res.ok) { const data = await res.json().catch(() => ({})); - throw new ApiError(res.status, data.error || res.statusText); + throw new ApiError(res.status, data.detail || data.error || res.statusText); } return res.json(); } diff --git a/cptr/frontend/src/lib/components/GitBar.svelte b/cptr/frontend/src/lib/components/GitBar.svelte index e76e764..491421c 100644 --- a/cptr/frontend/src/lib/components/GitBar.svelte +++ b/cptr/frontend/src/lib/components/GitBar.svelte @@ -65,6 +65,10 @@ files: GitFile[]; } | null); + // Branch has never been pushed to remote + const needsPublish = $derived(!gitStatus?.upstream); + const unpushedCount = $derived(needsPublish ? (commits?.length ?? 0) : (gitStatus?.ahead ?? 0)); + // Clear stale selection when file is no longer in the changed list $effect(() => { if (view === 'changes' && selectedFile) { @@ -200,8 +204,9 @@ try { const d = await gitUncommit(workspacePath); flash($t('git.uncommitted')); - } catch { - flash('Nothing to uncommit'); + switchView('changes'); + } catch (e) { + flash(e instanceof Error ? e.message : 'Failed to undo commit'); } loading = false; await refresh(); @@ -217,7 +222,6 @@ async function doPush() { loading = true; - const needsPublish = !gitStatus?.upstream; const d = await gitPush(workspacePath, { set_upstream: needsPublish, branch: needsPublish ? gitStatus?.branch : undefined @@ -255,6 +259,7 @@ // Context menu let contextMenu = $state<{ file: GitFile; anchor: HTMLElement } | null>(null); + let commitMenu = $state<{ commit: Commit; isLatest: boolean; anchor: HTMLElement } | null>(null); function openFileMenu(e: MouseEvent, file: GitFile) { e.stopPropagation(); @@ -265,6 +270,15 @@ contextMenu = null; } + function openCommitMenu(e: MouseEvent, commit: Commit, isLatest: boolean) { + e.stopPropagation(); + commitMenu = { commit, isLatest, anchor: e.currentTarget as HTMLElement }; + } + + function closeCommitMenu() { + commitMenu = null; + } + async function discardFile(path: string) { await discardChanges(workspacePath, [path]); if (selectedFile === path) { @@ -733,47 +747,47 @@ {$t('git.commitToBranch', { branch: gitStatus.branch })} {/if} - - - {#if gitStatus.ahead > 0 || !gitStatus.upstream} -
- - -
- {/if} {:else}
- {#each commits as c} + {#each commits as c, i} + {#if i === unpushedCount && unpushedCount > 0} +
+ + + {unpushedCount} unpushed {unpushedCount === 1 ? 'commit' : 'commits'} + +
+ {/if} {/each} {#if !commits.length} @@ -898,6 +912,36 @@ /> {/if} +{#if commitMenu} + { + doUncommit(); + closeCommitMenu(); + } + } + ] + : []), + { + label: $t('git.copyCommitHash'), + icon: 'copy', + onclick: () => { + navigator.clipboard.writeText(commitMenu!.commit.hash); + flash($t('git.copiedPath')); + closeCommitMenu(); + } + } + ]} + onclose={closeCommitMenu} + /> +{/if} +