From c813dddcd96918b22a16bef1e2f0ea14c8ea72f0 Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Thu, 1 Feb 2024 10:34:16 +0100 Subject: [PATCH] Rename File -> LocalFile --- gitbutler-ui/src/lib/components/BaseBranch.svelte | 4 ++-- gitbutler-ui/src/lib/components/BranchCard.svelte | 4 ++-- gitbutler-ui/src/lib/components/BranchCommits.svelte | 4 ++-- gitbutler-ui/src/lib/components/BranchFiles.svelte | 4 ++-- .../src/lib/components/BranchFilesHeader.svelte | 6 +++--- .../src/lib/components/BranchFilesList.svelte | 6 +++--- gitbutler-ui/src/lib/components/BranchLane.svelte | 6 +++--- gitbutler-ui/src/lib/components/CommitCard.svelte | 4 ++-- gitbutler-ui/src/lib/components/CommitDialog.svelte | 4 ++-- gitbutler-ui/src/lib/components/CommitList.svelte | 10 ++++++++-- .../src/lib/components/CommitListItem.svelte | 4 ++-- gitbutler-ui/src/lib/components/FileCard.svelte | 6 +++--- .../src/lib/components/FileCardHeader.svelte | 4 ++-- gitbutler-ui/src/lib/components/FileListItem.svelte | 6 +++--- .../src/lib/components/FileStatusIcons.svelte | 4 ++-- gitbutler-ui/src/lib/components/FileTree.svelte | 4 ++-- .../src/lib/components/RemoteBranchPreview.svelte | 4 ++-- gitbutler-ui/src/lib/components/TreeListFile.svelte | 6 +++--- gitbutler-ui/src/lib/dragging/draggables.ts | 10 +++++----- gitbutler-ui/src/lib/utils/fileSections.test.ts | 12 ++++++------ gitbutler-ui/src/lib/utils/fileSections.ts | 6 +++--- gitbutler-ui/src/lib/utils/fileStatus.ts | 4 ++-- gitbutler-ui/src/lib/utils/metrics.ts | 4 ++-- gitbutler-ui/src/lib/vbranches/filetree.test.ts | 8 ++++---- gitbutler-ui/src/lib/vbranches/filetree.ts | 12 ++++++------ gitbutler-ui/src/lib/vbranches/ownership.ts | 4 ++-- gitbutler-ui/src/lib/vbranches/types.ts | 10 +++++----- 27 files changed, 83 insertions(+), 77 deletions(-) diff --git a/gitbutler-ui/src/lib/components/BaseBranch.svelte b/gitbutler-ui/src/lib/components/BaseBranch.svelte index ce9ba2b9e..3e37f62b9 100644 --- a/gitbutler-ui/src/lib/components/BaseBranch.svelte +++ b/gitbutler-ui/src/lib/components/BaseBranch.svelte @@ -6,7 +6,7 @@ import { tooltip } from '$lib/utils/tooltip'; import { writable } from 'svelte/store'; import type { BranchController } from '$lib/vbranches/branchController'; - import type { BaseBranch, File, RemoteFile } from '$lib/vbranches/types'; + import type { BaseBranch, LocalFile, RemoteFile } from '$lib/vbranches/types'; export let base: BaseBranch; export let projectId: string; @@ -16,7 +16,7 @@ const mergeUpstreamWarningDismissed = projectMergeUpstreamWarningDismissed( branchController.projectId ); - const selectedFiles = writable<(File | RemoteFile)[]>([]); + const selectedFiles = writable<(LocalFile | RemoteFile)[]>([]); let updateTargetModal: Modal; let mergeUpstreamWarningDismissedCheckbox = false; diff --git a/gitbutler-ui/src/lib/components/BranchCard.svelte b/gitbutler-ui/src/lib/components/BranchCard.svelte index aefb07265..8e8d7dc6a 100644 --- a/gitbutler-ui/src/lib/components/BranchCard.svelte +++ b/gitbutler-ui/src/lib/components/BranchCard.svelte @@ -28,7 +28,7 @@ import type { BranchService } from '$lib/branches/service'; import type { GitHubService } from '$lib/github/service'; import type { BranchController } from '$lib/vbranches/branchController'; - import type { BaseBranch, Branch, File, RemoteFile } from '$lib/vbranches/types'; + import type { BaseBranch, Branch, LocalFile, RemoteFile } from '$lib/vbranches/types'; export let branch: Branch; export let isUnapplied = false; @@ -39,7 +39,7 @@ export let branchController: BranchController; export let branchCount = 1; export let user: User | undefined; - export let selectedFiles: Writable; + export let selectedFiles: Writable; export let githubService: GitHubService; export let selectedOwnership: Writable; export let commitBoxOpen: Writable; diff --git a/gitbutler-ui/src/lib/components/BranchCommits.svelte b/gitbutler-ui/src/lib/components/BranchCommits.svelte index aba32cfc1..05104eb03 100644 --- a/gitbutler-ui/src/lib/components/BranchCommits.svelte +++ b/gitbutler-ui/src/lib/components/BranchCommits.svelte @@ -4,7 +4,7 @@ import type { BranchService } from '$lib/branches/service'; import type { GitHubService } from '$lib/github/service'; import type { BranchController } from '$lib/vbranches/branchController'; - import type { BaseBranch, Branch, File, RemoteFile } from '$lib/vbranches/types'; + import type { BaseBranch, Branch, LocalFile, RemoteFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; export let project: Project; @@ -13,7 +13,7 @@ export let githubService: GitHubService; export let branchController: BranchController; export let branchService: BranchService; - export let selectedFiles: Writable<(File | RemoteFile)[]>; + export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>; export let isUnapplied: boolean; export let branchCount: number; diff --git a/gitbutler-ui/src/lib/components/BranchFiles.svelte b/gitbutler-ui/src/lib/components/BranchFiles.svelte index f662b05be..6df562528 100644 --- a/gitbutler-ui/src/lib/components/BranchFiles.svelte +++ b/gitbutler-ui/src/lib/components/BranchFiles.svelte @@ -4,13 +4,13 @@ import FileTree from './FileTree.svelte'; import { filesToFileTree } from '$lib/vbranches/filetree'; import type { Ownership } from '$lib/vbranches/ownership'; - import type { Branch, File } from '$lib/vbranches/types'; + import type { Branch, LocalFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; export let branch: Branch; export let isUnapplied: boolean; export let selectedOwnership: Writable; - export let selectedFiles: Writable; + export let selectedFiles: Writable; export let showCheckboxes = false; let selectedListMode: string; diff --git a/gitbutler-ui/src/lib/components/BranchFilesHeader.svelte b/gitbutler-ui/src/lib/components/BranchFilesHeader.svelte index 70052f7c2..d2f9efd82 100644 --- a/gitbutler-ui/src/lib/components/BranchFilesHeader.svelte +++ b/gitbutler-ui/src/lib/components/BranchFilesHeader.svelte @@ -4,16 +4,16 @@ import Segment from '$lib/components/SegmentControl/Segment.svelte'; import SegmentedControl from '$lib/components/SegmentControl/SegmentedControl.svelte'; import type { Ownership } from '$lib/vbranches/ownership'; - import type { File, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; - export let files: (File | RemoteFile)[]; + export let files: (LocalFile | RemoteFile)[]; export let selectedOwnership: Writable; export let showCheckboxes = false; export let selectedListMode: string; - function selectAll(selectedOwnership: Writable, files: (File | RemoteFile)[]) { + function selectAll(selectedOwnership: Writable, files: (LocalFile | RemoteFile)[]) { files.forEach((f) => selectedOwnership.update((ownership) => ownership.addHunk(f.id, ...f.hunks.map((h) => h.id))) ); diff --git a/gitbutler-ui/src/lib/components/BranchFilesList.svelte b/gitbutler-ui/src/lib/components/BranchFilesList.svelte index 4c16e99fe..13c2ba003 100644 --- a/gitbutler-ui/src/lib/components/BranchFilesList.svelte +++ b/gitbutler-ui/src/lib/components/BranchFilesList.svelte @@ -2,15 +2,15 @@ import FileListItem from './FileListItem.svelte'; import { sortLikeFileTree } from '$lib/vbranches/filetree'; import type { Ownership } from '$lib/vbranches/ownership'; - import type { File, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; export let branchId: string; - export let files: (File | RemoteFile)[]; + export let files: (LocalFile | RemoteFile)[]; export let selectedOwnership: Writable; export let isUnapplied = false; export let showCheckboxes = false; - export let selectedFiles: Writable<(File | RemoteFile)[]>; + export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>; export let allowMultiple = false; $: console.log(selectedFiles); diff --git a/gitbutler-ui/src/lib/components/BranchLane.svelte b/gitbutler-ui/src/lib/components/BranchLane.svelte index c77aaec56..6db43178e 100644 --- a/gitbutler-ui/src/lib/components/BranchLane.svelte +++ b/gitbutler-ui/src/lib/components/BranchLane.svelte @@ -2,7 +2,7 @@ import BranchCard from './BranchCard.svelte'; import FileCard from './FileCard.svelte'; import { Ownership } from '$lib/vbranches/ownership'; - import { RemoteFile, type BaseBranch, type Branch, type File } from '$lib/vbranches/types'; + import { RemoteFile, type BaseBranch, type Branch, type LocalFile } from '$lib/vbranches/types'; import { writable, type Writable } from 'svelte/store'; import type { User, getCloudApiClient } from '$lib/backend/cloud'; import type { Project } from '$lib/backend/projects'; @@ -25,11 +25,11 @@ $: selectedOwnership = writable(Ownership.fromBranch(branch)); $: selected = setSelected($selectedFiles, branch); - const selectedFiles = writable([]); + const selectedFiles = writable([]); let commitBoxOpen: Writable; - function setSelected(files: (File | RemoteFile)[], branch: Branch) { + function setSelected(files: (LocalFile | RemoteFile)[], branch: Branch) { if (files.length == 0) return undefined; if (files.length == 1 && files[0] instanceof RemoteFile) return files[0]; diff --git a/gitbutler-ui/src/lib/components/CommitCard.svelte b/gitbutler-ui/src/lib/components/CommitCard.svelte index aab1ff799..90f67e011 100644 --- a/gitbutler-ui/src/lib/components/CommitCard.svelte +++ b/gitbutler-ui/src/lib/components/CommitCard.svelte @@ -13,7 +13,7 @@ import { filesToFileTree } from '$lib/vbranches/filetree'; import { Ownership } from '$lib/vbranches/ownership'; import { listRemoteCommitFiles } from '$lib/vbranches/remoteCommits'; - import { File, RemoteCommit, Commit, RemoteFile } from '$lib/vbranches/types'; + import { LocalFile, RemoteCommit, Commit, RemoteFile } from '$lib/vbranches/types'; import { open } from '@tauri-apps/api/shell'; import { writable, type Writable } from 'svelte/store'; import type { ContentSection, HunkSection } from '$lib/utils/fileSections'; @@ -27,7 +27,7 @@ export let isUnapplied = false; export let branchController: BranchController; export let projectPath: string; - export let selectedFiles: Writable<(File | RemoteFile)[]>; + export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>; const selectedOwnership = writable(Ownership.default()); diff --git a/gitbutler-ui/src/lib/components/CommitDialog.svelte b/gitbutler-ui/src/lib/components/CommitDialog.svelte index 98f182bdf..f85044005 100644 --- a/gitbutler-ui/src/lib/components/CommitDialog.svelte +++ b/gitbutler-ui/src/lib/components/CommitDialog.svelte @@ -21,7 +21,7 @@ import type { User, getCloudApiClient } from '$lib/backend/cloud'; import type { BranchController } from '$lib/vbranches/branchController'; import type { Ownership } from '$lib/vbranches/ownership'; - import type { Branch, File } from '$lib/vbranches/types'; + import type { Branch, LocalFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; const dispatch = createEventDispatcher<{ @@ -74,7 +74,7 @@ $: checkCommitsAnnotated(); let isGeneratingCommigMessage = false; - async function generateCommitMessage(files: File[]) { + async function generateCommitMessage(files: LocalFile[]) { const diff = files .map((f) => f.hunks.filter((h) => $selectedOwnership.containsHunk(f.id, h.id))) .flat() diff --git a/gitbutler-ui/src/lib/components/CommitList.svelte b/gitbutler-ui/src/lib/components/CommitList.svelte index 8a5474baa..218145409 100644 --- a/gitbutler-ui/src/lib/components/CommitList.svelte +++ b/gitbutler-ui/src/lib/components/CommitList.svelte @@ -6,7 +6,13 @@ import type { BranchService } from '$lib/branches/service'; import type { GitHubService } from '$lib/github/service'; import type { BranchController } from '$lib/vbranches/branchController'; - import type { BaseBranch, Branch, CommitStatus, File, RemoteFile } from '$lib/vbranches/types'; + import type { + BaseBranch, + Branch, + CommitStatus, + LocalFile, + RemoteFile + } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; export let branch: Branch; @@ -16,7 +22,7 @@ export let type: CommitStatus; export let githubService: GitHubService; export let branchService: BranchService; - export let selectedFiles: Writable<(File | RemoteFile)[]>; + export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>; export let isUnapplied: boolean; export let branchCount: number = 0; diff --git a/gitbutler-ui/src/lib/components/CommitListItem.svelte b/gitbutler-ui/src/lib/components/CommitListItem.svelte index adede0c43..68c9c275d 100644 --- a/gitbutler-ui/src/lib/components/CommitListItem.svelte +++ b/gitbutler-ui/src/lib/components/CommitListItem.svelte @@ -16,7 +16,7 @@ type BaseBranch, type Branch, type Commit, - type File, + type LocalFile, RemoteFile } from '$lib/vbranches/types'; import { get, type Writable } from 'svelte/store'; @@ -31,7 +31,7 @@ export let isChained: boolean; export let isUnapplied = false; export let branchController: BranchController; - export let selectedFiles: Writable<(File | RemoteFile)[]>; + export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>; function acceptAmend(commit: Commit | RemoteCommit) { if (commit instanceof RemoteCommit) { diff --git a/gitbutler-ui/src/lib/components/FileCard.svelte b/gitbutler-ui/src/lib/components/FileCard.svelte index e2eb2350c..a5d629bc2 100644 --- a/gitbutler-ui/src/lib/components/FileCard.svelte +++ b/gitbutler-ui/src/lib/components/FileCard.svelte @@ -12,12 +12,12 @@ import { slide } from 'svelte/transition'; import type { BranchController } from '$lib/vbranches/branchController'; import type { Ownership } from '$lib/vbranches/ownership'; - import type { File, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; export let projectId: string; export let branchId: string; - export let file: File | RemoteFile; + export let file: LocalFile | RemoteFile; export let conflicted: boolean; export let projectPath: string | undefined; export let branchController: BranchController; @@ -35,7 +35,7 @@ let sections: (HunkSection | ContentSection)[] = []; - function parseFile(file: File | RemoteFile) { + function parseFile(file: LocalFile | RemoteFile) { // When we toggle expansion status on sections we need to assign // `sections = sections` to redraw, and why we do not use a reactive // variable. diff --git a/gitbutler-ui/src/lib/components/FileCardHeader.svelte b/gitbutler-ui/src/lib/components/FileCardHeader.svelte index da23ee504..2458af560 100644 --- a/gitbutler-ui/src/lib/components/FileCardHeader.svelte +++ b/gitbutler-ui/src/lib/components/FileCardHeader.svelte @@ -6,9 +6,9 @@ import { computeFileStatus } from '$lib/utils/fileStatus'; import { computeAddedRemovedByFiles } from '$lib/utils/metrics'; import { createEventDispatcher } from 'svelte'; - import type { File, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; - export let file: File | RemoteFile; + export let file: LocalFile | RemoteFile; export let isFileLocked: boolean; const dispatch = createEventDispatcher<{ close: void }>(); diff --git a/gitbutler-ui/src/lib/components/FileListItem.svelte b/gitbutler-ui/src/lib/components/FileListItem.svelte index 3fedca763..90d7e854f 100644 --- a/gitbutler-ui/src/lib/components/FileListItem.svelte +++ b/gitbutler-ui/src/lib/components/FileListItem.svelte @@ -5,16 +5,16 @@ import { draggableFile } from '$lib/dragging/draggables'; import { getVSIFileIcon } from '$lib/ext-icons'; import type { Ownership } from '$lib/vbranches/ownership'; - import type { File, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; export let branchId: string; - export let file: File | RemoteFile; + export let file: LocalFile | RemoteFile; export let isUnapplied: boolean; export let selected: boolean; export let showCheckbox: boolean = false; export let selectedOwnership: Writable; - export let selectedFiles: Writable<(File | RemoteFile)[]>; + export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>; let checked = false; let indeterminate = false; diff --git a/gitbutler-ui/src/lib/components/FileStatusIcons.svelte b/gitbutler-ui/src/lib/components/FileStatusIcons.svelte index 701f5809c..fbeadcce0 100644 --- a/gitbutler-ui/src/lib/components/FileStatusIcons.svelte +++ b/gitbutler-ui/src/lib/components/FileStatusIcons.svelte @@ -2,9 +2,9 @@ import FileStatusCircle from './FileStatusCircle.svelte'; import Icon from '$lib/components/Icon.svelte'; import { computeFileStatus } from '$lib/utils/fileStatus'; - import type { File, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; - export let file: File | RemoteFile; + export let file: LocalFile | RemoteFile; $: isLocked = file.hunks.some((h) => h.locked); diff --git a/gitbutler-ui/src/lib/components/FileTree.svelte b/gitbutler-ui/src/lib/components/FileTree.svelte index 570fa3488..0b3918e9b 100644 --- a/gitbutler-ui/src/lib/components/FileTree.svelte +++ b/gitbutler-ui/src/lib/components/FileTree.svelte @@ -7,7 +7,7 @@ import TreeListFolder from './TreeListFolder.svelte'; import type { TreeNode } from '$lib/vbranches/filetree'; import type { Ownership } from '$lib/vbranches/ownership'; - import type { File, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; export let expanded = true; @@ -15,7 +15,7 @@ export let isRoot = false; export let showCheckboxes = false; export let selectedOwnership: Writable; - export let selectedFiles: Writable<(File | RemoteFile)[]>; + export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>; export let branchId: string; export let isUnapplied: boolean; export let allowMultiple = false; diff --git a/gitbutler-ui/src/lib/components/RemoteBranchPreview.svelte b/gitbutler-ui/src/lib/components/RemoteBranchPreview.svelte index 71e41fec0..8cba5ad27 100644 --- a/gitbutler-ui/src/lib/components/RemoteBranchPreview.svelte +++ b/gitbutler-ui/src/lib/components/RemoteBranchPreview.svelte @@ -2,7 +2,7 @@ import Button from '$lib/components/Button.svelte'; import CommitCard from '$lib/components/CommitCard.svelte'; import type { BranchController } from '$lib/vbranches/branchController'; - import type { File, RemoteBranch, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteBranch, RemoteFile } from '$lib/vbranches/types'; import { writable } from 'svelte/store'; export let branch: RemoteBranch | undefined; @@ -10,7 +10,7 @@ export let projectPath: string; export let branchController: BranchController; - const selectedFiles = writable<(File | RemoteFile)[]>([]); + const selectedFiles = writable<(LocalFile | RemoteFile)[]>([]); {#if branch != undefined} diff --git a/gitbutler-ui/src/lib/components/TreeListFile.svelte b/gitbutler-ui/src/lib/components/TreeListFile.svelte index 1c8bb7c9f..65d4f120c 100644 --- a/gitbutler-ui/src/lib/components/TreeListFile.svelte +++ b/gitbutler-ui/src/lib/components/TreeListFile.svelte @@ -5,16 +5,16 @@ import { draggableFile } from '$lib/dragging/draggables'; import { getVSIFileIcon } from '$lib/ext-icons'; import type { Ownership } from '$lib/vbranches/ownership'; - import type { File, RemoteFile } from '$lib/vbranches/types'; + import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; import type { Writable } from 'svelte/store'; export let branchId: string; - export let file: File | RemoteFile; + export let file: LocalFile | RemoteFile; export let selected: boolean; export let isUnapplied: boolean; export let showCheckbox: boolean = false; export let selectedOwnership: Writable; - export let selectedFiles: Writable<(File | RemoteFile)[]>; + export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>; let checked = false; let indeterminate = false; diff --git a/gitbutler-ui/src/lib/dragging/draggables.ts b/gitbutler-ui/src/lib/dragging/draggables.ts index b938eff04..4d8a37728 100644 --- a/gitbutler-ui/src/lib/dragging/draggables.ts +++ b/gitbutler-ui/src/lib/dragging/draggables.ts @@ -1,4 +1,4 @@ -import type { Commit, File, Hunk, RemoteCommit, RemoteFile } from '../vbranches/types'; +import type { Commit, LocalFile, Hunk, RemoteCommit, RemoteFile } from '../vbranches/types'; import type { Writable } from 'svelte/store'; export function nonDraggable() { @@ -23,14 +23,14 @@ export function isDraggableHunk(obj: any): obj is DraggableHunk { export type DraggableFile = { branchId: string; - files: Writable<(File | RemoteFile)[]>; - current: File; + files: Writable<(LocalFile | RemoteFile)[]>; + current: LocalFile; }; export function draggableFile( branchId: string, - current: File | RemoteFile, - files: Writable<(File | RemoteFile)[]> + current: LocalFile | RemoteFile, + files: Writable<(LocalFile | RemoteFile)[]> ) { return { data: { branchId, current, files } }; } diff --git a/gitbutler-ui/src/lib/utils/fileSections.test.ts b/gitbutler-ui/src/lib/utils/fileSections.test.ts index b3892f7de..67cca0f24 100644 --- a/gitbutler-ui/src/lib/utils/fileSections.test.ts +++ b/gitbutler-ui/src/lib/utils/fileSections.test.ts @@ -1,5 +1,5 @@ import { parseHunkSection, parseFileSections, SectionType } from '$lib/utils/fileSections'; -import { File, Hunk } from '$lib/vbranches/types'; +import { LocalFile, Hunk } from '$lib/vbranches/types'; import { plainToInstance } from 'class-transformer'; import { expect, test } from 'vitest'; import type { ContentSection, HunkSection } from '$lib/utils/fileSections'; @@ -417,7 +417,7 @@ test('parses file with one hunk and balanced add-remove', () => { filePath: 'foo.py', locked: false }); - const file = plainToInstance(File, { + const file = plainToInstance(LocalFile, { id: '1', path: 'foo.py', hunks: [hunk], @@ -476,7 +476,7 @@ test('parses file with one hunk with more added than removed', () => { filePath: 'foo.py', locked: false }); - const file = plainToInstance(File, { + const file = plainToInstance(LocalFile, { id: '1', path: 'foo.py', hunks: [hunk], @@ -538,7 +538,7 @@ test('parses file with two hunks ordered by position in file', () => { filePath: 'foo.py', locked: false }); - const file = plainToInstance(File, { + const file = plainToInstance(LocalFile, { id: '1', path: 'foo.py', hunks: [bottomHunk, topHunk], @@ -611,7 +611,7 @@ test('parses whole file deleted', () => { filePath: 'foo.py', locked: false }); - const file = plainToInstance(File, { + const file = plainToInstance(LocalFile, { id: '1', path: 'foo.py', hunks: [deleteHunk], @@ -638,7 +638,7 @@ test('parses new file created', () => { filePath: 'foo.py', locked: false }); - const file = plainToInstance(File, { + const file = plainToInstance(LocalFile, { id: '1', path: 'foo.py', hunks: [newFileHunk], diff --git a/gitbutler-ui/src/lib/utils/fileSections.ts b/gitbutler-ui/src/lib/utils/fileSections.ts index 8d7270f6d..e68838bb1 100644 --- a/gitbutler-ui/src/lib/utils/fileSections.ts +++ b/gitbutler-ui/src/lib/utils/fileSections.ts @@ -1,4 +1,4 @@ -import { File } from '$lib/vbranches/types'; +import { LocalFile } from '$lib/vbranches/types'; import { plainToInstance } from 'class-transformer'; import type { Hunk, RemoteFile, RemoteHunk } from '$lib/vbranches/types'; @@ -146,13 +146,13 @@ export function parseHunkSection(hunk: Hunk | RemoteHunk): HunkSection { return hunkSection; } -export function parseFileSections(file: File | RemoteFile): (ContentSection | HunkSection)[] { +export function parseFileSections(file: LocalFile | RemoteFile): (ContentSection | HunkSection)[] { const hunkSections = file.hunks .map(parseHunkSection) .filter((hunkSection) => hunkSection !== undefined) .sort((a, b) => a.header.beforeStart - b.header.beforeStart); - const content = file instanceof File ? file.content : undefined; + const content = file instanceof LocalFile ? file.content : undefined; if (!content) return hunkSections; diff --git a/gitbutler-ui/src/lib/utils/fileStatus.ts b/gitbutler-ui/src/lib/utils/fileStatus.ts index 2769669a4..8df558812 100644 --- a/gitbutler-ui/src/lib/utils/fileStatus.ts +++ b/gitbutler-ui/src/lib/utils/fileStatus.ts @@ -1,8 +1,8 @@ -import { RemoteFile, type File } from '$lib/vbranches/types'; +import { RemoteFile, type LocalFile } from '$lib/vbranches/types'; export type FileStatus = 'A' | 'M' | 'D'; -export function computeFileStatus(file: File | RemoteFile): FileStatus { +export function computeFileStatus(file: LocalFile | RemoteFile): FileStatus { if (file instanceof RemoteFile) { // TODO: How do we compute this for remote files? return 'M'; diff --git a/gitbutler-ui/src/lib/utils/metrics.ts b/gitbutler-ui/src/lib/utils/metrics.ts index b8c88f2a8..71cdc1b13 100644 --- a/gitbutler-ui/src/lib/utils/metrics.ts +++ b/gitbutler-ui/src/lib/utils/metrics.ts @@ -1,7 +1,7 @@ import { HunkSection, type ContentSection } from './fileSections'; -import type { File, RemoteFile } from '$lib/vbranches/types'; +import type { LocalFile, RemoteFile } from '$lib/vbranches/types'; -export function computeAddedRemovedByFiles(...files: (File | RemoteFile)[]) { +export function computeAddedRemovedByFiles(...files: (LocalFile | RemoteFile)[]) { return files .flatMap((f) => f.hunks) .map((h) => h.diff.split('\n')) diff --git a/gitbutler-ui/src/lib/vbranches/filetree.test.ts b/gitbutler-ui/src/lib/vbranches/filetree.test.ts index aa4ca3ea3..831bf8224 100644 --- a/gitbutler-ui/src/lib/vbranches/filetree.test.ts +++ b/gitbutler-ui/src/lib/vbranches/filetree.test.ts @@ -1,11 +1,11 @@ import { filesToFileTree } from './filetree'; -import { File } from '$lib/vbranches/types'; +import { LocalFile } from '$lib/vbranches/types'; import { plainToInstance } from 'class-transformer'; import { expect, test } from 'vitest'; test('creates a file tree', () => { const files = [ - plainToInstance(File, { + plainToInstance(LocalFile, { id: '1234', path: 'test/foo.py', hunks: [], @@ -15,7 +15,7 @@ test('creates a file tree', () => { content: undefined, binary: false }), - plainToInstance(File, { + plainToInstance(LocalFile, { id: '1234', path: 'test/bar.rs', hunks: [], @@ -25,7 +25,7 @@ test('creates a file tree', () => { content: undefined, binary: false }), - plainToInstance(File, { + plainToInstance(LocalFile, { id: '1234', path: 'src/hello/world.txt', hunks: [], diff --git a/gitbutler-ui/src/lib/vbranches/filetree.ts b/gitbutler-ui/src/lib/vbranches/filetree.ts index 4990a2978..1059ce7a1 100644 --- a/gitbutler-ui/src/lib/vbranches/filetree.ts +++ b/gitbutler-ui/src/lib/vbranches/filetree.ts @@ -4,11 +4,11 @@ * This module provides support for tranforming a list of files into a * hirerarchical structure for easy rendering. */ -import type { File, RemoteFile } from './types'; +import type { LocalFile, RemoteFile } from './types'; export interface TreeNode { name: string; - file?: File | RemoteFile; + file?: LocalFile | RemoteFile; children: TreeNode[]; parent?: TreeNode; } @@ -40,7 +40,7 @@ export function sortChildren(node: TreeNode) { } } -export function filesToFileTree(files: (File | RemoteFile)[]): TreeNode { +export function filesToFileTree(files: (LocalFile | RemoteFile)[]): TreeNode { const acc: TreeNode = { name: 'root', children: [] }; files.forEach((f) => { const pathParts = f.path.split('/'); @@ -51,8 +51,8 @@ export function filesToFileTree(files: (File | RemoteFile)[]): TreeNode { return acc; } -function fileTreeToList(node: TreeNode): (File | RemoteFile)[] { - const list: (File | RemoteFile)[] = []; +function fileTreeToList(node: TreeNode): (LocalFile | RemoteFile)[] { + const list: (LocalFile | RemoteFile)[] = []; if (node.file) list.push(node.file); node.children.forEach((child) => { list.push(...fileTreeToList(child)); @@ -61,6 +61,6 @@ function fileTreeToList(node: TreeNode): (File | RemoteFile)[] { } // Sorts a file list the same way it is sorted in a file tree -export function sortLikeFileTree(files: (File | RemoteFile)[]): (File | RemoteFile)[] { +export function sortLikeFileTree(files: (LocalFile | RemoteFile)[]): (LocalFile | RemoteFile)[] { return fileTreeToList(filesToFileTree(files)); } diff --git a/gitbutler-ui/src/lib/vbranches/ownership.ts b/gitbutler-ui/src/lib/vbranches/ownership.ts index dac003d19..532523c2c 100644 --- a/gitbutler-ui/src/lib/vbranches/ownership.ts +++ b/gitbutler-ui/src/lib/vbranches/ownership.ts @@ -1,6 +1,6 @@ -import type { Branch, File, RemoteFile } from './types'; +import type { Branch, LocalFile, RemoteFile } from './types'; -export function filesToOwnership(files: (File | RemoteFile)[]) { +export function filesToOwnership(files: (LocalFile | RemoteFile)[]) { return files.map((f) => `${f.path}:${f.hunks.map(({ id }) => id).join(',')}`).join('\n'); } diff --git a/gitbutler-ui/src/lib/vbranches/types.ts b/gitbutler-ui/src/lib/vbranches/types.ts index c5a39ba17..d3b99f659 100644 --- a/gitbutler-ui/src/lib/vbranches/types.ts +++ b/gitbutler-ui/src/lib/vbranches/types.ts @@ -23,7 +23,7 @@ export class Hunk { changeType!: ChangeType; } -export class File { +export class LocalFile { id!: string; path!: string; @Type(() => Hunk) @@ -58,8 +58,8 @@ export class Branch { notes!: string; // Active means the branch has been applied to the workspace active!: boolean; - @Type(() => File) - files!: File[]; + @Type(() => LocalFile) + files!: LocalFile[]; @Type(() => Commit) commits!: Commit[]; requiresForce!: boolean; @@ -93,8 +93,8 @@ export class Commit { createdAt!: Date; isRemote!: boolean; isIntegrated!: boolean; - @Type(() => File) - files!: File[]; + @Type(() => LocalFile) + files!: LocalFile[]; parentIds!: string[]; branchId!: string;