Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into base-branch-improve…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
estib-vega committed Sep 16, 2024
2 parents bb09576 + 5b34cc7 commit bd6393e
Show file tree
Hide file tree
Showing 50 changed files with 1,281 additions and 735 deletions.
442 changes: 236 additions & 206 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resolver = "2"
[workspace.dependencies]
bstr = "1.10.0"
# Add the `tracing` or `tracing-detail` features to see more of gitoxide in the logs. Useful to see which programs it invokes.
gix = { git = "https://github.com/Byron/gitoxide", rev = "0fe5133598c6f843fb3172a4e0c4f58932405647", default-features = false, features = [] }
gix = { git = "https://github.com/Byron/gitoxide", rev = "72daa46bad9d397ef2cc48a3cffda23f414ccd8a", default-features = false, features = [] }
git2 = { version = "0.18.3", features = [
"vendored-openssl",
"vendored-libgit2",
Expand All @@ -48,7 +48,6 @@ thiserror = "1.0.63"
tokio = { version = "1.40.0", default-features = false }
keyring = "2.3.3"
anyhow = "1.0.86"
fslock = "0.2.1"
parking_lot = "0.12.3"
futures = "0.3.30"
toml = "0.8.13"
Expand Down
8 changes: 7 additions & 1 deletion apps/desktop/src/lib/baseBranch/baseBranchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { showError } from '$lib/notifications/toasts';
import { plainToInstance } from 'class-transformer';
import { writable } from 'svelte/store';

export interface RemoteBranchInfo {
name: string;
}

export class BaseBranchService {
readonly base = writable<BaseBranch | null | undefined>(undefined, () => {
this.refresh();
Expand Down Expand Up @@ -86,7 +90,9 @@ export class BaseBranchService {
}
}

export async function getRemoteBranches(projectId: string | undefined) {
export async function getRemoteBranches(
projectId: string | undefined
): Promise<RemoteBranchInfo[]> {
if (!projectId) return [];
return await invoke<Array<string>>('git_remote_branches', { projectId }).then((branches) =>
branches
Expand Down
6 changes: 4 additions & 2 deletions apps/desktop/src/lib/branch/BranchCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
let laneWidth: number | undefined = $state();
let commitDialog = $state<CommitDialog>();
let scrollViewport: HTMLElement | undefined = $state();
let rsViewport: HTMLElement | undefined = $state();
Expand All @@ -75,9 +76,7 @@
});
async function generateBranchName() {
console.log('before');
if (!aiGenEnabled) return;
console.log('after');
const hunks = branch.files.flatMap((f) => f.hunks);
Expand Down Expand Up @@ -174,6 +173,8 @@
files={branch.files}
showCheckboxes={$commitBoxOpen}
allowMultiple
commitDialogExpanded={commitBoxOpen}
focusCommitDialog={() => commitDialog?.focus()}
/>
{#if branch.conflicted}
<div class="card-notifications">
Expand All @@ -192,6 +193,7 @@
</Dropzones>

<CommitDialog
bind:this={commitDialog}
projectId={project.id}
expanded={commitBoxOpen}
hasSectionsAfter={branch.commits.length > 0}
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/lib/branch/BranchLabel.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { autoSelectBranchNameFeature } from '$lib/config/uiFeatureFlags';
import { resizeObserver } from '$lib/utils/resizeObserver';
interface Props {
Expand Down Expand Up @@ -34,6 +35,9 @@
onclick={(e) => {
e.stopPropagation();
inputEl.focus();
if ($autoSelectBranchNameFeature) {
inputEl.select();
}
}}
onblur={() => {
if (name === '') name = initialName;
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/branch/BranchLane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
conflicted={selected.conflicted}
file={selected}
readonly={selected instanceof RemoteFile}
selectable={$commitBoxOpen}
selectable={$commitBoxOpen && commitId === undefined}
{commitId}
on:close={() => {
fileIdSelection.clear();
Expand Down
26 changes: 21 additions & 5 deletions apps/desktop/src/lib/commit/CommitCard.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import CommitContextMenu from './CommitContextMenu.svelte';
import CommitDragItem from './CommitDragItem.svelte';
import { Project } from '$lib/backend/projects';
import { BaseBranch } from '$lib/baseBranch/baseBranch';
Expand Down Expand Up @@ -51,6 +52,7 @@
const currentCommitMessage = persistedCommitMessage(project.id, branch?.id || '');
let draggableCommitElement: HTMLElement | null = null;
let contextMenu: CommitContextMenu;
let files: RemoteFile[] = [];
let showDetails = false;
Expand Down Expand Up @@ -153,11 +155,15 @@
</script>

<Modal bind:this={commitMessageModal} width="small" onSubmit={submitCommitMessageModal}>
<CommitMessageInput
bind:commitMessage={description}
bind:valid={commitMessageValid}
isExpanded={true}
/>
{#snippet children(_, close)}
<CommitMessageInput
focusOnMount
bind:commitMessage={description}
bind:valid={commitMessageValid}
isExpanded={true}
cancel={close}
/>
{/snippet}
{#snippet controls(close)}
<Button style="ghost" outline onclick={close}>Cancel</Button>
<Button style="neutral" type="submit" kind="solid" grow disabled={!commitMessageValid}>
Expand Down Expand Up @@ -189,6 +195,13 @@
{/snippet}
</Modal>

<CommitContextMenu
bind:this={contextMenu}
targetElement={draggableCommitElement}
{commit}
{commitUrl}
/>

<div
class="commit-row"
class:is-commit-open={showDetails}
Expand Down Expand Up @@ -222,6 +235,9 @@
on:keyup={onKeyup}
role="button"
tabindex="0"
on:contextmenu={(e) => {
contextMenu.open(e);
}}
on:dragenter={() => {
isDragTargeted = true;
}}
Expand Down
51 changes: 51 additions & 0 deletions apps/desktop/src/lib/commit/CommitContextMenu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script lang="ts">
import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte';
import ContextMenuItem from '$lib/components/contextmenu/ContextMenuItem.svelte';
import ContextMenuSection from '$lib/components/contextmenu/ContextMenuSection.svelte';
import { copyToClipboard } from '$lib/utils/clipboard';
import { openExternalUrl } from '$lib/utils/url';
import type { Commit, DetailedCommit } from '$lib/vbranches/types';
interface Props {
targetElement: HTMLElement | null;
commit: DetailedCommit | Commit;
commitUrl: string | undefined;
}
const { targetElement, commit, commitUrl }: Props = $props();
const target = $derived(targetElement ?? undefined);
let contextMenu = $state<ContextMenu>();
export function open(e: MouseEvent) {
e.preventDefault();
e.stopPropagation();
contextMenu?.open(e);
}
function copySha() {
copyToClipboard(commit.id);
contextMenu?.close();
}
function openInBrowser() {
if (commitUrl) openExternalUrl(commitUrl);
contextMenu?.close();
}
function copyCommitMessage() {
copyToClipboard(commit.description);
contextMenu?.close();
}
</script>

<ContextMenu bind:this={contextMenu} {target} openByMouse>
<ContextMenuSection>
<ContextMenuItem label="Copy SHA" on:click={copySha} />
{#if commitUrl}
<ContextMenuItem label="Open in browser" on:click={openInBrowser} />
{/if}
<ContextMenuItem label="Copy commit message" on:click={copyCommitMessage} />
</ContextMenuSection>
</ContextMenu>
23 changes: 13 additions & 10 deletions apps/desktop/src/lib/commit/CommitDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
const runCommitHooks = projectRunCommitHooks(projectId);
const commitMessage = persistedCommitMessage(projectId, $branch.id);
let commitMessageInput: CommitMessageInput;
let isCommitting = false;
let commitMessageValid = false;
let isInViewport = false;
Expand All @@ -40,6 +41,14 @@
isCommitting = false;
}
}
function close() {
$expanded = false;
}
export function focus() {
commitMessageInput.focus();
}
</script>

<div
Expand All @@ -62,24 +71,17 @@
}}
>
<CommitMessageInput
bind:this={commitMessageInput}
bind:commitMessage={$commitMessage}
bind:valid={commitMessageValid}
isExpanded={$expanded}
cancel={close}
{commit}
/>
<div class="actions" class:commit-box__actions-expanded={$expanded}>
{#if $expanded && !isCommitting}
<div class="cancel-btn-wrapper" transition:slideFade={{ duration: 200, axis: 'x' }}>
<Button
style="ghost"
outline
id="commit-to-branch"
onclick={() => {
$expanded = false;
}}
>
Cancel
</Button>
<Button style="ghost" outline id="commit-to-branch" onclick={close}>Cancel</Button>
</div>
{/if}
<Button
Expand All @@ -96,6 +98,7 @@
commit();
} else {
$expanded = true;
commitMessageInput.focus();
}
}}
>
Expand Down
9 changes: 3 additions & 6 deletions apps/desktop/src/lib/commit/CommitDragItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
const branch = maybeGetContextStore(VirtualBranch);
let actions = $state<CommitDragActions>();
$effect.pre(() => {
if (!$branch) return;
actions = commitDragActionsFactory.build($branch, commit);
});
const actions = $derived<CommitDragActions | undefined>(
$branch && commitDragActionsFactory.build($branch, commit)
);
</script>

<div class="dropzone-wrapper">
Expand Down
20 changes: 19 additions & 1 deletion apps/desktop/src/lib/commit/CommitMessageInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
export let isExpanded: boolean;
export let commitMessage: string;
export let focusOnMount: boolean = false;
export let valid: boolean = false;
export let commit: (() => void) | undefined = undefined;
export let cancel: () => void;
const user = getContextStore(User);
const selectedOwnership = getContextStore(SelectedOwnership);
Expand Down Expand Up @@ -61,7 +63,7 @@
}
function focusTextAreaOnMount(el: HTMLTextAreaElement) {
el.focus();
if (focusOnMount) el.focus();
}
function updateFieldsHeight() {
Expand Down Expand Up @@ -125,6 +127,12 @@
function handleDescriptionKeyDown(e: KeyboardEvent & { currentTarget: HTMLTextAreaElement }) {
const value = e.currentTarget.value;
if (e.key === KeyName.Escape) {
e.preventDefault();
cancel();
return;
}
if (e.key === KeyName.Delete && value.length === 0) {
e.preventDefault();
if (titleTextArea) {
Expand All @@ -144,6 +152,12 @@
}
function handleSummaryKeyDown(e: KeyboardEvent & { currentTarget: HTMLTextAreaElement }) {
if (e.key === KeyName.Escape) {
e.preventDefault();
cancel();
return;
}
if (commit && (e.ctrlKey || e.metaKey) && e.key === KeyName.Enter) commit();
if (e.key === KeyName.Enter) {
e.preventDefault();
Expand Down Expand Up @@ -171,6 +185,10 @@
descriptionTextArea?.focus();
}
}
export function focus() {
titleTextArea?.focus();
}
</script>

{#if isExpanded}
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/lib/components/ProjectSetup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ProjectSetupTarget from './ProjectSetupTarget.svelte';
import newProjectSvg from '$lib/assets/illustrations/new-project.svg?raw';
import { Project, ProjectService } from '$lib/backend/projects';
import { BaseBranchService } from '$lib/baseBranch/baseBranchService';
import { BaseBranchService, type RemoteBranchInfo } from '$lib/baseBranch/baseBranchService';
import DecorativeSplitView from '$lib/components/DecorativeSplitView.svelte';
import { platformName } from '$lib/platform/platform';
import KeysForm from '$lib/settings/KeysForm.svelte';
Expand All @@ -11,7 +11,7 @@
import Button from '@gitbutler/ui/Button.svelte';
import { goto } from '$app/navigation';
export let remoteBranches: { name: string }[];
export let remoteBranches: RemoteBranchInfo[];
const project = getContext(Project);
const projectService = getContext(ProjectService);
Expand Down
Loading

0 comments on commit bd6393e

Please # to comment.