mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-18 06:22:28 +03:00
Rename File -> LocalFile
This commit is contained in:
parent
f5428dcec7
commit
c813dddcd9
@ -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;
|
||||
|
@ -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<File[]>;
|
||||
export let selectedFiles: Writable<LocalFile[]>;
|
||||
export let githubService: GitHubService;
|
||||
export let selectedOwnership: Writable<Ownership>;
|
||||
export let commitBoxOpen: Writable<boolean>;
|
||||
|
@ -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;
|
||||
</script>
|
||||
|
@ -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<Ownership>;
|
||||
export let selectedFiles: Writable<File[]>;
|
||||
export let selectedFiles: Writable<LocalFile[]>;
|
||||
export let showCheckboxes = false;
|
||||
|
||||
let selectedListMode: string;
|
||||
|
@ -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<Ownership>;
|
||||
export let showCheckboxes = false;
|
||||
|
||||
export let selectedListMode: string;
|
||||
|
||||
function selectAll(selectedOwnership: Writable<Ownership>, files: (File | RemoteFile)[]) {
|
||||
function selectAll(selectedOwnership: Writable<Ownership>, files: (LocalFile | RemoteFile)[]) {
|
||||
files.forEach((f) =>
|
||||
selectedOwnership.update((ownership) => ownership.addHunk(f.id, ...f.hunks.map((h) => h.id)))
|
||||
);
|
||||
|
@ -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<Ownership>;
|
||||
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);
|
||||
|
@ -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<File[]>([]);
|
||||
const selectedFiles = writable<LocalFile[]>([]);
|
||||
|
||||
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 == 1 && files[0] instanceof RemoteFile) return files[0];
|
||||
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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.
|
||||
|
@ -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 }>();
|
||||
|
@ -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<Ownership>;
|
||||
export let selectedFiles: Writable<(File | RemoteFile)[]>;
|
||||
export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
|
||||
|
||||
let checked = false;
|
||||
let indeterminate = false;
|
||||
|
@ -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);
|
||||
</script>
|
||||
|
||||
|
@ -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<Ownership>;
|
||||
export let selectedFiles: Writable<(File | RemoteFile)[]>;
|
||||
export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
|
||||
export let branchId: string;
|
||||
export let isUnapplied: boolean;
|
||||
export let allowMultiple = false;
|
||||
|
@ -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)[]>([]);
|
||||
</script>
|
||||
|
||||
{#if branch != undefined}
|
||||
|
@ -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<Ownership>;
|
||||
export let selectedFiles: Writable<(File | RemoteFile)[]>;
|
||||
export let selectedFiles: Writable<(LocalFile | RemoteFile)[]>;
|
||||
|
||||
let checked = false;
|
||||
let indeterminate = false;
|
||||
|
@ -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 } };
|
||||
}
|
||||
|
@ -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],
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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';
|
||||
|
@ -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'))
|
||||
|
@ -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: [],
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user