Skip to content

Commit a01f745

Browse files
committed
Persist the redacted commit message
1 parent 09f6fb6 commit a01f745

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<script lang="ts">
22
import EditorFooter from '$components/v3/editor/EditorFooter.svelte';
33
import MessageEditor from '$components/v3/editor/MessageEditor.svelte';
4+
import { persistedCommitMessage } from '$lib/config/config';
45
import { persisted } from '@gitbutler/shared/persisted';
56
import Button from '@gitbutler/ui/Button.svelte';
67
import Textbox from '@gitbutler/ui/Textbox.svelte';
78
89
type Props = {
10+
isNewCommit?: boolean;
911
projectId: string;
1012
stackId: string;
1113
actionLabel: string;
@@ -18,6 +20,7 @@
1820
};
1921
2022
const {
23+
isNewCommit,
2124
projectId,
2225
stackId,
2326
actionLabel,
@@ -35,14 +38,19 @@
3538
let markdown = persisted(true, 'useMarkdown__' + projectId);
3639
3740
let titleText = $state<string | undefined>(initialTitle);
38-
let composer = $state<ReturnType<typeof MessageEditor>>();
41+
let descriptionText = $state<string | undefined>(initialValue);
42+
const commitMessage = persistedCommitMessage(projectId, stackId);
3943
40-
export function getTitle(): string | undefined {
41-
return titleText;
42-
}
44+
$effect(() => {
45+
if (isNewCommit) {
46+
$commitMessage = [titleText, descriptionText].filter((a) => a).join('\n\n');
47+
}
48+
});
49+
50+
let composer = $state<ReturnType<typeof MessageEditor>>();
4351
44-
export async function getPlaintext(): Promise<string | undefined> {
45-
return await composer?.getPlaintext();
52+
export function getMessage() {
53+
return $commitMessage;
4654
}
4755
</script>
4856

@@ -54,6 +62,9 @@
5462
{initialValue}
5563
{projectId}
5664
{stackId}
65+
onChange={(text: string) => {
66+
descriptionText = text;
67+
}}
5768
/>
5869
</div>
5970
<EditorFooter {onCancel}>

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import CommitMessageInput from '$components/v3/CommitMessageInput.svelte';
77
import Drawer from '$components/v3/Drawer.svelte';
88
import { FocusManager } from '$lib/focus/focusManager.svelte';
9+
import { showToast } from '$lib/notifications/toasts';
910
import { StackService } from '$lib/stacks/stackService.svelte';
1011
import { UiState } from '$lib/state/uiState.svelte';
1112
import { inject } from '@gitbutler/shared/context';
@@ -54,11 +55,11 @@
5455
throw new Error('No branch selected!');
5556
}
5657
if (!commitMessageInput) return;
57-
const title = commitMessageInput.getTitle();
58-
const message = await commitMessageInput.getPlaintext();
59-
if (!message && !title) return;
60-
61-
const commitMessage = [title, message].filter((a) => a).join('\n\n');
58+
const commitMessage = commitMessageInput.getMessage();
59+
if (!commitMessage) {
60+
showToast({ message: 'Commit message is required', style: 'error' });
61+
return;
62+
}
6263
6364
const newCommitId = await updateCommitMessage({
6465
projectId,

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script lang="ts">
22
import CommitMessageInput from '$components/v3/CommitMessageInput.svelte';
33
import Drawer from '$components/v3/Drawer.svelte';
4-
import { showError } from '$lib/notifications/toasts';
4+
import { persistedCommitMessage } from '$lib/config/config';
5+
import { showError, showToast } from '$lib/notifications/toasts';
56
import { ChangeSelectionService } from '$lib/selection/changeSelection.svelte';
67
import { IdSelection } from '$lib/selection/idSelection.svelte';
78
import { StackService } from '$lib/stacks/stackService.svelte';
@@ -25,6 +26,8 @@
2526
const changeSelection = getContext(ChangeSelectionService);
2627
const selection = $derived(changeSelection.list());
2728
const canCommit = $derived(branchName && selection.current.length > 0);
29+
const commitMessage = persistedCommitMessage(projectId, stackId);
30+
const [initialTitle, initialMessage] = $derived($commitMessage.split('\n\n'));
2831
2932
let input = $state<ReturnType<typeof CommitMessageInput>>();
3033
let drawer = $state<ReturnType<typeof Drawer>>();
@@ -61,16 +64,18 @@
6164
}
6265
6366
async function handleCommitCreation() {
64-
const titleText = await input?.getTitle();
65-
const message = await input?.getPlaintext();
66-
if (!titleText) return;
67-
68-
const commitMessage = [titleText, message].filter((a) => a).join('\n\n');
67+
const message = input?.getMessage();
68+
if (!message) {
69+
showToast({ message: 'Commit message is required', style: 'error' });
70+
return;
71+
}
6972
7073
try {
71-
await createCommit(commitMessage);
74+
await createCommit(message);
7275
} catch (err: unknown) {
7376
showError('Failed to commit', err);
77+
} finally {
78+
$commitMessage = '';
7479
}
7580
}
7681
@@ -89,5 +94,8 @@
8994
onCancel={cancel}
9095
disabledAction={!canCommit}
9196
loading={commitCreation.current.isLoading}
97+
{initialTitle}
98+
{initialMessage}
99+
isNewCommit
92100
/>
93101
</Drawer>

0 commit comments

Comments
 (0)