mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-30 17:05:16 -05:00
1370 lines
52 KiB
Svelte
1370 lines
52 KiB
Svelte
<script lang="ts">
|
|
import { getContext, onDestroy, onMount } from 'svelte';
|
|
import { getMachineFeatures, type MachineTarget } from '$lib/apis/machines';
|
|
import { watchMachineFiles } from '$lib/apis/machines/events';
|
|
import {
|
|
gitRequest,
|
|
gitAction,
|
|
gitRemoteWebUrl,
|
|
type GitStatus,
|
|
type GitFile,
|
|
type GitCommit,
|
|
type GitBranch
|
|
} from '$lib/apis/machines/git';
|
|
import { copyToClipboard } from '$lib/utils';
|
|
import Icon from '../FileNav/Icon.svelte';
|
|
import GitDiff from './GitDiff.svelte';
|
|
import { parseDiffRows } from '../Messages/diff';
|
|
import Dropdown from '../../common/Dropdown.svelte';
|
|
import DropdownMenu from '../../common/DropdownMenu.svelte';
|
|
import ConfirmDialog from '../../common/ConfirmDialog.svelte';
|
|
import Tooltip from '../../common/Tooltip.svelte';
|
|
import GitPullRequests from './GitPullRequests.svelte';
|
|
import GitListDivider from './GitListDivider.svelte';
|
|
import GitIssues from './GitIssues.svelte';
|
|
import { relativeTime } from './gitPanel';
|
|
|
|
export let target: MachineTarget | null = null;
|
|
export let directory = '.';
|
|
export let chatId: string | null = null;
|
|
export let active = false;
|
|
export let onOpenFile: (path: string) => void = () => {};
|
|
export let onDraftPrompt: ((text: string) => void) | null = null;
|
|
export let onOpenDirectory: (path: string) => void = () => {};
|
|
const i18n = getContext<any>('i18n');
|
|
export let status: GitStatus | null = null;
|
|
export let initialView: any = null;
|
|
/** Fills a tab of its own: always expanded, no collapse or resize. */
|
|
export let standalone = false;
|
|
export let onOpenTab: ((root: string) => void) | null = null;
|
|
let expanded = standalone || (initialView?.expanded ?? false);
|
|
export const captureView = () => ({ expanded, summary, description, height, listWidth, view });
|
|
export let diffMode: 'unified' | 'split' = 'unified';
|
|
export let hideWhitespace = false;
|
|
let view: 'changes' | 'history' | 'pull requests' | 'issues' = initialView?.view ?? 'changes';
|
|
let github: {
|
|
available: boolean;
|
|
default_branch?: string;
|
|
issues?: boolean;
|
|
open_pull_requests?: number | null;
|
|
open_issues?: number | null;
|
|
} | null = null;
|
|
$: openPullRequests = github?.open_pull_requests ?? null;
|
|
$: openIssues = github?.issues ? (github.open_issues ?? null) : null;
|
|
let githubRoot = '';
|
|
let selected: { path: string; staged: boolean; untracked: boolean } | null = null;
|
|
let selectedCommit: GitCommit | null = null;
|
|
let diff = '';
|
|
$: diffStats = parseDiffRows(diff).reduce(
|
|
(counts, row) => {
|
|
if (row.type === 'addition') counts.additions++;
|
|
if (row.type === 'deletion') counts.deletions++;
|
|
return counts;
|
|
},
|
|
{ additions: 0, deletions: 0 }
|
|
);
|
|
let commits: GitCommit[] = [];
|
|
let branches: GitBranch[] = [];
|
|
let branchSearch = '';
|
|
let newBranch = '';
|
|
let creatingBranch = false;
|
|
let creatingWorktree = false;
|
|
let actionBranch: GitBranch | null = null;
|
|
let worktreeSearch = '';
|
|
|
|
let showBranches = false;
|
|
let showWorktrees = false;
|
|
let worktrees: { path: string; branch: string; current: boolean }[] = [];
|
|
let worktreePath = '';
|
|
let worktreeBranch = '';
|
|
let showRename = false;
|
|
let showUncommit = false;
|
|
let showDeleteBranch = false;
|
|
let summary = initialView?.summary ?? '';
|
|
let description = initialView?.description ?? '';
|
|
let error = '';
|
|
let detectionError = '';
|
|
let busy = false;
|
|
let loadingDiff = false;
|
|
let confirmDiscard = false;
|
|
let discardFiles: GitFile[] = [];
|
|
// Files picked with Cmd/Ctrl- or Shift-click, separate from staging and the open diff.
|
|
let picked = new Set<string>();
|
|
let pickAnchor: string | null = null;
|
|
$: pickedFiles = status?.files.filter((file) => picked.has(file.path)) ?? [];
|
|
let discarding: Set<string> | null = null;
|
|
let height = initialView?.height ?? 280;
|
|
let resizing = false;
|
|
let resizeY = 0;
|
|
let resizeHeight = 0;
|
|
let splitWidth = 0;
|
|
let listWidth: number | null = initialView?.listWidth ?? null;
|
|
$: maxListWidth = Math.max(160, splitWidth - 220);
|
|
$: effectiveListWidth = Math.max(
|
|
160,
|
|
Math.min(maxListWidth, listWidth ?? (splitWidth >= 800 ? 288 : 240))
|
|
);
|
|
let mounted = false;
|
|
let context = '';
|
|
let generation = 0;
|
|
let diffGeneration = 0;
|
|
let stopWatching: (() => void) | undefined;
|
|
let watchError = '';
|
|
let gitEnabled = false;
|
|
let configuration = 0;
|
|
let pending: Promise<void> | null = null;
|
|
let syncAction: 'publish' | 'pull' | 'push' | 'fetch';
|
|
let syncFeedback: typeof syncAction | null = null;
|
|
let syncComplete = false;
|
|
let syncFeedbackTimer: ReturnType<typeof setTimeout> | undefined;
|
|
let pendingStaging: { action: 'stage' | 'unstage'; paths: Set<string> } | null = null;
|
|
$: stageStates = new Map<string, boolean | 'mixed'>(
|
|
(status?.files ?? []).map((file) => [
|
|
file.path,
|
|
pendingStaging?.paths.has(file.path)
|
|
? pendingStaging.action === 'stage'
|
|
: file.staged
|
|
? file.unstaged
|
|
? 'mixed'
|
|
: true
|
|
: false
|
|
])
|
|
);
|
|
$: staged = status?.files.filter((file) => stageStates.get(file.path)) ?? [];
|
|
$: allStaged =
|
|
!!status?.files.length && status.files.every((file) => stageStates.get(file.path) === true);
|
|
$: someStaged = staged.length > 0 && !allStaged;
|
|
$: additions = status?.files.reduce((sum, file) => sum + file.additions, 0) ?? 0;
|
|
$: deletions = status?.files.reduce((sum, file) => sum + file.deletions, 0) ?? 0;
|
|
$: branchLabel = status?.branch === '(detached)' ? status.head?.slice(0, 7) : status?.branch;
|
|
$: remoteWebUrl = gitRemoteWebUrl(status?.remote_url);
|
|
$: remoteHost = remoteWebUrl ? new URL(remoteWebUrl).hostname : '';
|
|
$: remotePlatform =
|
|
remoteHost === 'github.com'
|
|
? 'GitHub'
|
|
: remoteHost.includes('gitlab')
|
|
? 'GitLab'
|
|
: remoteHost === 'bitbucket.org'
|
|
? 'Bitbucket'
|
|
: remoteHost;
|
|
$: syncAction = !status?.upstream
|
|
? 'publish'
|
|
: status.behind > 0
|
|
? 'pull'
|
|
: status.ahead > 0
|
|
? 'push'
|
|
: 'fetch';
|
|
$: syncLabel = { publish: 'Publish', pull: 'Pull', push: 'Push', fetch: 'Fetch' }[syncAction];
|
|
// Extraction hints for the dynamic feedback labels below.
|
|
// $i18n.t('Published')
|
|
// $i18n.t('Pulled')
|
|
// $i18n.t('Pushed')
|
|
// $i18n.t('Fetched')
|
|
// $i18n.t('Publishing…')
|
|
// $i18n.t('Pulling…')
|
|
// $i18n.t('Pushing…')
|
|
// $i18n.t('Fetching…')
|
|
// $i18n.t('Staging…')
|
|
// $i18n.t('Unstaging…')
|
|
// $i18n.t('Discarding…')
|
|
$: syncMessage = syncFeedback
|
|
? syncComplete
|
|
? { publish: 'Published', pull: 'Pulled', push: 'Pushed', fetch: 'Fetched' }[syncFeedback]
|
|
: { publish: 'Publishing…', pull: 'Pulling…', push: 'Pushing…', fetch: 'Fetching…' }[
|
|
syncFeedback
|
|
]
|
|
: '';
|
|
$: feedbackMessage = discarding
|
|
? 'Discarding…'
|
|
: pendingStaging
|
|
? pendingStaging.action === 'stage'
|
|
? 'Staging…'
|
|
: 'Unstaging…'
|
|
: syncMessage;
|
|
$: syncIcon = { publish: 'upload', pull: 'download', push: 'upload', fetch: 'refresh' }[
|
|
busy && syncFeedback ? syncFeedback : syncAction
|
|
];
|
|
const clearSyncFeedback = () => {
|
|
clearTimeout(syncFeedbackTimer);
|
|
syncFeedback = null;
|
|
syncComplete = false;
|
|
};
|
|
|
|
const request = <T,>(
|
|
operation: string,
|
|
params: Record<string, string> = {},
|
|
body?: Record<string, unknown>
|
|
) => gitRequest<T>(target!, status?.root ?? directory, operation, params, body);
|
|
const refresh = (force = false): Promise<void> => {
|
|
if (!target || !active || !gitEnabled || (!force && document.hidden)) return Promise.resolve();
|
|
if (pending) return pending;
|
|
const current = generation;
|
|
const task = gitRequest<GitStatus>(target, directory, 'status')
|
|
.then((next) => {
|
|
if (current !== generation) return;
|
|
detectionError = '';
|
|
if (status?.root && status.root !== next.root) resetSelection();
|
|
status = next.is_repo ? next : null;
|
|
if (next.root && next.root !== githubRoot) {
|
|
githubRoot = next.root;
|
|
github = null;
|
|
void loadGitHub();
|
|
}
|
|
if (
|
|
selected &&
|
|
!(next.files ?? []).some(
|
|
(file) =>
|
|
file.path === selected?.path && (selected.staged ? file.staged : file.unstaged)
|
|
)
|
|
)
|
|
resetSelection();
|
|
})
|
|
.catch((reason) => {
|
|
if (current === generation) {
|
|
status = null;
|
|
detectionError = String(reason instanceof Error ? reason.message : reason);
|
|
}
|
|
})
|
|
.finally(() => {
|
|
if (current === generation) pending = null;
|
|
});
|
|
pending = task;
|
|
return task;
|
|
};
|
|
// What `gh` reports for this repo: availability, default branch, issues, and open counts.
|
|
// A refresh after a change keeps the last known values if it fails.
|
|
const loadGitHub = async (refreshing = false) => {
|
|
const current = generation;
|
|
const root = githubRoot;
|
|
try {
|
|
const data = await request<NonNullable<typeof github>>('pr/capabilities');
|
|
if (current === generation && root === githubRoot) github = data;
|
|
} catch {
|
|
if (!refreshing && current === generation && root === githubRoot) github = null;
|
|
}
|
|
};
|
|
const resetSelection = () => {
|
|
++diffGeneration;
|
|
selected = null;
|
|
selectedCommit = null;
|
|
diff = '';
|
|
loadingDiff = false;
|
|
};
|
|
const configure = async (key: string, enabled: boolean) => {
|
|
const version = ++configuration;
|
|
stopWatching?.();
|
|
stopWatching = undefined;
|
|
watchError = '';
|
|
gitEnabled = false;
|
|
if (key !== context) {
|
|
const restoring = !context && initialView;
|
|
clearSyncFeedback();
|
|
pendingStaging = null;
|
|
discarding = null;
|
|
picked = new Set();
|
|
pickAnchor = null;
|
|
context = key;
|
|
++generation;
|
|
pending = null;
|
|
status = null;
|
|
error = '';
|
|
detectionError = '';
|
|
expanded = standalone || (restoring?.expanded ?? false);
|
|
showBranches =
|
|
showWorktrees =
|
|
showRename =
|
|
showUncommit =
|
|
showDeleteBranch =
|
|
confirmDiscard =
|
|
false;
|
|
summary = restoring?.summary ?? '';
|
|
description = restoring?.description ?? '';
|
|
commits = [];
|
|
github = null;
|
|
githubRoot = '';
|
|
view = restoring?.view ?? 'changes';
|
|
resetSelection();
|
|
}
|
|
if (enabled && target) {
|
|
const features = await getMachineFeatures(target);
|
|
if (version !== configuration || !mounted) return;
|
|
gitEnabled = features.git === true;
|
|
if (!gitEnabled) {
|
|
status = null;
|
|
return;
|
|
}
|
|
void refresh();
|
|
if (features.events !== true) return;
|
|
const current = generation;
|
|
stopWatching = watchMachineFiles(
|
|
target,
|
|
directory,
|
|
async () => {
|
|
// An event arriving during a status request must refresh after that request.
|
|
await pending;
|
|
if (current === generation) await refresh();
|
|
},
|
|
(message) => {
|
|
watchError = message;
|
|
}
|
|
);
|
|
}
|
|
};
|
|
$: configure(JSON.stringify([target, chatId, directory]), mounted && active);
|
|
|
|
const selectFile = async (file: GitFile, staged: boolean) => {
|
|
resetSelection();
|
|
selected = { path: file.path, staged, untracked: file.status === 'untracked' };
|
|
const version = diffGeneration;
|
|
loadingDiff = true;
|
|
error = '';
|
|
try {
|
|
const result = await request<{ diff: string }>('diff', {
|
|
file: file.path,
|
|
staged: String(staged),
|
|
untracked: String(selected.untracked)
|
|
});
|
|
if (version === diffGeneration) diff = result.diff;
|
|
} catch (reason) {
|
|
if (version === diffGeneration)
|
|
error = String(reason instanceof Error ? reason.message : reason);
|
|
} finally {
|
|
if (version === diffGeneration) loadingDiff = false;
|
|
}
|
|
};
|
|
const loadHistory = async () => {
|
|
const current = generation;
|
|
try {
|
|
const data = await request<GitCommit[]>('log');
|
|
if (current === generation) commits = data;
|
|
} catch (reason) {
|
|
if (current === generation) error = String(reason instanceof Error ? reason.message : reason);
|
|
}
|
|
};
|
|
const selectCommit = async (commit: GitCommit) => {
|
|
resetSelection();
|
|
selectedCommit = commit;
|
|
const version = diffGeneration;
|
|
loadingDiff = true;
|
|
try {
|
|
const result = await request<{ diff: string }>('show', { ref: commit.hash });
|
|
if (version === diffGeneration) diff = result.diff;
|
|
} catch (reason) {
|
|
if (version === diffGeneration)
|
|
error = String(reason instanceof Error ? reason.message : reason);
|
|
} finally {
|
|
if (version === diffGeneration) loadingDiff = false;
|
|
}
|
|
};
|
|
const loadBranches = async (show: boolean) => {
|
|
creatingBranch = false;
|
|
if (!show) return;
|
|
const current = generation;
|
|
try {
|
|
const data = await request<GitBranch[]>('branches');
|
|
if (current === generation) branches = data;
|
|
} catch (reason) {
|
|
if (current === generation) error = String(reason instanceof Error ? reason.message : reason);
|
|
}
|
|
};
|
|
const loadWorktrees = async (show: boolean) => {
|
|
creatingWorktree = false;
|
|
if (!show) return;
|
|
const current = generation;
|
|
try {
|
|
const data = await request<typeof worktrees>('worktrees');
|
|
if (current === generation) worktrees = data;
|
|
} catch (reason) {
|
|
if (current === generation) error = String(reason instanceof Error ? reason.message : reason);
|
|
}
|
|
};
|
|
const act = async (action: string, fields: Record<string, unknown> = {}) => {
|
|
if (busy) return;
|
|
const current = generation;
|
|
clearSyncFeedback();
|
|
if (action === 'fetch' || action === 'pull' || action === 'push' || action === 'publish')
|
|
syncFeedback = action;
|
|
if (action === 'stage' || action === 'unstage')
|
|
pendingStaging = { action, paths: new Set(fields.paths as string[]) };
|
|
if (action === 'discard') discarding = new Set(fields.paths as string[]);
|
|
busy = true;
|
|
error = '';
|
|
try {
|
|
const result = await gitAction<{ path?: string }>(
|
|
target!,
|
|
status?.root ?? directory,
|
|
action,
|
|
fields
|
|
);
|
|
if (current !== generation) return;
|
|
if (action === 'commit') summary = description = '';
|
|
if (action === 'discard') {
|
|
picked = new Set();
|
|
pickAnchor = null;
|
|
}
|
|
showBranches = false;
|
|
showWorktrees = false;
|
|
resetSelection();
|
|
await pending;
|
|
if (current !== generation) return;
|
|
await refresh(true);
|
|
if (current !== generation) return;
|
|
if (view === 'history') await loadHistory();
|
|
if (current !== generation) return;
|
|
if (syncFeedback) {
|
|
if (status?.is_repo && !detectionError && !error) {
|
|
syncComplete = true;
|
|
syncFeedbackTimer = setTimeout(clearSyncFeedback, 1800);
|
|
} else clearSyncFeedback();
|
|
}
|
|
if (action === 'worktree' && result.path) onOpenDirectory(result.path);
|
|
} catch (reason) {
|
|
if (current === generation) {
|
|
clearSyncFeedback();
|
|
error = String(reason instanceof Error ? reason.message : reason);
|
|
}
|
|
} finally {
|
|
if (current === generation) pendingStaging = discarding = null;
|
|
busy = false;
|
|
}
|
|
};
|
|
// Plain clicks keep their usual behavior and reset the pick; Cmd/Ctrl toggles, Shift extends.
|
|
const pick = (event: MouseEvent, file: GitFile) => {
|
|
if ((event.target as Element | null)?.closest('[data-no-pick]')) return;
|
|
const toggling = event.metaKey || event.ctrlKey;
|
|
if (!toggling && !event.shiftKey) {
|
|
picked = new Set();
|
|
pickAnchor = file.path;
|
|
return;
|
|
}
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
const files = status?.files ?? [];
|
|
const anchor = pickAnchor ?? selected?.path;
|
|
if (event.shiftKey) {
|
|
const from = files.findIndex((entry) => entry.path === anchor);
|
|
const to = files.findIndex((entry) => entry.path === file.path);
|
|
const range = from < 0 ? [file] : files.slice(Math.min(from, to), Math.max(from, to) + 1);
|
|
picked = new Set([...(toggling ? picked : []), ...range.map((entry) => entry.path)]);
|
|
return;
|
|
}
|
|
const next = new Set(picked);
|
|
// Starting a pick while a diff is open includes the file being viewed.
|
|
if (
|
|
!next.size &&
|
|
anchor &&
|
|
anchor !== file.path &&
|
|
files.some((entry) => entry.path === anchor)
|
|
)
|
|
next.add(anchor);
|
|
if (next.has(file.path)) next.delete(file.path);
|
|
else next.add(file.path);
|
|
picked = next;
|
|
pickAnchor = file.path;
|
|
};
|
|
// Nested repositories cannot be discarded, so a bulk discard leaves them out.
|
|
const askDiscard = (files: GitFile[]) => {
|
|
const kept = files.filter((file) => !(file.status === 'untracked' && file.path.endsWith('/')));
|
|
discardFiles = kept.length ? kept : files;
|
|
if (discardFiles.length) confirmDiscard = true;
|
|
};
|
|
const paths = (files: GitFile[]) => [
|
|
...new Set(
|
|
files.flatMap((file) => [file.path, ...(file.original_path ? [file.original_path] : [])])
|
|
)
|
|
];
|
|
const toggle = () => {
|
|
if (standalone) return;
|
|
expanded = !expanded;
|
|
if (expanded) {
|
|
void refresh(true);
|
|
if (view === 'history') void loadHistory();
|
|
}
|
|
};
|
|
const visibility = () => {
|
|
if (!document.hidden) void refresh();
|
|
};
|
|
onMount(() => {
|
|
mounted = true;
|
|
document.addEventListener('visibilitychange', visibility);
|
|
return () => document.removeEventListener('visibilitychange', visibility);
|
|
});
|
|
onDestroy(() => {
|
|
clearSyncFeedback();
|
|
mounted = false;
|
|
++configuration;
|
|
++generation;
|
|
++diffGeneration;
|
|
stopWatching?.();
|
|
});
|
|
</script>
|
|
|
|
{#if status?.is_repo}
|
|
<section
|
|
class="@container relative {standalone
|
|
? 'flex h-full min-h-0 flex-col'
|
|
: 'shrink-0 border-t border-base-200/40 dark:border-base-850/20'}"
|
|
aria-label={$i18n.t('Git')}
|
|
>
|
|
{#if expanded && !standalone}
|
|
<div
|
|
role="separator"
|
|
aria-label={$i18n.t('Resize Git panel')}
|
|
aria-orientation="horizontal"
|
|
aria-valuenow={height}
|
|
tabindex="0"
|
|
class="absolute inset-x-0 -top-px h-px z-20 cursor-row-resize touch-none border-t border-transparent hover:border-base-300/60 dark:hover:border-base-800 transition"
|
|
on:pointerdown={(event) => {
|
|
event.preventDefault();
|
|
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
|
resizing = true;
|
|
resizeY = event.clientY;
|
|
resizeHeight = height;
|
|
}}
|
|
on:pointermove={(event) => {
|
|
if (resizing)
|
|
height = Math.max(
|
|
140,
|
|
Math.min(window.innerHeight * 0.65, resizeHeight + resizeY - event.clientY)
|
|
);
|
|
}}
|
|
on:pointerup={() => (resizing = false)}
|
|
on:pointercancel={() => (resizing = false)}
|
|
on:keydown={(event) => {
|
|
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
|
event.preventDefault();
|
|
height = Math.max(
|
|
140,
|
|
Math.min(window.innerHeight * 0.65, height + (event.key === 'ArrowUp' ? 20 : -20))
|
|
);
|
|
}
|
|
}}
|
|
>
|
|
<span class="absolute inset-x-0 -top-1.5 -bottom-1.5 bg-transparent"></span>
|
|
</div>
|
|
{/if}
|
|
<div class="flex min-w-0 items-center h-7 pl-3 pr-1 text-base-400 dark:text-base-600">
|
|
<Dropdown side="top" maxHeight="15rem" bind:show={showBranches} onOpenChange={loadBranches}>
|
|
<button
|
|
class="group/selector flex min-w-0 max-w-32 shrink items-center gap-1.5 h-6 -ml-1.5 px-1.5 rounded-md hover:text-base-700 dark:hover:text-base-300 transition-colors duration-75"
|
|
aria-label={$i18n.t('Switch branch')}
|
|
disabled={busy}
|
|
><Icon name="git-branch" size={12} /><span
|
|
class="min-w-0 truncate whitespace-nowrap text-[0.6875rem] text-base-600 dark:text-base-400 group-hover/selector:text-base-700 dark:group-hover/selector:text-base-300"
|
|
>{branchLabel}</span
|
|
><Icon name="chevron-down" size={9} /></button
|
|
>
|
|
<div slot="content">
|
|
<DropdownMenu className="w-56 text-xs">
|
|
<div class="flex items-center gap-1.5 h-6 mt-0.5 mx-2">
|
|
<Icon name="search" size={13} class="text-base-300 dark:text-base-600" /><input
|
|
class="min-w-0 flex-1 bg-transparent text-[0.6875rem] text-base-500 dark:text-base-400 placeholder:text-base-300 dark:placeholder:text-base-600 outline-none"
|
|
aria-label={$i18n.t('Search branches')}
|
|
placeholder={$i18n.t('Search branches')}
|
|
bind:value={branchSearch}
|
|
/>
|
|
</div>
|
|
|
|
<div class="max-h-36 overflow-y-auto scrollbar-hidden py-0.5">
|
|
{#each branches.filter((branch) => branch.name
|
|
.toLowerCase()
|
|
.includes(branchSearch.toLowerCase())) as branch}
|
|
<div
|
|
class="group flex items-center gap-1 w-full h-6 rounded-xl text-xs transition-colors duration-75 {branch.current
|
|
? 'bg-base-100/40 dark:bg-base-800/25 text-base-900 dark:text-base-0'
|
|
: 'text-base-500 dark:text-base-400 hover:bg-base-100/30 dark:hover:bg-base-800/20'}"
|
|
>
|
|
<button
|
|
class="flex items-center gap-2 min-w-0 flex-1 h-full px-2 text-inherit"
|
|
disabled={busy || branch.current}
|
|
on:click={() => act('checkout', { branch: branch.name })}
|
|
><Icon name="git-branch" size={14} /><span class="flex-1 text-left truncate"
|
|
>{branch.name}</span
|
|
>{#if branch.current}<Icon
|
|
name="check"
|
|
size={12}
|
|
class="text-base-400 dark:text-base-500"
|
|
/>{/if}</button
|
|
>
|
|
<Dropdown side="top" align="end" closeOnSelect>
|
|
<button
|
|
class="flex items-center justify-center w-5 h-5 mr-0.5 rounded-lg shrink-0 text-base-400 hover:text-base-600 dark:hover:text-base-300 hover:bg-base-100/30 dark:hover:bg-base-800/20"
|
|
aria-label={`${$i18n.t('Branch actions')} ${branch.name}`}
|
|
><Icon name="three-dots" size={12} /></button
|
|
>
|
|
<div slot="content">
|
|
<DropdownMenu className="w-40">
|
|
{#if branch.is_local !== false}<button
|
|
disabled={busy}
|
|
on:click={() => {
|
|
actionBranch = branch;
|
|
showBranches = false;
|
|
showRename = true;
|
|
}}><Icon name="pencil" size={13} />{$i18n.t('Rename')}</button
|
|
>{/if}
|
|
<button
|
|
on:click={async () => {
|
|
if (!(await copyToClipboard(branch.name))) {
|
|
error = $i18n.t('Could not copy branch name');
|
|
}
|
|
}}><Icon name="copy" size={13} />{$i18n.t('Copy branch name')}</button
|
|
>
|
|
{#if branch.is_local !== false && !branch.current}<button
|
|
disabled={busy}
|
|
on:click={() => {
|
|
actionBranch = branch;
|
|
showBranches = false;
|
|
showDeleteBranch = true;
|
|
}}><Icon name="xmark" size={13} />{$i18n.t('Delete')}</button
|
|
>{/if}
|
|
</DropdownMenu>
|
|
</div>
|
|
</Dropdown>
|
|
</div>
|
|
{/each}
|
|
</div>
|
|
{#if creatingBranch}<form
|
|
class="flex items-center gap-2 h-7 px-2"
|
|
on:submit|preventDefault={() => act('branch', { branch: newBranch })}
|
|
>
|
|
<Icon name="git-branch" size={14} class="text-base-400" /><input
|
|
class="min-w-0 flex-1 bg-transparent text-xs outline-none text-base-900 dark:text-base-0"
|
|
aria-label={$i18n.t('New branch')}
|
|
placeholder={$i18n.t('New branch')}
|
|
bind:value={newBranch}
|
|
/><button disabled={busy || !newBranch.trim()} aria-label={$i18n.t('Create branch')}
|
|
><Icon name="check" size={12} /></button
|
|
><button
|
|
type="button"
|
|
aria-label={$i18n.t('Cancel')}
|
|
on:click={() => (creatingBranch = false)}><Icon name="xmark" size={12} /></button
|
|
>
|
|
</form>
|
|
{:else}<div>
|
|
<button
|
|
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-base-600 dark:text-base-300 hover:bg-base-50 dark:hover:bg-base-0/5"
|
|
on:click={() => (creatingBranch = true)}
|
|
><Icon name="plus" size={14} />{$i18n.t('New branch')}</button
|
|
>
|
|
</div>{/if}
|
|
</DropdownMenu>
|
|
</div>
|
|
</Dropdown>
|
|
<Dropdown side="top" maxHeight="15rem" bind:show={showWorktrees} onOpenChange={loadWorktrees}>
|
|
<button
|
|
class="group/selector flex min-w-0 max-w-32 shrink items-center gap-1.5 h-6 px-1.5 rounded-md hover:text-base-700 dark:hover:text-base-300 transition-colors duration-75"
|
|
aria-label={$i18n.t('Worktrees')}
|
|
disabled={busy}
|
|
>
|
|
<Icon name="folder" size={12} /><span
|
|
class="min-w-0 truncate whitespace-nowrap text-[0.6875rem] text-base-500 dark:text-base-500 group-hover/selector:text-base-700 dark:group-hover/selector:text-base-300"
|
|
>{status.root?.split('/').pop()}</span
|
|
><Icon name="chevron-down" size={9} />
|
|
</button>
|
|
<div slot="content">
|
|
<DropdownMenu className="w-56 text-xs">
|
|
<div class="flex items-center gap-1.5 h-6 mt-0.5 mx-2">
|
|
<Icon name="search" size={13} class="text-base-300 dark:text-base-600" /><input
|
|
class="min-w-0 flex-1 bg-transparent text-[0.6875rem] text-base-500 dark:text-base-400 placeholder:text-base-300 dark:placeholder:text-base-600 outline-none"
|
|
aria-label={$i18n.t('Search worktrees')}
|
|
placeholder={$i18n.t('Search worktrees')}
|
|
bind:value={worktreeSearch}
|
|
/>
|
|
</div>
|
|
<div class="max-h-36 overflow-y-auto scrollbar-hidden py-0.5">
|
|
{#each worktrees.filter((tree) => `${tree.branch} ${tree.path}`
|
|
.toLowerCase()
|
|
.includes(worktreeSearch.toLowerCase())) as tree}<button
|
|
class="flex items-center gap-2 w-full h-6 px-2 rounded-xl text-xs {tree.current
|
|
? 'bg-base-100 dark:bg-base-0/6 text-base-900 dark:text-base-0'
|
|
: 'text-base-600 dark:text-base-300 hover:bg-base-50 dark:hover:bg-base-0/5'}"
|
|
disabled={tree.current}
|
|
on:click={() => {
|
|
showWorktrees = false;
|
|
onOpenDirectory(tree.path);
|
|
}}
|
|
><Icon name="folder" size={14} /><span class="min-w-0 flex-1 text-left truncate"
|
|
>{tree.branch || tree.path.split('/').pop()}</span
|
|
><span
|
|
class="min-w-0 max-w-[45%] truncate text-[0.6875rem] text-base-300 dark:text-base-600"
|
|
>{tree.path}</span
|
|
>{#if tree.current}<Icon name="check" size={12} />{/if}</button
|
|
>{/each}
|
|
</div>
|
|
{#if creatingWorktree}<form
|
|
class="px-2 py-1 space-y-1"
|
|
on:submit|preventDefault={() =>
|
|
act('worktree', { branch: worktreeBranch, target: worktreePath })}
|
|
>
|
|
<input
|
|
class="w-full h-6 bg-transparent text-xs outline-none"
|
|
aria-label={$i18n.t('Worktree branch')}
|
|
placeholder={$i18n.t('New branch')}
|
|
bind:value={worktreeBranch}
|
|
/><input
|
|
class="w-full h-6 bg-transparent text-xs outline-none"
|
|
aria-label={$i18n.t('Worktree directory')}
|
|
placeholder={$i18n.t('Worktree directory')}
|
|
bind:value={worktreePath}
|
|
/>
|
|
<div class="flex items-center justify-end gap-2">
|
|
<button type="button" on:click={() => (creatingWorktree = false)}
|
|
>{$i18n.t('Cancel')}</button
|
|
><button disabled={busy || !worktreeBranch.trim() || !worktreePath.trim()}
|
|
>{$i18n.t('Create worktree')}</button
|
|
>
|
|
</div>
|
|
</form>
|
|
{:else}<div>
|
|
<button
|
|
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-base-600 dark:text-base-300 hover:bg-base-50 dark:hover:bg-base-0/5"
|
|
on:click={() => (creatingWorktree = true)}
|
|
><Icon name="plus" size={14} />{$i18n.t('New worktree')}</button
|
|
>
|
|
</div>{/if}
|
|
</DropdownMenu>
|
|
</div>
|
|
</Dropdown>
|
|
<button
|
|
class="flex flex-1 min-w-0 h-full items-center justify-end gap-1.5 pl-1 mr-2 text-[0.625rem] font-mono text-left whitespace-nowrap"
|
|
aria-label={$i18n.t('Git changes')}
|
|
aria-expanded={expanded}
|
|
on:click={toggle}
|
|
>
|
|
{#if status.files.length}<span class="truncate"
|
|
>{status.files.length} {$i18n.t('changed')}</span
|
|
>{/if}
|
|
{#if additions || deletions}<span class="flex gap-1 shrink-0"
|
|
><span class="text-green-600 dark:text-green-400">+{additions}</span><span
|
|
class="text-base-500 dark:text-base-400">-{deletions}</span
|
|
></span
|
|
>{/if}
|
|
</button>
|
|
{#if status.ahead || status.behind}
|
|
<span
|
|
class="flex shrink-0 items-center gap-1.5 text-[0.625rem] font-mono whitespace-nowrap"
|
|
>
|
|
{#if status.ahead}<span>↑{status.ahead}</span>{/if}
|
|
{#if status.behind}<span>↓{status.behind}</span>{/if}
|
|
</span>
|
|
{/if}
|
|
<span
|
|
role="status"
|
|
class="shrink-0 text-[0.625rem] font-mono whitespace-nowrap text-base-500 dark:text-base-400 {feedbackMessage
|
|
? 'ml-1.5'
|
|
: ''}">{feedbackMessage ? $i18n.t(feedbackMessage) : ''}</span
|
|
>
|
|
<Tooltip
|
|
content={[
|
|
$i18n.t(busy && syncFeedback ? syncMessage : syncLabel),
|
|
...(watchError ? [$i18n.t(watchError)] : [])
|
|
].join('\n')}
|
|
>
|
|
<button
|
|
class="flex shrink-0 items-center justify-center h-6 w-6 text-base-400 hover:text-base-600 dark:hover:text-base-300 transition-colors duration-75"
|
|
aria-label={$i18n.t(busy && syncFeedback ? syncMessage : syncLabel)}
|
|
aria-busy={busy && !!syncFeedback}
|
|
on:click={() => act(syncAction)}
|
|
disabled={busy}
|
|
><span
|
|
class="flex"
|
|
class:git-fetching={busy && syncFeedback === 'fetch'}
|
|
class:git-pulling={busy && syncFeedback === 'pull'}
|
|
class:git-pushing={busy && (syncFeedback === 'push' || syncFeedback === 'publish')}
|
|
><Icon name={syncIcon} size={10} /></span
|
|
></button
|
|
>
|
|
</Tooltip>
|
|
{#if onOpenTab && !standalone}
|
|
<Tooltip content={$i18n.t('Open in tab')}>
|
|
<button
|
|
class="flex h-6 w-5 items-center justify-center text-base-400 hover:text-base-600 dark:hover:text-base-300 shrink-0 transition-colors duration-75"
|
|
aria-label={$i18n.t('Open in tab')}
|
|
on:click={() => onOpenTab?.(status?.root ?? directory)}
|
|
><Icon name="arrow-up-right" size={13} /></button
|
|
>
|
|
</Tooltip>
|
|
{/if}
|
|
{#if !standalone}
|
|
<button
|
|
class="flex h-6 w-5 items-center justify-center text-base-500 dark:text-base-400 hover:text-base-700 dark:hover:text-base-200 ml-0.5 shrink-0"
|
|
aria-label={expanded ? $i18n.t('Collapse Git panel') : $i18n.t('Expand Git panel')}
|
|
on:click={toggle}
|
|
><Icon name={expanded ? 'chevron-down' : 'chevron-up'} size={14} /></button
|
|
>
|
|
{/if}
|
|
</div>
|
|
{#if error}<div
|
|
role="alert"
|
|
class="px-3 py-2 text-xs text-base-500 dark:text-base-400 break-words"
|
|
>
|
|
{error}
|
|
</div>{/if}
|
|
{#if expanded}
|
|
<div
|
|
class="flex flex-col min-h-0 {standalone
|
|
? 'flex-1'
|
|
: 'max-h-[65dvh]'} border-t border-base-100/50 dark:border-base-0/2"
|
|
style:height={standalone ? null : `${height + 32}px`}
|
|
>
|
|
<div
|
|
class="flex items-center gap-0.5 px-1 h-8 shrink-0 border-b border-base-100/50 dark:border-base-0/2"
|
|
>
|
|
{#each ['changes', 'history', ...(github?.available ? [...(github.issues ? ['issues'] : []), 'pull requests'] : [])] as section}<button
|
|
class="px-2.5 py-0.5 shrink-0 rounded-md text-[0.6875rem] font-normal transition-colors duration-75 {view ===
|
|
section
|
|
? 'bg-base-100/40 dark:bg-base-800/25 text-base-900 dark:text-base-0'
|
|
: 'text-base-400 hover:text-base-600 dark:hover:text-base-300'}"
|
|
on:click={() => {
|
|
view = section as typeof view;
|
|
resetSelection();
|
|
if (view === 'history') void loadHistory();
|
|
}}
|
|
>{$i18n.t(
|
|
section === 'changes'
|
|
? 'Changes'
|
|
: section === 'history'
|
|
? 'History'
|
|
: section === 'issues'
|
|
? 'Issues'
|
|
: 'Pull requests'
|
|
)}{#if section === 'changes' && status.files.length}<span
|
|
class="ml-1 text-base-400 dark:text-base-500">{status.files.length}</span
|
|
>{:else if section === 'pull requests' && openPullRequests}<span
|
|
class="ml-1 text-base-400 dark:text-base-500">{openPullRequests}</span
|
|
>{:else if section === 'issues' && openIssues}<span
|
|
class="ml-1 text-base-400 dark:text-base-500">{openIssues}</span
|
|
>{/if}</button
|
|
>{/each}
|
|
<div class="flex-1"></div>
|
|
{#if remoteWebUrl}
|
|
<Tooltip content={$i18n.t('View on {{platform}}', { platform: remotePlatform })}>
|
|
<a
|
|
href={remoteWebUrl}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
aria-label={$i18n.t('View on {{platform}}', { platform: remotePlatform })}
|
|
class="flex items-center justify-center w-5 h-4 py-0.5 rounded-md text-base-400 hover:text-base-600 dark:hover:text-base-300"
|
|
><Icon name="external-link" size={10} /></a
|
|
>
|
|
</Tooltip>
|
|
{/if}
|
|
<Dropdown side="top" align="end">
|
|
<button
|
|
class="flex items-center justify-center w-5 h-4 py-0.5 rounded-md text-base-400 hover:text-base-600 dark:hover:text-base-300"
|
|
aria-label={$i18n.t('Diff settings')}><Icon name="settings" size={10} /></button
|
|
>
|
|
<div slot="content">
|
|
<DropdownMenu className="w-48"
|
|
><div class="py-0.5 text-xs font-normal">
|
|
<button
|
|
class="flex h-6 w-full items-center gap-2 rounded-xl px-2 text-left text-xs text-base-500 dark:text-base-400 hover:bg-base-100 dark:hover:bg-base-0/6"
|
|
aria-pressed={hideWhitespace}
|
|
on:click={() => (hideWhitespace = !hideWhitespace)}
|
|
><Icon name="code" size={13} /><span class="min-w-0 flex-1 truncate"
|
|
>{$i18n.t('Hide whitespace')}</span
|
|
><span
|
|
class="relative h-3.5 w-6 rounded-full {hideWhitespace
|
|
? 'bg-base-900 dark:bg-base-0'
|
|
: 'bg-base-300 dark:bg-base-700'}"
|
|
><span
|
|
class="absolute top-0.5 h-2.5 w-2.5 rounded-full {hideWhitespace
|
|
? 'left-3 bg-base-0 dark:bg-base-1000'
|
|
: 'left-0.5 bg-base-0 dark:bg-base-500'}"
|
|
></span></span
|
|
></button
|
|
>
|
|
<div
|
|
class="px-2 pb-0.5 pt-1 text-[0.625rem] leading-none uppercase text-base-400 dark:text-base-600"
|
|
>
|
|
{$i18n.t('Display')}
|
|
</div>
|
|
{#each ['unified', 'split'] as mode}<button
|
|
class="flex h-6 w-full items-center gap-2 rounded-xl px-2 text-left text-xs {diffMode ===
|
|
mode
|
|
? 'bg-base-100 dark:bg-base-0/6 text-base-900 dark:text-base-0'
|
|
: 'text-base-500 dark:text-base-400'}"
|
|
on:click={() => (diffMode = mode as typeof diffMode)}
|
|
><Icon name={mode === 'unified' ? 'list' : 'split-view'} size={13} /><span
|
|
class="flex-1">{$i18n.t(mode === 'unified' ? 'Unified' : 'Split')}</span
|
|
>{#if diffMode === mode}<Icon name="check" size={11} />{/if}</button
|
|
>{/each}
|
|
</div></DropdownMenu
|
|
>
|
|
</div>
|
|
</Dropdown>
|
|
</div>
|
|
<div class="flex min-h-0 flex-1 overflow-hidden" bind:clientWidth={splitWidth}>
|
|
{#if view === 'pull requests' && target && status.root}
|
|
{#key status.root}<GitPullRequests
|
|
listWidth={effectiveListWidth}
|
|
{maxListWidth}
|
|
onResizeList={(width) => (listWidth = width)}
|
|
mode={diffMode}
|
|
{hideWhitespace}
|
|
{target}
|
|
directory={status.root}
|
|
branch={status.branch}
|
|
defaultBranch={github?.default_branch ?? 'main'}
|
|
onDraft={onDraftPrompt}
|
|
onChange={() => {
|
|
void refresh(true);
|
|
void loadGitHub(true);
|
|
}}
|
|
/>{/key}
|
|
{:else if view === 'issues' && target && status.root}
|
|
{#key status.root}<GitIssues
|
|
listWidth={effectiveListWidth}
|
|
{maxListWidth}
|
|
onResizeList={(width) => (listWidth = width)}
|
|
{target}
|
|
directory={status.root}
|
|
onDraft={onDraftPrompt}
|
|
onChange={() => void loadGitHub(true)}
|
|
/>{/key}
|
|
{:else}
|
|
<div
|
|
class="min-w-0 flex-1 flex-col overflow-hidden @min-[560px]:flex @min-[560px]:flex-[0_0_var(--git-list-width)] {selected ||
|
|
selectedCommit
|
|
? 'hidden'
|
|
: 'flex'}"
|
|
style:--git-list-width={`${effectiveListWidth}px`}
|
|
>
|
|
{#if view === 'changes'}
|
|
{#if status.files.length}
|
|
<div
|
|
class="flex min-w-0 items-center gap-1.5 h-7 pe-2.5 border-b border-base-100/50 dark:border-base-0/2 shrink-0"
|
|
>
|
|
<button
|
|
class="flex min-w-0 flex-1 items-center gap-1.5 h-full ps-2.5 hover:bg-base-50 dark:hover:bg-base-0/3"
|
|
disabled={busy}
|
|
role="checkbox"
|
|
aria-checked={allStaged ? true : someStaged ? 'mixed' : false}
|
|
aria-busy={!!pendingStaging}
|
|
aria-label={$i18n.t(allStaged ? 'Unstage all' : 'Stage all')}
|
|
on:click={() =>
|
|
act(allStaged ? 'unstage' : 'stage', { paths: paths(status?.files ?? []) })}
|
|
>
|
|
<span
|
|
class:opacity-60={!!pendingStaging}
|
|
class="flex items-center justify-center w-3 h-3 me-1 rounded border shrink-0 border-base-300 dark:border-base-600 {allStaged
|
|
? 'bg-base-800 dark:bg-base-0'
|
|
: someStaged
|
|
? 'bg-base-400 dark:bg-base-500'
|
|
: ''}"
|
|
>{#if allStaged || someStaged}<Icon
|
|
name={allStaged ? 'check' : 'minus'}
|
|
size={7}
|
|
class="text-white dark:text-base-1000"
|
|
/>{/if}</span
|
|
>
|
|
<span
|
|
class="min-w-0 truncate text-[0.6875rem] text-base-600 dark:text-base-400"
|
|
>{status.files.length}
|
|
{$i18n.t(
|
|
status.files.length === 1 ? 'changed file' : 'changed files'
|
|
)}</span
|
|
>
|
|
</button>
|
|
{#if pickedFiles.length > 1}
|
|
<button
|
|
class="flex shrink-0 items-center gap-0.5 text-[0.625rem] text-base-500 dark:text-base-400 hover:text-base-700 dark:hover:text-base-200"
|
|
aria-label={$i18n.t('Clear selection')}
|
|
on:click={() => {
|
|
picked = new Set();
|
|
pickAnchor = null;
|
|
}}
|
|
>{$i18n.t('{{COUNT}} selected', { COUNT: pickedFiles.length })}<Icon
|
|
name="xmark"
|
|
size={10}
|
|
/></button
|
|
>
|
|
{/if}
|
|
<Dropdown align="end" closeOnSelect>
|
|
<button
|
|
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-base-400 hover:text-base-600 dark:hover:text-base-300"
|
|
aria-label={$i18n.t('More options')}
|
|
><Icon name="three-dots" size={12} /></button
|
|
>
|
|
<div slot="content">
|
|
<DropdownMenu className="w-48">
|
|
{#if pickedFiles.length > 1}<button
|
|
disabled={busy}
|
|
on:click={() => askDiscard(pickedFiles)}
|
|
>{$i18n.t('Discard changes to {{COUNT}} files', {
|
|
COUNT: pickedFiles.length
|
|
})}</button
|
|
>{/if}
|
|
<button disabled={busy} on:click={() => askDiscard(status?.files ?? [])}
|
|
>{$i18n.t('Discard all changes')}</button
|
|
>
|
|
</DropdownMenu>
|
|
</div>
|
|
</Dropdown>
|
|
</div>
|
|
{/if}
|
|
<div
|
|
class="min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto scrollbar-hidden"
|
|
>
|
|
{#each status.files as file (file.path)}
|
|
{@const checked = stageStates.get(file.path) ?? false}
|
|
{@const staging = pendingStaging?.paths.has(file.path) ?? false}
|
|
{@const inPick = picked.has(file.path) && pickedFiles.length > 1}
|
|
<!-- svelte-ignore a11y_no_static_element_interactions a11y_click_events_have_key_events -->
|
|
<div
|
|
class="group flex min-w-0 items-center gap-1.5 w-full h-7 px-2.5 text-left select-none transition-colors duration-75 {selected?.path ===
|
|
file.path || picked.has(file.path)
|
|
? 'bg-base-100/40 dark:bg-base-800/25'
|
|
: 'hover:bg-base-50 dark:hover:bg-base-0/3'}"
|
|
class:opacity-60={discarding?.has(file.path)}
|
|
on:click|capture={(event) => pick(event, file)}
|
|
>
|
|
<button
|
|
data-no-pick
|
|
class="flex items-center justify-center w-3 h-3 me-1 rounded border shrink-0 border-base-300 dark:border-base-600 {checked
|
|
? 'bg-base-800 dark:bg-base-0'
|
|
: 'hover:border-base-500 dark:hover:border-base-400'}"
|
|
disabled={busy}
|
|
class:opacity-60={staging}
|
|
role="checkbox"
|
|
aria-checked={checked}
|
|
aria-busy={staging}
|
|
aria-label={`${$i18n.t(checked ? 'Unstage' : 'Stage')} ${file.path}`}
|
|
on:click={() =>
|
|
act(file.staged ? 'unstage' : 'stage', { paths: paths([file]) })}
|
|
>
|
|
{#if checked}<Icon
|
|
name={checked === 'mixed' ? 'minus' : 'check'}
|
|
size={7}
|
|
class="text-white dark:text-base-1000"
|
|
/>{/if}
|
|
</button>
|
|
<div class="flex min-w-0 flex-1 items-center gap-0.5 h-full">
|
|
{#if file.path.includes('/')}<button
|
|
class="min-w-0 truncate text-[0.625rem] text-base-400 dark:text-base-600"
|
|
aria-label={`${$i18n.t('View changes')} ${file.path}`}
|
|
on:click={() => selectFile(file, file.staged)}
|
|
>{file.path.slice(0, file.path.lastIndexOf('/') + 1)}</button
|
|
>{/if}
|
|
<button
|
|
class="min-w-0 truncate text-[0.6875rem] text-base-800 dark:text-base-200 hover:underline"
|
|
aria-label={`${$i18n.t('Open file')} ${file.path}`}
|
|
on:click={() => {
|
|
if (status?.root)
|
|
onOpenFile(`${status.root.replace(/\/$/, '')}/${file.path}`);
|
|
}}>{file.path.split('/').pop()}</button
|
|
>
|
|
<button
|
|
class="min-w-0 flex-1 self-stretch"
|
|
aria-label={`${$i18n.t('View changes')} ${file.path}`}
|
|
on:click={() => selectFile(file, file.staged)}
|
|
></button>
|
|
</div>
|
|
{#if file.binary}<span
|
|
class="text-[0.625rem] font-mono font-normal text-base-400"
|
|
title={file.status}
|
|
>{file.status === 'untracked' ? 'U' : file.status[0].toUpperCase()}</span
|
|
>{:else}<button
|
|
class="flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-normal"
|
|
aria-label={`${$i18n.t('View changes')} ${file.path}`}
|
|
on:click={() => selectFile(file, file.staged)}
|
|
><span class="text-green-600 dark:text-green-400">+{file.additions}</span
|
|
><span class="text-base-500 dark:text-base-400">-{file.deletions}</span
|
|
></button
|
|
>{/if}
|
|
<Dropdown side="top" align="end" closeOnSelect>
|
|
<button
|
|
data-no-pick
|
|
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-base-400 hover:text-base-600 dark:hover:text-base-300"
|
|
aria-label={`${$i18n.t('File actions')} ${file.path}`}
|
|
><Icon name="three-dots" size={12} /></button
|
|
>
|
|
<div slot="content">
|
|
<DropdownMenu className="w-44">
|
|
<button
|
|
on:click={() =>
|
|
onOpenFile(`${status?.root?.replace(/\/$/, '')}/${file.path}`)}
|
|
>{$i18n.t('Open file')}</button
|
|
>
|
|
{#if file.staged}<button on:click={() => selectFile(file, true)}
|
|
>{$i18n.t('Staged changes')}</button
|
|
>{/if}
|
|
{#if file.unstaged}<button on:click={() => selectFile(file, false)}
|
|
>{$i18n.t('Working tree changes')}</button
|
|
>{/if}
|
|
<button
|
|
disabled={busy}
|
|
on:click={() => askDiscard(inPick ? pickedFiles : [file])}
|
|
>{inPick
|
|
? $i18n.t('Discard changes to {{COUNT}} files', {
|
|
COUNT: pickedFiles.length
|
|
})
|
|
: $i18n.t('Discard changes')}</button
|
|
>
|
|
</DropdownMenu>
|
|
</div>
|
|
</Dropdown>
|
|
</div>
|
|
{/each}
|
|
{#if !status.files.length}<div
|
|
class="flex h-full items-center justify-center p-3 text-center text-[0.6875rem] text-base-400 dark:text-base-600"
|
|
>
|
|
{$i18n.t('No changes')}
|
|
</div>{/if}
|
|
</div>
|
|
<form
|
|
class="border-t border-base-100/50 dark:border-base-0/2 px-2 pb-1.5 shrink-0"
|
|
on:submit|preventDefault={() =>
|
|
act('commit', {
|
|
message: [summary.trim(), description.trim()].filter(Boolean).join('\n\n')
|
|
})}
|
|
>
|
|
<div class="rounded-lg overflow-hidden">
|
|
<input
|
|
class="w-full h-6 px-1 bg-transparent text-[0.6875rem] text-base-900 dark:text-base-0 placeholder:text-base-400 dark:placeholder:text-base-600 outline-none"
|
|
aria-label={$i18n.t('Commit summary')}
|
|
placeholder={$i18n.t('Summary')}
|
|
bind:value={summary}
|
|
/>
|
|
<textarea
|
|
class="block w-full px-1 py-1 bg-transparent text-[0.6875rem] text-base-900 dark:text-base-0 placeholder:text-base-400 dark:placeholder:text-base-600 outline-none resize-none border-t border-base-100/50 dark:border-base-0/2"
|
|
rows="3"
|
|
aria-label={$i18n.t('Description')}
|
|
placeholder={$i18n.t('Description')}
|
|
bind:value={description}
|
|
></textarea>
|
|
</div>
|
|
<button
|
|
class="w-full h-6 mt-1 rounded-lg text-[0.6875rem] font-normal transition-colors duration-75 {staged.length &&
|
|
summary.trim()
|
|
? 'bg-base-900 dark:bg-base-0 text-base-0 dark:text-base-1000 hover:bg-base-800 dark:hover:bg-base-0/90'
|
|
: 'bg-base-100 dark:bg-base-0/6 text-base-400 dark:text-base-600 cursor-default'}"
|
|
disabled={busy || !staged.length || !summary.trim()}
|
|
>
|
|
{staged.length
|
|
? $i18n.t(
|
|
staged.length === 1
|
|
? 'Commit {{count}} file to {{branch}}'
|
|
: 'Commit {{count}} files to {{branch}}',
|
|
{ count: staged.length, branch: status.branch }
|
|
)
|
|
: $i18n.t('Commit to {{branch}}', { branch: status.branch })}
|
|
</button>
|
|
</form>
|
|
{:else}
|
|
<div class="min-h-0 flex-1 overflow-y-auto scrollbar-hidden">
|
|
{#each commits as commit, index}<div
|
|
class="group flex min-w-0 items-center border-b border-base-50/50 dark:border-base-0/2 transition-colors duration-75 {selectedCommit?.hash ===
|
|
commit.hash
|
|
? 'bg-base-100/40 dark:bg-base-800/25'
|
|
: 'hover:bg-base-100/30 dark:hover:bg-base-800/20'}"
|
|
>
|
|
<Tooltip content={commit.hash} className="flex min-w-0 flex-1"
|
|
><button
|
|
class="flex min-w-0 flex-1 items-center gap-1.5 px-2.5 py-1.5 text-left"
|
|
on:click={() => selectCommit(commit)}
|
|
>
|
|
{#if index < status.ahead}<span
|
|
class="w-1.5 h-1.5 rounded-full bg-blue-500 dark:bg-blue-400 shrink-0"
|
|
title={$i18n.t('Unpushed')}
|
|
></span>{/if}
|
|
<div class="flex flex-col min-w-0 flex-1">
|
|
<span class="text-xs text-base-800 dark:text-base-200 truncate"
|
|
>{commit.message}</span
|
|
><span
|
|
class="text-[0.625rem] text-base-400 dark:text-base-600 font-mono truncate"
|
|
>{commit.author} · {relativeTime(commit.date)}</span
|
|
>
|
|
</div>
|
|
</button></Tooltip
|
|
><Dropdown side="top" align="end" closeOnSelect
|
|
><button
|
|
class="flex items-center justify-center w-5 h-5 mr-1 rounded shrink-0 opacity-0 group-hover:opacity-100 focus:opacity-100 text-base-400 hover:text-base-600 dark:hover:text-base-300"
|
|
aria-label={`${$i18n.t('Commit actions')} ${commit.short_hash}`}
|
|
><Icon name="three-dots" size={12} /></button
|
|
>
|
|
<div slot="content">
|
|
<DropdownMenu className="w-44"
|
|
>{#if index === 0}<button
|
|
disabled={busy}
|
|
on:click={() => (showUncommit = true)}
|
|
><Icon name="undo" size={13} />{$i18n.t('Undo last commit')}</button
|
|
>{/if}<button
|
|
on:click={async () => {
|
|
if (!(await copyToClipboard(commit.hash))) {
|
|
error = $i18n.t('Could not copy commit hash');
|
|
}
|
|
}}><Icon name="copy" size={13} />{$i18n.t('Copy commit hash')}</button
|
|
></DropdownMenu
|
|
>
|
|
</div></Dropdown
|
|
>
|
|
</div>{/each}
|
|
{#if !commits.length}<div
|
|
class="flex h-full items-center justify-center p-3 text-center text-[0.6875rem] text-base-400 dark:text-base-600"
|
|
>
|
|
{$i18n.t('No commits yet')}
|
|
</div>{/if}
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
<GitListDivider
|
|
width={effectiveListWidth}
|
|
max={maxListWidth}
|
|
onResize={(width) => (listWidth = width)}
|
|
/>
|
|
<div
|
|
class="min-w-0 flex-1 flex-col overflow-hidden @min-[560px]:flex {selected ||
|
|
selectedCommit
|
|
? 'flex'
|
|
: 'hidden'}"
|
|
>
|
|
{#if selected || selectedCommit}
|
|
<div
|
|
class="flex items-center gap-2 px-2 h-6 shrink-0 border-b border-base-100/50 dark:border-base-0/2 text-[0.625rem] font-mono text-base-400 dark:text-base-600"
|
|
>
|
|
<button
|
|
class="@min-[560px]:hidden"
|
|
aria-label={$i18n.t('Back to changes')}
|
|
on:click={resetSelection}><Icon name="chevron-left" size={12} /></button
|
|
><span class="min-w-0 flex-1 truncate"
|
|
>{selected?.path ??
|
|
`${selectedCommit?.short_hash} · ${selectedCommit?.message}`}</span
|
|
>
|
|
{#if diff && !loadingDiff}<span class="flex shrink-0 items-center gap-1"
|
|
><span class="text-green-600 dark:text-green-400">+{diffStats.additions}</span
|
|
><span class="text-base-500 dark:text-base-400">-{diffStats.deletions}</span
|
|
></span
|
|
>{/if}
|
|
</div>
|
|
<div class="min-h-0 flex-1 overflow-auto scrollbar-hidden text-[0.6875rem]">
|
|
{#if loadingDiff}<p
|
|
class="flex h-full items-center justify-center p-3 text-center text-base-400"
|
|
>
|
|
{$i18n.t('Loading...')}
|
|
</p>{:else if diff}<GitDiff
|
|
code={diff}
|
|
mode={diffMode}
|
|
{hideWhitespace}
|
|
/>{:else}<div
|
|
class="flex h-full items-center justify-center p-3 text-center text-base-400 dark:text-base-600"
|
|
>
|
|
{$i18n.t('No text changes')}
|
|
</div>{/if}
|
|
</div>
|
|
{:else}<div
|
|
class="flex h-full items-center justify-center p-3 text-center text-[0.6875rem] text-base-400 dark:text-base-600"
|
|
>
|
|
{$i18n.t(
|
|
view === 'history'
|
|
? 'Select a commit to view changes'
|
|
: 'Select a file to view changes'
|
|
)}
|
|
</div>{/if}
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
</section>
|
|
{:else if detectionError}
|
|
<div
|
|
class="flex h-7 shrink-0 items-center gap-1.5 border-t border-base-100/50 dark:border-base-0/2 px-3 text-[0.6875rem] text-base-500 dark:text-base-400"
|
|
>
|
|
<Icon name="git-branch" size={12} />
|
|
<Tooltip content={detectionError} className="min-w-0 flex-1"
|
|
><span>{$i18n.t('Git unavailable')}</span></Tooltip
|
|
>
|
|
<button
|
|
class="flex h-6 w-6 items-center justify-center rounded-md hover:bg-base-100/30 dark:hover:bg-base-800/20"
|
|
aria-label={$i18n.t('Retry Git detection')}
|
|
on:click={() => refresh(true)}><Icon name="refresh" size={12} /></button
|
|
>
|
|
</div>
|
|
{:else if standalone && status}
|
|
<div
|
|
class="flex h-full items-center justify-center p-3 text-center text-xs text-base-400 dark:text-base-500"
|
|
>
|
|
{$i18n.t('Not a Git repository')}
|
|
</div>
|
|
{/if}
|
|
|
|
<!-- Retired warning: keep its translation.
|
|
{$i18n.t('Discard unsaved working-tree changes to this file? This cannot be undone.')}
|
|
-->
|
|
<ConfirmDialog
|
|
bind:show={confirmDiscard}
|
|
title={$i18n.t('Discard changes')}
|
|
message={discardFiles.length > 1
|
|
? $i18n.t(
|
|
'Discard all staged and unstaged changes to {{COUNT}} files? Files not in the last commit will be deleted. This cannot be undone.',
|
|
{ COUNT: discardFiles.length }
|
|
)
|
|
: $i18n.t(
|
|
'Discard all staged and unstaged changes to this file? Files not in the last commit will be deleted. This cannot be undone.'
|
|
)}
|
|
on:confirm={() => {
|
|
if (discardFiles.length) void act('discard', { paths: paths(discardFiles) });
|
|
}}
|
|
/>
|
|
|
|
<ConfirmDialog
|
|
bind:show={showRename}
|
|
title={$i18n.t('Rename branch')}
|
|
input={true}
|
|
inputValue={actionBranch?.name ?? ''}
|
|
on:confirm={(event) => {
|
|
if (actionBranch)
|
|
void act('rename_branch', { branch: actionBranch.name, target: event.detail });
|
|
}}
|
|
/>
|
|
<ConfirmDialog
|
|
bind:show={showDeleteBranch}
|
|
title={$i18n.t('Delete branch')}
|
|
message={$i18n.t('Delete branch {{branch}}? Unmerged branches will be kept.', {
|
|
branch: actionBranch?.name ?? ''
|
|
})}
|
|
on:confirm={() => {
|
|
if (actionBranch) void act('delete_branch', { branch: actionBranch.name });
|
|
}}
|
|
/>
|
|
<ConfirmDialog
|
|
bind:show={showUncommit}
|
|
title={$i18n.t('Undo last commit')}
|
|
message={$i18n.t('Undo the last commit and keep its changes staged?')}
|
|
on:confirm={() => act('uncommit')}
|
|
/>
|
|
|
|
<style>
|
|
@media (prefers-reduced-motion: no-preference) {
|
|
.git-fetching {
|
|
animation: git-fetch 1.2s linear infinite;
|
|
}
|
|
.git-pulling,
|
|
.git-pushing {
|
|
animation: git-transfer 1s ease-out infinite;
|
|
--git-direction: 3px;
|
|
}
|
|
.git-pushing {
|
|
--git-direction: -3px;
|
|
}
|
|
}
|
|
@keyframes git-fetch {
|
|
from {
|
|
transform: rotate(0deg);
|
|
}
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
@keyframes git-transfer {
|
|
0%,
|
|
100% {
|
|
transform: translateY(0);
|
|
}
|
|
50% {
|
|
transform: translateY(var(--git-direction));
|
|
}
|
|
}
|
|
</style>
|