Skip to content

Commit 052ed71

Browse files
Fixes failure to finish and commit when no workdir changes present
1 parent f3c1604 commit 052ed71

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
@@ -618,7 +618,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
618618
@log()
619619
async hasWorkingChanges(
620620
repoPath: string,
621-
options?: { staged?: boolean; unstaged?: boolean; untracked?: boolean },
621+
options?: { staged?: boolean; unstaged?: boolean; untracked?: boolean; throwOnError?: boolean },
622622
cancellation?: CancellationToken,
623623
): Promise<boolean> {
624624
const scope = getLogScope();
@@ -664,6 +664,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
664664
// Log other errors and return false for graceful degradation
665665
Logger.error(ex, scope);
666666
setLogScopeExit(scope, ' \u2022 error checking for changes');
667+
if (options?.throwOnError) throw ex;
667668
return false;
668669
}
669670
}

src/git/gitProvider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ export interface GitStatusSubProvider {
751751
unstaged?: boolean;
752752
/** Check for untracked files (default: true) */
753753
untracked?: boolean;
754+
/** Throw errors rather than returning false */
755+
throwOnError?: boolean;
754756
},
755757
cancellation?: CancellationToken,
756758
): 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)