Rename File -> LocalFile

This commit is contained in:
Mattias Granlund 2024-02-01 10:34:16 +01:00
parent f5428dcec7
commit c813dddcd9
27 changed files with 83 additions and 77 deletions

View File

@ -6,7 +6,7 @@
import { tooltip } from '$lib/utils/tooltip'; import { tooltip } from '$lib/utils/tooltip';
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import type { BranchController } from '$lib/vbranches/branchController'; 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 base: BaseBranch;
export let projectId: string; export let projectId: string;
@ -16,7 +16,7 @@
const mergeUpstreamWarningDismissed = projectMergeUpstreamWarningDismissed( const mergeUpstreamWarningDismissed = projectMergeUpstreamWarningDismissed(
branchController.projectId branchController.projectId
); );
const selectedFiles = writable<(File | RemoteFile)[]>([]); const selectedFiles = writable<(LocalFile | RemoteFile)[]>([]);
let updateTargetModal: Modal; let updateTargetModal: Modal;
let mergeUpstreamWarningDismissedCheckbox = false; let mergeUpstreamWarningDismissedCheckbox = false;

View File

@ -28,7 +28,7 @@
import type { BranchService } from '$lib/branches/service'; import type { BranchService } from '$lib/branches/service';
import type { GitHubService } from '$lib/github/service'; import type { GitHubService } from '$lib/github/service';
import type { BranchController } from '$lib/vbranches/branchController'; 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 branch: Branch;
export let isUnapplied = false; export let isUnapplied = false;
@ -39,7 +39,7 @@
export let branchController: BranchController; export let branchController: BranchController;
export let branchCount = 1; export let branchCount = 1;
export let user: User | undefined; export let user: User | undefined;
export let selectedFiles: Writable<File[]>; export let selectedFiles: Writable<LocalFile[]>;
export let githubService: GitHubService; export let githubService: GitHubService;
export let selectedOwnership: Writable<Ownership>; export let selectedOwnership: Writable<Ownership>;
export let commitBoxOpen: Writable<boolean>; export let commitBoxOpen: Writable<boolean>;

View File

@ -4,7 +4,7 @@
import type { BranchService } from '$lib/branches/service'; import type { BranchService } from '$lib/branches/service';
import type { GitHubService } from '$lib/github/service'; import type { GitHubService } from '$lib/github/service';
import type { BranchController } from '$lib/vbranches/branchController'; 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'; import type { Writable } from 'svelte/store';
export let project: Project; export let project: Project;
@ -13,7 +13,7 @@
export let githubService: GitHubService; export let githubService: GitHubService;
export let branchController: BranchController; export let branchController: BranchController;
export let branchService: BranchService; export let branchService: BranchService;
export let selectedFiles: Writable<(File | RemoteFile)[]>; export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
export let isUnapplied: boolean; export let isUnapplied: boolean;
export let branchCount: number; export let branchCount: number;
</script> </script>

View File

@ -4,13 +4,13 @@
import FileTree from './FileTree.svelte'; import FileTree from './FileTree.svelte';
import { filesToFileTree } from '$lib/vbranches/filetree'; import { filesToFileTree } from '$lib/vbranches/filetree';
import type { Ownership } from '$lib/vbranches/ownership'; 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'; import type { Writable } from 'svelte/store';
export let branch: Branch; export let branch: Branch;
export let isUnapplied: boolean; export let isUnapplied: boolean;
export let selectedOwnership: Writable<Ownership>; export let selectedOwnership: Writable<Ownership>;
export let selectedFiles: Writable<File[]>; export let selectedFiles: Writable<LocalFile[]>;
export let showCheckboxes = false; export let showCheckboxes = false;
let selectedListMode: string; let selectedListMode: string;

View File

@ -4,16 +4,16 @@
import Segment from '$lib/components/SegmentControl/Segment.svelte'; import Segment from '$lib/components/SegmentControl/Segment.svelte';
import SegmentedControl from '$lib/components/SegmentControl/SegmentedControl.svelte'; import SegmentedControl from '$lib/components/SegmentControl/SegmentedControl.svelte';
import type { Ownership } from '$lib/vbranches/ownership'; 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'; import type { Writable } from 'svelte/store';
export let files: (File | RemoteFile)[]; export let files: (LocalFile | RemoteFile)[];
export let selectedOwnership: Writable<Ownership>; export let selectedOwnership: Writable<Ownership>;
export let showCheckboxes = false; export let showCheckboxes = false;
export let selectedListMode: string; export let selectedListMode: string;
function selectAll(selectedOwnership: Writable<Ownership>, files: (File | RemoteFile)[]) { function selectAll(selectedOwnership: Writable<Ownership>, files: (LocalFile | RemoteFile)[]) {
files.forEach((f) => files.forEach((f) =>
selectedOwnership.update((ownership) => ownership.addHunk(f.id, ...f.hunks.map((h) => h.id))) selectedOwnership.update((ownership) => ownership.addHunk(f.id, ...f.hunks.map((h) => h.id)))
); );

View File

@ -2,15 +2,15 @@
import FileListItem from './FileListItem.svelte'; import FileListItem from './FileListItem.svelte';
import { sortLikeFileTree } from '$lib/vbranches/filetree'; import { sortLikeFileTree } from '$lib/vbranches/filetree';
import type { Ownership } from '$lib/vbranches/ownership'; 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'; import type { Writable } from 'svelte/store';
export let branchId: string; export let branchId: string;
export let files: (File | RemoteFile)[]; export let files: (LocalFile | RemoteFile)[];
export let selectedOwnership: Writable<Ownership>; export let selectedOwnership: Writable<Ownership>;
export let isUnapplied = false; export let isUnapplied = false;
export let showCheckboxes = false; export let showCheckboxes = false;
export let selectedFiles: Writable<(File | RemoteFile)[]>; export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
export let allowMultiple = false; export let allowMultiple = false;
$: console.log(selectedFiles); $: console.log(selectedFiles);

View File

@ -2,7 +2,7 @@
import BranchCard from './BranchCard.svelte'; import BranchCard from './BranchCard.svelte';
import FileCard from './FileCard.svelte'; import FileCard from './FileCard.svelte';
import { Ownership } from '$lib/vbranches/ownership'; 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 { writable, type Writable } from 'svelte/store';
import type { User, getCloudApiClient } from '$lib/backend/cloud'; import type { User, getCloudApiClient } from '$lib/backend/cloud';
import type { Project } from '$lib/backend/projects'; import type { Project } from '$lib/backend/projects';
@ -25,11 +25,11 @@
$: selectedOwnership = writable(Ownership.fromBranch(branch)); $: selectedOwnership = writable(Ownership.fromBranch(branch));
$: selected = setSelected($selectedFiles, branch); $: selected = setSelected($selectedFiles, branch);
const selectedFiles = writable<File[]>([]); const selectedFiles = writable<LocalFile[]>([]);
let commitBoxOpen: Writable<boolean>; let commitBoxOpen: Writable<boolean>;
function setSelected(files: (File | RemoteFile)[], branch: Branch) { function setSelected(files: (LocalFile | RemoteFile)[], branch: Branch) {
if (files.length == 0) return undefined; if (files.length == 0) return undefined;
if (files.length == 1 && files[0] instanceof RemoteFile) return files[0]; if (files.length == 1 && files[0] instanceof RemoteFile) return files[0];

View File

@ -13,7 +13,7 @@
import { filesToFileTree } from '$lib/vbranches/filetree'; import { filesToFileTree } from '$lib/vbranches/filetree';
import { Ownership } from '$lib/vbranches/ownership'; import { Ownership } from '$lib/vbranches/ownership';
import { listRemoteCommitFiles } from '$lib/vbranches/remoteCommits'; 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 { open } from '@tauri-apps/api/shell';
import { writable, type Writable } from 'svelte/store'; import { writable, type Writable } from 'svelte/store';
import type { ContentSection, HunkSection } from '$lib/utils/fileSections'; import type { ContentSection, HunkSection } from '$lib/utils/fileSections';
@ -27,7 +27,7 @@
export let isUnapplied = false; export let isUnapplied = false;
export let branchController: BranchController; export let branchController: BranchController;
export let projectPath: string; export let projectPath: string;
export let selectedFiles: Writable<(File | RemoteFile)[]>; export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
const selectedOwnership = writable(Ownership.default()); const selectedOwnership = writable(Ownership.default());

View File

@ -21,7 +21,7 @@
import type { User, getCloudApiClient } from '$lib/backend/cloud'; import type { User, getCloudApiClient } from '$lib/backend/cloud';
import type { BranchController } from '$lib/vbranches/branchController'; import type { BranchController } from '$lib/vbranches/branchController';
import type { Ownership } from '$lib/vbranches/ownership'; 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'; import type { Writable } from 'svelte/store';
const dispatch = createEventDispatcher<{ const dispatch = createEventDispatcher<{
@ -74,7 +74,7 @@
$: checkCommitsAnnotated(); $: checkCommitsAnnotated();
let isGeneratingCommigMessage = false; let isGeneratingCommigMessage = false;
async function generateCommitMessage(files: File[]) { async function generateCommitMessage(files: LocalFile[]) {
const diff = files const diff = files
.map((f) => f.hunks.filter((h) => $selectedOwnership.containsHunk(f.id, h.id))) .map((f) => f.hunks.filter((h) => $selectedOwnership.containsHunk(f.id, h.id)))
.flat() .flat()

View File

@ -6,7 +6,13 @@
import type { BranchService } from '$lib/branches/service'; import type { BranchService } from '$lib/branches/service';
import type { GitHubService } from '$lib/github/service'; import type { GitHubService } from '$lib/github/service';
import type { BranchController } from '$lib/vbranches/branchController'; 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'; import type { Writable } from 'svelte/store';
export let branch: Branch; export let branch: Branch;
@ -16,7 +22,7 @@
export let type: CommitStatus; export let type: CommitStatus;
export let githubService: GitHubService; export let githubService: GitHubService;
export let branchService: BranchService; export let branchService: BranchService;
export let selectedFiles: Writable<(File | RemoteFile)[]>; export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
export let isUnapplied: boolean; export let isUnapplied: boolean;
export let branchCount: number = 0; export let branchCount: number = 0;

View File

@ -16,7 +16,7 @@
type BaseBranch, type BaseBranch,
type Branch, type Branch,
type Commit, type Commit,
type File, type LocalFile,
RemoteFile RemoteFile
} from '$lib/vbranches/types'; } from '$lib/vbranches/types';
import { get, type Writable } from 'svelte/store'; import { get, type Writable } from 'svelte/store';
@ -31,7 +31,7 @@
export let isChained: boolean; export let isChained: boolean;
export let isUnapplied = false; export let isUnapplied = false;
export let branchController: BranchController; export let branchController: BranchController;
export let selectedFiles: Writable<(File | RemoteFile)[]>; export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
function acceptAmend(commit: Commit | RemoteCommit) { function acceptAmend(commit: Commit | RemoteCommit) {
if (commit instanceof RemoteCommit) { if (commit instanceof RemoteCommit) {

View File

@ -12,12 +12,12 @@
import { slide } from 'svelte/transition'; import { slide } from 'svelte/transition';
import type { BranchController } from '$lib/vbranches/branchController'; import type { BranchController } from '$lib/vbranches/branchController';
import type { Ownership } from '$lib/vbranches/ownership'; 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'; import type { Writable } from 'svelte/store';
export let projectId: string; export let projectId: string;
export let branchId: string; export let branchId: string;
export let file: File | RemoteFile; export let file: LocalFile | RemoteFile;
export let conflicted: boolean; export let conflicted: boolean;
export let projectPath: string | undefined; export let projectPath: string | undefined;
export let branchController: BranchController; export let branchController: BranchController;
@ -35,7 +35,7 @@
let sections: (HunkSection | ContentSection)[] = []; 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 // When we toggle expansion status on sections we need to assign
// `sections = sections` to redraw, and why we do not use a reactive // `sections = sections` to redraw, and why we do not use a reactive
// variable. // variable.

View File

@ -6,9 +6,9 @@
import { computeFileStatus } from '$lib/utils/fileStatus'; import { computeFileStatus } from '$lib/utils/fileStatus';
import { computeAddedRemovedByFiles } from '$lib/utils/metrics'; import { computeAddedRemovedByFiles } from '$lib/utils/metrics';
import { createEventDispatcher } from 'svelte'; 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; export let isFileLocked: boolean;
const dispatch = createEventDispatcher<{ close: void }>(); const dispatch = createEventDispatcher<{ close: void }>();

View File

@ -5,16 +5,16 @@
import { draggableFile } from '$lib/dragging/draggables'; import { draggableFile } from '$lib/dragging/draggables';
import { getVSIFileIcon } from '$lib/ext-icons'; import { getVSIFileIcon } from '$lib/ext-icons';
import type { Ownership } from '$lib/vbranches/ownership'; 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'; import type { Writable } from 'svelte/store';
export let branchId: string; export let branchId: string;
export let file: File | RemoteFile; export let file: LocalFile | RemoteFile;
export let isUnapplied: boolean; export let isUnapplied: boolean;
export let selected: boolean; export let selected: boolean;
export let showCheckbox: boolean = false; export let showCheckbox: boolean = false;
export let selectedOwnership: Writable<Ownership>; export let selectedOwnership: Writable<Ownership>;
export let selectedFiles: Writable<(File | RemoteFile)[]>; export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
let checked = false; let checked = false;
let indeterminate = false; let indeterminate = false;

View File

@ -2,9 +2,9 @@
import FileStatusCircle from './FileStatusCircle.svelte'; import FileStatusCircle from './FileStatusCircle.svelte';
import Icon from '$lib/components/Icon.svelte'; import Icon from '$lib/components/Icon.svelte';
import { computeFileStatus } from '$lib/utils/fileStatus'; 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); $: isLocked = file.hunks.some((h) => h.locked);
</script> </script>

View File

@ -7,7 +7,7 @@
import TreeListFolder from './TreeListFolder.svelte'; import TreeListFolder from './TreeListFolder.svelte';
import type { TreeNode } from '$lib/vbranches/filetree'; import type { TreeNode } from '$lib/vbranches/filetree';
import type { Ownership } from '$lib/vbranches/ownership'; 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'; import type { Writable } from 'svelte/store';
export let expanded = true; export let expanded = true;
@ -15,7 +15,7 @@
export let isRoot = false; export let isRoot = false;
export let showCheckboxes = false; export let showCheckboxes = false;
export let selectedOwnership: Writable<Ownership>; export let selectedOwnership: Writable<Ownership>;
export let selectedFiles: Writable<(File | RemoteFile)[]>; export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
export let branchId: string; export let branchId: string;
export let isUnapplied: boolean; export let isUnapplied: boolean;
export let allowMultiple = false; export let allowMultiple = false;

View File

@ -2,7 +2,7 @@
import Button from '$lib/components/Button.svelte'; import Button from '$lib/components/Button.svelte';
import CommitCard from '$lib/components/CommitCard.svelte'; import CommitCard from '$lib/components/CommitCard.svelte';
import type { BranchController } from '$lib/vbranches/branchController'; 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'; import { writable } from 'svelte/store';
export let branch: RemoteBranch | undefined; export let branch: RemoteBranch | undefined;
@ -10,7 +10,7 @@
export let projectPath: string; export let projectPath: string;
export let branchController: BranchController; export let branchController: BranchController;
const selectedFiles = writable<(File | RemoteFile)[]>([]); const selectedFiles = writable<(LocalFile | RemoteFile)[]>([]);
</script> </script>
{#if branch != undefined} {#if branch != undefined}

View File

@ -5,16 +5,16 @@
import { draggableFile } from '$lib/dragging/draggables'; import { draggableFile } from '$lib/dragging/draggables';
import { getVSIFileIcon } from '$lib/ext-icons'; import { getVSIFileIcon } from '$lib/ext-icons';
import type { Ownership } from '$lib/vbranches/ownership'; 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'; import type { Writable } from 'svelte/store';
export let branchId: string; export let branchId: string;
export let file: File | RemoteFile; export let file: LocalFile | RemoteFile;
export let selected: boolean; export let selected: boolean;
export let isUnapplied: boolean; export let isUnapplied: boolean;
export let showCheckbox: boolean = false; export let showCheckbox: boolean = false;
export let selectedOwnership: Writable<Ownership>; export let selectedOwnership: Writable<Ownership>;
export let selectedFiles: Writable<(File | RemoteFile)[]>; export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
let checked = false; let checked = false;
let indeterminate = false; let indeterminate = false;

View File

@ -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'; import type { Writable } from 'svelte/store';
export function nonDraggable() { export function nonDraggable() {
@ -23,14 +23,14 @@ export function isDraggableHunk(obj: any): obj is DraggableHunk {
export type DraggableFile = { export type DraggableFile = {
branchId: string; branchId: string;
files: Writable<(File | RemoteFile)[]>; files: Writable<(LocalFile | RemoteFile)[]>;
current: File; current: LocalFile;
}; };
export function draggableFile( export function draggableFile(
branchId: string, branchId: string,
current: File | RemoteFile, current: LocalFile | RemoteFile,
files: Writable<(File | RemoteFile)[]> files: Writable<(LocalFile | RemoteFile)[]>
) { ) {
return { data: { branchId, current, files } }; return { data: { branchId, current, files } };
} }

View File

@ -1,5 +1,5 @@
import { parseHunkSection, parseFileSections, SectionType } from '$lib/utils/fileSections'; 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 { plainToInstance } from 'class-transformer';
import { expect, test } from 'vitest'; import { expect, test } from 'vitest';
import type { ContentSection, HunkSection } from '$lib/utils/fileSections'; 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', filePath: 'foo.py',
locked: false locked: false
}); });
const file = plainToInstance(File, { const file = plainToInstance(LocalFile, {
id: '1', id: '1',
path: 'foo.py', path: 'foo.py',
hunks: [hunk], hunks: [hunk],
@ -476,7 +476,7 @@ test('parses file with one hunk with more added than removed', () => {
filePath: 'foo.py', filePath: 'foo.py',
locked: false locked: false
}); });
const file = plainToInstance(File, { const file = plainToInstance(LocalFile, {
id: '1', id: '1',
path: 'foo.py', path: 'foo.py',
hunks: [hunk], hunks: [hunk],
@ -538,7 +538,7 @@ test('parses file with two hunks ordered by position in file', () => {
filePath: 'foo.py', filePath: 'foo.py',
locked: false locked: false
}); });
const file = plainToInstance(File, { const file = plainToInstance(LocalFile, {
id: '1', id: '1',
path: 'foo.py', path: 'foo.py',
hunks: [bottomHunk, topHunk], hunks: [bottomHunk, topHunk],
@ -611,7 +611,7 @@ test('parses whole file deleted', () => {
filePath: 'foo.py', filePath: 'foo.py',
locked: false locked: false
}); });
const file = plainToInstance(File, { const file = plainToInstance(LocalFile, {
id: '1', id: '1',
path: 'foo.py', path: 'foo.py',
hunks: [deleteHunk], hunks: [deleteHunk],
@ -638,7 +638,7 @@ test('parses new file created', () => {
filePath: 'foo.py', filePath: 'foo.py',
locked: false locked: false
}); });
const file = plainToInstance(File, { const file = plainToInstance(LocalFile, {
id: '1', id: '1',
path: 'foo.py', path: 'foo.py',
hunks: [newFileHunk], hunks: [newFileHunk],

View File

@ -1,4 +1,4 @@
import { File } from '$lib/vbranches/types'; import { LocalFile } from '$lib/vbranches/types';
import { plainToInstance } from 'class-transformer'; import { plainToInstance } from 'class-transformer';
import type { Hunk, RemoteFile, RemoteHunk } from '$lib/vbranches/types'; import type { Hunk, RemoteFile, RemoteHunk } from '$lib/vbranches/types';
@ -146,13 +146,13 @@ export function parseHunkSection(hunk: Hunk | RemoteHunk): HunkSection {
return hunkSection; return hunkSection;
} }
export function parseFileSections(file: File | RemoteFile): (ContentSection | HunkSection)[] { export function parseFileSections(file: LocalFile | RemoteFile): (ContentSection | HunkSection)[] {
const hunkSections = file.hunks const hunkSections = file.hunks
.map(parseHunkSection) .map(parseHunkSection)
.filter((hunkSection) => hunkSection !== undefined) .filter((hunkSection) => hunkSection !== undefined)
.sort((a, b) => a.header.beforeStart - b.header.beforeStart); .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; if (!content) return hunkSections;

View File

@ -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 type FileStatus = 'A' | 'M' | 'D';
export function computeFileStatus(file: File | RemoteFile): FileStatus { export function computeFileStatus(file: LocalFile | RemoteFile): FileStatus {
if (file instanceof RemoteFile) { if (file instanceof RemoteFile) {
// TODO: How do we compute this for remote files? // TODO: How do we compute this for remote files?
return 'M'; return 'M';

View File

@ -1,7 +1,7 @@
import { HunkSection, type ContentSection } from './fileSections'; 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 return files
.flatMap((f) => f.hunks) .flatMap((f) => f.hunks)
.map((h) => h.diff.split('\n')) .map((h) => h.diff.split('\n'))

View File

@ -1,11 +1,11 @@
import { filesToFileTree } from './filetree'; import { filesToFileTree } from './filetree';
import { File } from '$lib/vbranches/types'; import { LocalFile } from '$lib/vbranches/types';
import { plainToInstance } from 'class-transformer'; import { plainToInstance } from 'class-transformer';
import { expect, test } from 'vitest'; import { expect, test } from 'vitest';
test('creates a file tree', () => { test('creates a file tree', () => {
const files = [ const files = [
plainToInstance(File, { plainToInstance(LocalFile, {
id: '1234', id: '1234',
path: 'test/foo.py', path: 'test/foo.py',
hunks: [], hunks: [],
@ -15,7 +15,7 @@ test('creates a file tree', () => {
content: undefined, content: undefined,
binary: false binary: false
}), }),
plainToInstance(File, { plainToInstance(LocalFile, {
id: '1234', id: '1234',
path: 'test/bar.rs', path: 'test/bar.rs',
hunks: [], hunks: [],
@ -25,7 +25,7 @@ test('creates a file tree', () => {
content: undefined, content: undefined,
binary: false binary: false
}), }),
plainToInstance(File, { plainToInstance(LocalFile, {
id: '1234', id: '1234',
path: 'src/hello/world.txt', path: 'src/hello/world.txt',
hunks: [], hunks: [],

View File

@ -4,11 +4,11 @@
* This module provides support for tranforming a list of files into a * This module provides support for tranforming a list of files into a
* hirerarchical structure for easy rendering. * hirerarchical structure for easy rendering.
*/ */
import type { File, RemoteFile } from './types'; import type { LocalFile, RemoteFile } from './types';
export interface TreeNode { export interface TreeNode {
name: string; name: string;
file?: File | RemoteFile; file?: LocalFile | RemoteFile;
children: TreeNode[]; children: TreeNode[];
parent?: 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: [] }; const acc: TreeNode = { name: 'root', children: [] };
files.forEach((f) => { files.forEach((f) => {
const pathParts = f.path.split('/'); const pathParts = f.path.split('/');
@ -51,8 +51,8 @@ export function filesToFileTree(files: (File | RemoteFile)[]): TreeNode {
return acc; return acc;
} }
function fileTreeToList(node: TreeNode): (File | RemoteFile)[] { function fileTreeToList(node: TreeNode): (LocalFile | RemoteFile)[] {
const list: (File | RemoteFile)[] = []; const list: (LocalFile | RemoteFile)[] = [];
if (node.file) list.push(node.file); if (node.file) list.push(node.file);
node.children.forEach((child) => { node.children.forEach((child) => {
list.push(...fileTreeToList(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 // 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)); return fileTreeToList(filesToFileTree(files));
} }

View File

@ -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'); return files.map((f) => `${f.path}:${f.hunks.map(({ id }) => id).join(',')}`).join('\n');
} }

View File

@ -23,7 +23,7 @@ export class Hunk {
changeType!: ChangeType; changeType!: ChangeType;
} }
export class File { export class LocalFile {
id!: string; id!: string;
path!: string; path!: string;
@Type(() => Hunk) @Type(() => Hunk)
@ -58,8 +58,8 @@ export class Branch {
notes!: string; notes!: string;
// Active means the branch has been applied to the workspace // Active means the branch has been applied to the workspace
active!: boolean; active!: boolean;
@Type(() => File) @Type(() => LocalFile)
files!: File[]; files!: LocalFile[];
@Type(() => Commit) @Type(() => Commit)
commits!: Commit[]; commits!: Commit[];
requiresForce!: boolean; requiresForce!: boolean;
@ -93,8 +93,8 @@ export class Commit {
createdAt!: Date; createdAt!: Date;
isRemote!: boolean; isRemote!: boolean;
isIntegrated!: boolean; isIntegrated!: boolean;
@Type(() => File) @Type(() => LocalFile)
files!: File[]; files!: LocalFile[];
parentIds!: string[]; parentIds!: string[];
branchId!: string; branchId!: string;