This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-15 11:53:21 +02:00
1 parent ed11c3cd6c
commit b6ec72dd18
4 files changed
+96 -36

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@ export async function fetchJSON<T = unknown>(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();
}
+77 -33
View File
@@ -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}
</button>
<!-- Push & Uncommit actions -->
{#if gitStatus.ahead > 0 || !gitStatus.upstream}
<div class="flex gap-1.5 mt-1.5">
<button
class="flex-1 flex items-center justify-center gap-1.5 h-7 rounded-lg text-[11px] font-medium transition-colors duration-75 border border-gray-200 dark:border-white/8 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-white/4"
disabled={loading}
onclick={doPush}
>
<Icon name="upload" size={11} />
<span>{gitStatus.ahead > 0 ? $t('git.pushCount', { count: gitStatus.ahead }) : $t('git.publish')}</span>
</button>
<button
class="flex items-center justify-center gap-1 h-7 px-2 rounded-lg text-[11px] font-medium transition-colors duration-75 text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-50 dark:hover:bg-white/4"
disabled={loading}
onclick={doUncommit}
use:tooltip={$t('git.uncommitTooltip')}
>
<Icon name="undo" size={11} />
<span>{$t('git.uncommit')}</span>
</button>
</div>
{/if}
</div>
{:else}
<!-- History: commit list -->
<div class="flex-1 overflow-y-auto">
{#each commits as c}
{#each commits as c, i}
{#if i === unpushedCount && unpushedCount > 0}
<div class="flex items-center gap-2 px-2.5 py-1 border-b border-gray-100 dark:border-white/4 bg-gray-50/50 dark:bg-white/2">
<Icon name="upload" size={10} class="text-gray-400 dark:text-gray-600 shrink-0" />
<span class="text-[10px] text-gray-400 dark:text-gray-600">
{unpushedCount} unpushed {unpushedCount === 1 ? 'commit' : 'commits'}
</span>
</div>
{/if}
<button
class="flex flex-col w-full px-2.5 py-1.5 text-left border-b border-gray-50 dark:border-white/3 transition-colors duration-75
class="group flex items-center gap-1.5 w-full px-2.5 py-1.5 text-left border-b border-gray-50 dark:border-white/3 transition-colors duration-75
{selectedCommit?.hash === c.hash
? 'bg-gray-100 dark:bg-white/8'
: 'hover:bg-gray-50 dark:hover:bg-white/3'}"
onclick={() => selectCommit(c)}
>
<span class="text-xs text-gray-800 dark:text-gray-200 truncate w-full"
>{c.message}</span
>
<span class="text-[10px] text-gray-400 dark:text-gray-600 font-mono"
>{c.short_hash} · {c.author} · {relTime(c.date)}</span
{#if i < unpushedCount}
<span class="w-1.5 h-1.5 rounded-full bg-blue-500 dark:bg-blue-400 shrink-0" title="Unpushed"></span>
{/if}
<div class="flex flex-col min-w-0 flex-1">
<span class="text-xs text-gray-800 dark:text-gray-200 truncate w-full"
>{c.message}</span
>
<span class="text-[10px] text-gray-400 dark:text-gray-600 font-mono"
>{c.short_hash} · {c.author} · {relTime(c.date)}</span
>
</div>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<span
class="flex items-center justify-center w-5 h-5 rounded shrink-0 opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/10 transition-all duration-75"
role="button"
tabindex="-1"
onclick={(e) => openCommitMenu(e, c, i === 0)}
aria-label={$t('files.moreActions')}
>
<Icon name="three-dots" size={12} />
</span>
</button>
{/each}
{#if !commits.length}
@@ -898,6 +912,36 @@
/>
{/if}
{#if commitMenu}
<DropdownMenu
anchor={commitMenu.anchor}
items={[
...(commitMenu.isLatest
? [
{
label: $t('git.undoCommit'),
icon: 'undo',
onclick: () => {
doUncommit();
closeCommitMenu();
}
}
]
: []),
{
label: $t('git.copyCommitHash'),
icon: 'copy',
onclick: () => {
navigator.clipboard.writeText(commitMenu!.commit.hash);
flash($t('git.copiedPath'));
closeCommitMenu();
}
}
]}
onclose={closeCommitMenu}
/>
{/if}
<style>
.diff-content {
width: max-content;
@@ -171,6 +171,8 @@
"git.stageAll": "Stage all",
"git.unstageAll": "Unstage all",
"git.discard": "Discard",
"git.undoCommit": "Undo commit",
"git.copyCommitHash": "Copy commit hash",
"git.copyFilePath": "Copy File Path",
"git.copyRelativePath": "Copy Relative File Path",
+16 -2
View File
@@ -63,6 +63,7 @@ async def status(root: str) -> dict[str, Any]:
upstream = ""
ahead = 0
behind = 0
has_ab = False
files: list[dict] = []
for line in out.splitlines():
@@ -71,6 +72,7 @@ async def status(root: str) -> dict[str, Any]:
elif line.startswith("# branch.upstream "):
upstream = line.split(" ", 2)[2]
elif line.startswith("# branch.ab "):
has_ab = True
parts = line.split()
ahead = int(parts[2].lstrip("+"))
behind = abs(int(parts[3].lstrip("-")))
@@ -110,6 +112,11 @@ async def status(root: str) -> dict[str, Any]:
path = parts[-1]
files.append({"path": path, "status": "conflict", "staged": False})
# upstream is set but remote branch doesn't exist yet (no ab line)
# — treat as unpublished so the frontend shows "Publish"
if upstream and not has_ab:
upstream = ""
return {
"branch": branch,
"upstream": upstream,
@@ -440,7 +447,8 @@ async def push(
async def uncommit(root: str) -> dict[str, str]:
"""Undo the last commit, moving its changes back to the staging area.
Uses ``git reset --soft HEAD~1``.
Uses ``git reset --soft HEAD~1``, or ``git update-ref -d HEAD`` for root
commits (no parent).
"""
# Grab info about the commit we're about to undo
_, log_out, _ = await _run(
@@ -450,7 +458,13 @@ async def uncommit(root: str) -> dict[str, str]:
undone_hash = parts[1] if len(parts) >= 2 else ""
undone_msg = parts[2] if len(parts) >= 3 else ""
await _run("reset", "--soft", "HEAD~1", cwd=root)
# Check if HEAD~1 exists (root commits have no parent)
code, _, _ = await _run("rev-parse", "--verify", "HEAD~1", cwd=root, check=False)
if code != 0:
# Root commit: remove HEAD ref, keeps index (staged files) intact
await _run("update-ref", "-d", "HEAD", cwd=root)
else:
await _run("reset", "--soft", "HEAD~1", cwd=root)
return {"hash": undone_hash, "message": undone_msg}