Skip to content

Update commit_changes to support tree changes along side commit changes #8324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/desktop/src/components/v3/FileListItemWrapper.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { draggableChips } from '$lib/dragging/draggable';
import { ChangeDropData } from '$lib/dragging/draggables';
import { getFilename } from '$lib/files/utils';
import { previousPathBytesFromTreeChange, type TreeChange } from '$lib/hunks/change';
import { ChangeSelectionService } from '$lib/selection/changeSelection.svelte';
import { IdSelection } from '$lib/selection/idSelection.svelte';
import { key, type SelectionId } from '$lib/selection/key';
Expand All @@ -13,7 +14,6 @@
import FileListItemV3 from '@gitbutler/ui/file/FileListItemV3.svelte';
import FileViewHeader from '@gitbutler/ui/file/FileViewHeader.svelte';
import { stickyHeader } from '@gitbutler/ui/utils/stickyHeader';
import type { TreeChange } from '$lib/hunks/change';
import type { Rename } from '$lib/hunks/change';
import type { UnifiedDiff } from '$lib/hunks/diff';

Expand Down Expand Up @@ -88,7 +88,8 @@
changeSelection.add({
type: 'full',
path,
pathBytes
pathBytes,
previousPathBytes: previousPathBytesFromTreeChange(change)
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/components/v3/NewCommitView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
if (item.type === 'full') {
worktreeChanges.push({
pathBytes: item.pathBytes,
previousPathBytes: item.previousPathBytes,
hunkHeaders: []
});
continue;
Expand All @@ -123,6 +124,7 @@
}
worktreeChanges.push({
pathBytes: item.pathBytes,
previousPathBytes: item.previousPathBytes,
hunkHeaders
});
continue;
Expand Down
4 changes: 3 additions & 1 deletion apps/desktop/src/components/v3/TreeListFolder.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { countLeafNodes, getAllChanges, nodePath, type TreeNode } from '$lib/files/filetreeV3';
import { previousPathBytesFromTreeChange } from '$lib/hunks/change';
import { ChangeSelectionService } from '$lib/selection/changeSelection.svelte';
import { getContext } from '@gitbutler/shared/context';
import FolderListItem from '@gitbutler/ui/file/FolderListItem.svelte';
Expand Down Expand Up @@ -37,7 +38,8 @@
selectionService.add({
type: 'full',
path: change.path,
pathBytes: change.pathBytes
pathBytes: change.pathBytes,
previousPathBytes: previousPathBytesFromTreeChange(change)
});
} else {
selectionService.remove(change.path);
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src/components/v3/UnifiedDiffView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import DependencyService from '$lib/dependencies/dependencyService.svelte';
import { draggableChips } from '$lib/dragging/draggable';
import { ChangeDropData } from '$lib/dragging/draggables';
import { previousPathBytesFromTreeChange, type TreeChange } from '$lib/hunks/change';
import { canBePartiallySelected, getLineLocks, type DiffHunk } from '$lib/hunks/hunk';
import { Project } from '$lib/project/project';
import { isWorkspacePath } from '$lib/routes/routes.svelte';
Expand All @@ -24,7 +25,6 @@
import { getContextStoreBySymbol, inject } from '@gitbutler/shared/context';
import EmptyStatePlaceholder from '@gitbutler/ui/EmptyStatePlaceholder.svelte';
import HunkDiff from '@gitbutler/ui/HunkDiff.svelte';
import type { TreeChange } from '$lib/hunks/change';
import type { UnifiedDiff } from '$lib/hunks/diff';
import type { LineId } from '@gitbutler/ui/utils/diffParsing';

Expand Down Expand Up @@ -67,7 +67,8 @@
const selection = $derived(changeSelectionResult.current);
const pathData = $derived({
path: change.path,
pathBytes: change.pathBytes
pathBytes: change.pathBytes,
previousPathBytes: previousPathBytesFromTreeChange(change)
});

const changesTimestamp = $derived(worktreeService.getChangesTimeStamp(projectId));
Expand Down
8 changes: 6 additions & 2 deletions apps/desktop/src/components/v3/WorktreeChanges.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { createCommitStore } from '$lib/commits/contexts';
import { Focusable, FocusManager } from '$lib/focus/focusManager.svelte';
import { focusable } from '$lib/focus/focusable.svelte';
import { previousPathBytesFromTreeChange } from '$lib/hunks/change';
import { ChangeSelectionService, type SelectedFile } from '$lib/selection/changeSelection.svelte';
import { StackService } from '$lib/stacks/stackService.svelte';
import { UiState } from '$lib/state/uiState.svelte';
Expand Down Expand Up @@ -72,10 +73,13 @@

function selectEverything() {
const affectedPaths =
changesResult.current.data?.map((c) => [c.path, c.pathBytes] as const) ?? [];
const files: SelectedFile[] = affectedPaths.map(([path, pathBytes]) => ({
changesResult.current.data?.map(
(c) => [c.path, c.pathBytes, previousPathBytesFromTreeChange(c)] as const
) ?? [];
const files: SelectedFile[] = affectedPaths.map(([path, pathBytes, previousPathBytes]) => ({
path,
pathBytes,
previousPathBytes,
type: 'full'
}));
changeSelection.addMany(files);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type TreeChange } from '$lib/hunks/change';
import { previousPathBytesFromTreeChange, type TreeChange } from '$lib/hunks/change';
import { leftJoinBy, outerJoinBy } from '$lib/utils/array';
import { isDefined } from '@gitbutler/ui/utils/typeguards';
import type { DiffHunk } from '$lib/hunks/hunk';
Expand All @@ -21,7 +21,8 @@ export default class LineSelection {
this.change
? {
path: this.change.path,
pathBytes: this.change.pathBytes
pathBytes: this.change.pathBytes,
previousPathBytes: previousPathBytesFromTreeChange(this.change)
}
: undefined
);
Expand Down
7 changes: 7 additions & 0 deletions apps/desktop/src/lib/hunks/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export type TreeChange = {
readonly status: Status;
};

export function previousPathBytesFromTreeChange(treeChange: TreeChange): number[] | null {
if (treeChange.status.type === 'Rename') {
return treeChange.status.subject.previousPathBytes;
}
return null;
}

export type TreeStats = {
/** The total amount of lines added. */
readonly linesAdded: number;
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/lib/selection/changeSelection.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type SelectedHunk = FullySelectedHunk | PartiallySelectedHunk;
type FileHeader = {
path: string;
pathBytes: number[];
previousPathBytes: number[] | null;
};

export type FullySelectedFile = FileHeader & {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/stacks/stackService.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type CreateCommitRequest = {
parentId: string | undefined;
stackBranchName: string;
worktreeChanges: {
previousPathBytes?: number[];
previousPathBytes: number[] | null;
pathBytes: number[];
hunkHeaders: HunkHeader[];
}[];
Expand Down
Loading