diff --git a/app/src/lib/commit/CommitCard.svelte b/app/src/lib/commit/CommitCard.svelte index e54ceddab..6c19caf1c 100644 --- a/app/src/lib/commit/CommitCard.svelte +++ b/app/src/lib/commit/CommitCard.svelte @@ -20,7 +20,7 @@ import { listRemoteCommitFiles } from '$lib/vbranches/remoteCommits'; import { RemoteCommit, - Commit, + DetailedCommit, RemoteFile, VirtualBranch, type CommitStatus @@ -28,7 +28,7 @@ import { type Snippet } from 'svelte'; export let branch: VirtualBranch | undefined = undefined; - export let commit: Commit | RemoteCommit; + export let commit: DetailedCommit | RemoteCommit; export let commitUrl: string | undefined = undefined; export let isHeadCommit: boolean = false; export let isUnapplied = false; @@ -66,7 +66,7 @@ } } - function undoCommit(commit: Commit | RemoteCommit) { + function undoCommit(commit: DetailedCommit | RemoteCommit) { if (!branch || !$baseBranch) { console.error('Unable to undo commit'); return; @@ -74,7 +74,7 @@ branchController.undoCommit(branch.id, commit.id); } - let isUndoable = commit instanceof Commit; + let isUndoable = commit instanceof DetailedCommit; const hasCommitUrl = !commit.isLocal && commitUrl; @@ -192,7 +192,9 @@ dragDirection = isTop ? 'up' : 'down'; }} - use:draggableCommit={commit instanceof Commit && !isUnapplied && type !== 'integrated' + use:draggableCommit={commit instanceof DetailedCommit && + !isUnapplied && + type !== 'integrated' ? { label: commit.descriptionTitle, sha: commitShortSha, diff --git a/app/src/lib/commit/CommitDragItem.svelte b/app/src/lib/commit/CommitDragItem.svelte index ab33067ee..653b1e2ac 100644 --- a/app/src/lib/commit/CommitDragItem.svelte +++ b/app/src/lib/commit/CommitDragItem.svelte @@ -3,13 +3,13 @@ import CardOverlay from '$lib/dropzone/CardOverlay.svelte'; import Dropzone from '$lib/dropzone/Dropzone.svelte'; import { getContext, maybeGetContextStore } from '$lib/utils/context'; - import { RemoteCommit, VirtualBranch, Commit } from '$lib/vbranches/types'; + import { RemoteCommit, VirtualBranch, DetailedCommit } from '$lib/vbranches/types'; import type { Snippet } from 'svelte'; const commitDragActionsFactory = getContext(CommitDragActionsFactory); interface Props { - commit: Commit | RemoteCommit; + commit: DetailedCommit | RemoteCommit; children: Snippet; } diff --git a/app/src/lib/commits/dragActions.ts b/app/src/lib/commits/dragActions.ts index 5c7bc0b17..1adf5da2a 100644 --- a/app/src/lib/commits/dragActions.ts +++ b/app/src/lib/commits/dragActions.ts @@ -5,7 +5,7 @@ import { RemoteCommit, RemoteFile, type VirtualBranch, - type Commit + type DetailedCommit } from '$lib/vbranches/types'; import type { Project } from '$lib/backend/projects'; import type { BranchController } from '$lib/vbranches/branchController'; @@ -15,7 +15,7 @@ class CommitDragActions { private branchController: BranchController, private project: Project, private branch: VirtualBranch, - private commit: Commit | RemoteCommit + private commit: DetailedCommit | RemoteCommit ) {} acceptAmend(data: any) { @@ -102,7 +102,7 @@ export class CommitDragActionsFactory { private project: Project ) {} - build(branch: VirtualBranch, commit: Commit | RemoteCommit) { + build(branch: VirtualBranch, commit: DetailedCommit | RemoteCommit) { return new CommitDragActions(this.branchController, this.project, branch, commit); } } diff --git a/app/src/lib/dragging/draggables.ts b/app/src/lib/dragging/draggables.ts index db5ab8539..eebe2406f 100644 --- a/app/src/lib/dragging/draggables.ts +++ b/app/src/lib/dragging/draggables.ts @@ -1,4 +1,4 @@ -import type { AnyCommit, AnyFile, Commit, Hunk, RemoteCommit } from '../vbranches/types'; +import type { AnyCommit, AnyFile, DetailedCommit, Hunk, RemoteCommit } from '../vbranches/types'; export function nonDraggable() { return { @@ -31,7 +31,7 @@ export class DraggableFile { export class DraggableCommit { constructor( public readonly branchId: string, - public readonly commit: Commit, + public readonly commit: DetailedCommit, public readonly isHeadCommit: boolean ) {} } diff --git a/app/src/lib/dragging/reorderDropzoneManager.ts b/app/src/lib/dragging/reorderDropzoneManager.ts index 124979ae6..da218dfbd 100644 --- a/app/src/lib/dragging/reorderDropzoneManager.ts +++ b/app/src/lib/dragging/reorderDropzoneManager.ts @@ -1,6 +1,6 @@ import { DraggableCommit } from '$lib/dragging/draggables'; import type { BranchController } from '$lib/vbranches/branchController'; -import type { VirtualBranch, Commit } from '$lib/vbranches/types'; +import type { VirtualBranch, DetailedCommit } from '$lib/vbranches/types'; // Exported for type access only export class ReorderDropzone { @@ -33,7 +33,7 @@ export class ReorderDropzoneManager { constructor( private branchController: BranchController, private branch: VirtualBranch, - commits: Commit[] + commits: DetailedCommit[] ) { this.indexer = new Indexer(commits); } @@ -54,7 +54,7 @@ export class ReorderDropzoneManager { export class ReorderDropzoneManagerFactory { constructor(private branchController: BranchController) {} - build(branch: VirtualBranch, commits: Commit[]) { + build(branch: VirtualBranch, commits: DetailedCommit[]) { return new ReorderDropzoneManager(this.branchController, branch, commits); } } @@ -64,7 +64,7 @@ class Indexer { private dropzoneIndexes = new Map(); private commitIndexes = new Map(); - constructor(commits: Commit[]) { + constructor(commits: DetailedCommit[]) { this.dropzoneIndexes.set('top', 0); commits.forEach((commit, index) => { diff --git a/app/src/lib/vbranches/contexts.ts b/app/src/lib/vbranches/contexts.ts index 2523cb5de..aea166c5a 100644 --- a/app/src/lib/vbranches/contexts.ts +++ b/app/src/lib/vbranches/contexts.ts @@ -1,14 +1,14 @@ import { buildContextStore } from '$lib/utils/context'; -import type { AnyCommit, Commit, RemoteCommit } from './types'; +import type { AnyCommit, DetailedCommit, RemoteCommit } from './types'; // When we can't use type for context objects we build typed getter/setter pairs // to avoid using symbols explicitly. export const [getLocalCommits, createLocalCommitsContextStore] = - buildContextStore('localCommits'); + buildContextStore('localCommits'); export const [getLocalAndRemoteCommits, createLocalAndRemoteCommitsContextStore] = - buildContextStore('remoteCommits'); + buildContextStore('remoteCommits'); export const [getIntegratedCommits, createIntegratedCommitsContextStore] = - buildContextStore('integratedCommits'); + buildContextStore('integratedCommits'); export const [getRemoteCommits, createRemoteCommitsContextStore] = buildContextStore('remoteCommits'); export const [getCommitStore, createCommitStore] = buildContextStore( diff --git a/app/src/lib/vbranches/tooltip.ts b/app/src/lib/vbranches/tooltip.ts index 1ae4ef90f..7ed676570 100644 --- a/app/src/lib/vbranches/tooltip.ts +++ b/app/src/lib/vbranches/tooltip.ts @@ -1,7 +1,10 @@ -import { HunkLock, type Commit } from './types'; +import { HunkLock, type DetailedCommit } from './types'; import { unique } from '$lib/utils/filters'; -export function getLockText(hunkLocks: HunkLock | HunkLock[] | string, commits: Commit[]): string { +export function getLockText( + hunkLocks: HunkLock | HunkLock[] | string, + commits: DetailedCommit[] +): string { if (!hunkLocks || commits === undefined) return 'Depends on a committed change'; const locks = hunkLocks instanceof HunkLock ? [hunkLocks] : (hunkLocks as HunkLock[]); diff --git a/app/src/lib/vbranches/types.ts b/app/src/lib/vbranches/types.ts index 7132ce37c..a98a9b879 100644 --- a/app/src/lib/vbranches/types.ts +++ b/app/src/lib/vbranches/types.ts @@ -103,8 +103,8 @@ export class VirtualBranch { notes!: string; @Type(() => LocalFile) files!: LocalFile[]; - @Type(() => Commit) - commits!: Commit[]; + @Type(() => DetailedCommit) + commits!: DetailedCommit[]; requiresForce!: boolean; description!: string; head!: string; @@ -165,7 +165,7 @@ export type ComponentColor = | 'purple'; export type CommitStatus = 'local' | 'localAndRemote' | 'integrated' | 'remote'; -export class Commit { +export class DetailedCommit { id!: string; author!: Author; description!: string; @@ -181,8 +181,8 @@ export class Commit { isSigned!: boolean; relatedTo?: RemoteCommit; - prev?: Commit; - next?: Commit; + prev?: DetailedCommit; + next?: DetailedCommit; get isLocal() { return !this.isRemote && !this.isIntegrated; @@ -203,7 +203,7 @@ export class Commit { return splitMessage(this.description).description || undefined; } - isParentOf(possibleChild: Commit) { + isParentOf(possibleChild: DetailedCommit) { return possibleChild.parentIds.includes(this.id); } @@ -212,8 +212,8 @@ export class Commit { } } -export function isLocalCommit(obj: any): obj is Commit { - return obj instanceof Commit; +export function isLocalCommit(obj: any): obj is DetailedCommit { + return obj instanceof DetailedCommit; } export class RemoteCommit { @@ -228,7 +228,7 @@ export class RemoteCommit { prev?: RemoteCommit; next?: RemoteCommit; - relatedTo?: Commit; + relatedTo?: DetailedCommit; get isLocal() { return false; @@ -255,7 +255,7 @@ export function isRemoteCommit(obj: any): obj is RemoteCommit { return obj instanceof RemoteCommit; } -export type AnyCommit = Commit | RemoteCommit; +export type AnyCommit = DetailedCommit | RemoteCommit; export function commitCompare(left: AnyCommit, right: AnyCommit): boolean { if (left.id === right.id) return true; diff --git a/app/src/lib/vbranches/virtualBranch.ts b/app/src/lib/vbranches/virtualBranch.ts index c86527559..d3790b772 100644 --- a/app/src/lib/vbranches/virtualBranch.ts +++ b/app/src/lib/vbranches/virtualBranch.ts @@ -1,4 +1,10 @@ -import { VirtualBranch, Commit, RemoteCommit, VirtualBranches, commitCompare } from './types'; +import { + VirtualBranch, + DetailedCommit, + RemoteCommit, + VirtualBranches, + commitCompare +} from './types'; import { invoke, listen } from '$lib/backend/ipc'; import { RemoteBranchService } from '$lib/stores/remoteBranches'; import { plainToInstance } from 'class-transformer'; @@ -94,14 +100,14 @@ export class VirtualBranchService { } } -function linkAsParentChildren(commits: Commit[] | RemoteCommit[]) { +function linkAsParentChildren(commits: DetailedCommit[] | RemoteCommit[]) { for (let j = 0; j < commits.length; j++) { const commit = commits[j]; if (j === 0) { commit.next = undefined; } else { const child = commits[j - 1]; - if (child instanceof Commit) commit.next = child; + if (child instanceof DetailedCommit) commit.next = child; if (child instanceof RemoteCommit) commit.next = child; } if (j !== commits.length - 1) {