Skip to content

Commit cef5c1b

Browse files
Merge pull request #8324 from gitbutlerapp/commiting-renames
Update commit_changes to support tree changes along side commit changes
2 parents f3afca8 + bc8b25e commit cef5c1b

File tree

9 files changed

+29
-10
lines changed

9 files changed

+29
-10
lines changed

apps/desktop/src/components/v3/FileListItemWrapper.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { draggableChips } from '$lib/dragging/draggable';
55
import { ChangeDropData } from '$lib/dragging/draggables';
66
import { getFilename } from '$lib/files/utils';
7+
import { previousPathBytesFromTreeChange, type TreeChange } from '$lib/hunks/change';
78
import { ChangeSelectionService } from '$lib/selection/changeSelection.svelte';
89
import { IdSelection } from '$lib/selection/idSelection.svelte';
910
import { key, type SelectionId } from '$lib/selection/key';
@@ -13,7 +14,6 @@
1314
import FileListItemV3 from '@gitbutler/ui/file/FileListItemV3.svelte';
1415
import FileViewHeader from '@gitbutler/ui/file/FileViewHeader.svelte';
1516
import { stickyHeader } from '@gitbutler/ui/utils/stickyHeader';
16-
import type { TreeChange } from '$lib/hunks/change';
1717
import type { Rename } from '$lib/hunks/change';
1818
import type { UnifiedDiff } from '$lib/hunks/diff';
1919
@@ -88,7 +88,8 @@
8888
changeSelection.add({
8989
type: 'full',
9090
path,
91-
pathBytes
91+
pathBytes,
92+
previousPathBytes: previousPathBytesFromTreeChange(change)
9293
});
9394
}
9495
}

apps/desktop/src/components/v3/NewCommitView.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
if (item.type === 'full') {
9999
worktreeChanges.push({
100100
pathBytes: item.pathBytes,
101+
previousPathBytes: item.previousPathBytes,
101102
hunkHeaders: []
102103
});
103104
continue;
@@ -123,6 +124,7 @@
123124
}
124125
worktreeChanges.push({
125126
pathBytes: item.pathBytes,
127+
previousPathBytes: item.previousPathBytes,
126128
hunkHeaders
127129
});
128130
continue;

apps/desktop/src/components/v3/TreeListFolder.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import { countLeafNodes, getAllChanges, nodePath, type TreeNode } from '$lib/files/filetreeV3';
3+
import { previousPathBytesFromTreeChange } from '$lib/hunks/change';
34
import { ChangeSelectionService } from '$lib/selection/changeSelection.svelte';
45
import { getContext } from '@gitbutler/shared/context';
56
import FolderListItem from '@gitbutler/ui/file/FolderListItem.svelte';
@@ -37,7 +38,8 @@
3738
selectionService.add({
3839
type: 'full',
3940
path: change.path,
40-
pathBytes: change.pathBytes
41+
pathBytes: change.pathBytes,
42+
previousPathBytes: previousPathBytesFromTreeChange(change)
4143
});
4244
} else {
4345
selectionService.remove(change.path);

apps/desktop/src/components/v3/UnifiedDiffView.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import DependencyService from '$lib/dependencies/dependencyService.svelte';
99
import { draggableChips } from '$lib/dragging/draggable';
1010
import { ChangeDropData } from '$lib/dragging/draggables';
11+
import { previousPathBytesFromTreeChange, type TreeChange } from '$lib/hunks/change';
1112
import { canBePartiallySelected, getLineLocks, type DiffHunk } from '$lib/hunks/hunk';
1213
import { Project } from '$lib/project/project';
1314
import { isWorkspacePath } from '$lib/routes/routes.svelte';
@@ -24,7 +25,6 @@
2425
import { getContextStoreBySymbol, inject } from '@gitbutler/shared/context';
2526
import EmptyStatePlaceholder from '@gitbutler/ui/EmptyStatePlaceholder.svelte';
2627
import HunkDiff from '@gitbutler/ui/HunkDiff.svelte';
27-
import type { TreeChange } from '$lib/hunks/change';
2828
import type { UnifiedDiff } from '$lib/hunks/diff';
2929
import type { LineId } from '@gitbutler/ui/utils/diffParsing';
3030
@@ -67,7 +67,8 @@
6767
const selection = $derived(changeSelectionResult.current);
6868
const pathData = $derived({
6969
path: change.path,
70-
pathBytes: change.pathBytes
70+
pathBytes: change.pathBytes,
71+
previousPathBytes: previousPathBytesFromTreeChange(change)
7172
});
7273
7374
const changesTimestamp = $derived(worktreeService.getChangesTimeStamp(projectId));

apps/desktop/src/components/v3/WorktreeChanges.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { createCommitStore } from '$lib/commits/contexts';
99
import { Focusable, FocusManager } from '$lib/focus/focusManager.svelte';
1010
import { focusable } from '$lib/focus/focusable.svelte';
11+
import { previousPathBytesFromTreeChange } from '$lib/hunks/change';
1112
import { ChangeSelectionService, type SelectedFile } from '$lib/selection/changeSelection.svelte';
1213
import { StackService } from '$lib/stacks/stackService.svelte';
1314
import { UiState } from '$lib/state/uiState.svelte';
@@ -72,10 +73,13 @@
7273
7374
function selectEverything() {
7475
const affectedPaths =
75-
changesResult.current.data?.map((c) => [c.path, c.pathBytes] as const) ?? [];
76-
const files: SelectedFile[] = affectedPaths.map(([path, pathBytes]) => ({
76+
changesResult.current.data?.map(
77+
(c) => [c.path, c.pathBytes, previousPathBytesFromTreeChange(c)] as const
78+
) ?? [];
79+
const files: SelectedFile[] = affectedPaths.map(([path, pathBytes, previousPathBytes]) => ({
7780
path,
7881
pathBytes,
82+
previousPathBytes,
7983
type: 'full'
8084
}));
8185
changeSelection.addMany(files);

apps/desktop/src/components/v3/unifiedDiffLineSelection.svelte.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type TreeChange } from '$lib/hunks/change';
1+
import { previousPathBytesFromTreeChange, type TreeChange } from '$lib/hunks/change';
22
import { leftJoinBy, outerJoinBy } from '$lib/utils/array';
33
import { isDefined } from '@gitbutler/ui/utils/typeguards';
44
import type { DiffHunk } from '$lib/hunks/hunk';
@@ -21,7 +21,8 @@ export default class LineSelection {
2121
this.change
2222
? {
2323
path: this.change.path,
24-
pathBytes: this.change.pathBytes
24+
pathBytes: this.change.pathBytes,
25+
previousPathBytes: previousPathBytesFromTreeChange(this.change)
2526
}
2627
: undefined
2728
);

apps/desktop/src/lib/hunks/change.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export type TreeChange = {
2525
readonly status: Status;
2626
};
2727

28+
export function previousPathBytesFromTreeChange(treeChange: TreeChange): number[] | null {
29+
if (treeChange.status.type === 'Rename') {
30+
return treeChange.status.subject.previousPathBytes;
31+
}
32+
return null;
33+
}
34+
2835
export type TreeStats = {
2936
/** The total amount of lines added. */
3037
readonly linesAdded: number;

apps/desktop/src/lib/selection/changeSelection.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type SelectedHunk = FullySelectedHunk | PartiallySelectedHunk;
3737
type FileHeader = {
3838
path: string;
3939
pathBytes: number[];
40+
previousPathBytes: number[] | null;
4041
};
4142

4243
export type FullySelectedFile = FileHeader & {

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type CreateCommitRequest = {
3838
parentId: string | undefined;
3939
stackBranchName: string;
4040
worktreeChanges: {
41-
previousPathBytes?: number[];
41+
previousPathBytes: number[] | null;
4242
pathBytes: number[];
4343
hunkHeaders: HunkHeader[];
4444
}[];

0 commit comments

Comments
 (0)