Skip to content

Commit 9aacb54

Browse files
Fixes failure to finish and commit when no workdir changes present
1 parent 242e331 commit 9aacb54

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

src/env/node/git/sub-providers/status.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
123123
@log()
124124
async hasWorkingChanges(
125125
repoPath: string,
126-
options?: { staged?: boolean; unstaged?: boolean; untracked?: boolean },
126+
options?: { staged?: boolean; unstaged?: boolean; untracked?: boolean; throwOnError?: boolean },
127127
cancellation?: CancellationToken,
128128
): Promise<boolean> {
129129
const scope = getLogScope();
@@ -169,6 +169,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
169169
// Log other errors and return false for graceful degradation
170170
Logger.error(ex, scope);
171171
setLogScopeExit(scope, ' \u2022 error checking for changes');
172+
if (options?.throwOnError) throw ex;
172173
return false;
173174
}
174175
}

src/git/gitProvider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ export interface GitStatusSubProvider {
762762
unstaged?: boolean;
763763
/** Check for untracked files (default: true) */
764764
untracked?: boolean;
765+
/** Throw errors rather than returning false */
766+
throwOnError?: boolean;
765767
},
766768
cancellation?: CancellationToken,
767769
): Promise<boolean>;

src/webviews/plus/composer/composerWebview.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,30 +1393,34 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
13931393

13941394
// Capture previous stash state
13951395
let previousStashCommit;
1396-
let stash = await svc.stash?.getStash();
1397-
if (stash?.stashes.size) {
1398-
const latestStash = stash.stashes.values().next().value;
1399-
if (latestStash) {
1400-
previousStashCommit = latestStash;
1401-
}
1402-
}
1403-
1404-
// Stash the working changes
1405-
const stashMessage = `Commit composer: ${new Date().toLocaleString()}`;
1406-
await svc.stash?.saveStash(stashMessage, undefined, { includeUntracked: true });
1407-
1408-
// Get the new stash reference
1409-
stash = await svc.stash?.getStash();
1396+
let stash;
14101397
let stashCommit;
14111398
let stashedSuccessfully = false;
1412-
if (stash?.stashes.size) {
1413-
stashCommit = stash.stashes.values().next().value;
1414-
if (
1415-
stashCommit &&
1416-
stashCommit.ref !== previousStashCommit?.ref &&
1417-
stashCommit.message?.includes(stashMessage)
1418-
) {
1419-
stashedSuccessfully = true;
1399+
const hasWorkingChanges = await repo.git.status.hasWorkingChanges({ throwOnError: true });
1400+
if (hasWorkingChanges) {
1401+
stash = await svc.stash?.getStash();
1402+
if (stash?.stashes.size) {
1403+
const latestStash = stash.stashes.values().next().value;
1404+
if (latestStash) {
1405+
previousStashCommit = latestStash;
1406+
}
1407+
}
1408+
1409+
// Stash the working changes
1410+
const stashMessage = `Commit composer: ${new Date().toLocaleString()}`;
1411+
await svc.stash?.saveStash(stashMessage, undefined, { includeUntracked: true });
1412+
1413+
// Get the new stash reference
1414+
stash = await svc.stash?.getStash();
1415+
if (stash?.stashes.size) {
1416+
stashCommit = stash.stashes.values().next().value;
1417+
if (
1418+
stashCommit &&
1419+
stashCommit.ref !== previousStashCommit?.ref &&
1420+
stashCommit.message?.includes(stashMessage)
1421+
) {
1422+
stashedSuccessfully = true;
1423+
}
14201424
}
14211425
}
14221426

0 commit comments

Comments
 (0)