Skip to content

Commit b208b87

Browse files
authored
Git - Optimistic UI plumbing (microsoft#165237)
1 parent 2423a7a commit b208b87

File tree

4 files changed

+137
-90
lines changed

4 files changed

+137
-90
lines changed

extensions/git/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,15 @@
25432543
"default": false,
25442544
"markdownDescription": "%config.mergeEditor%",
25452545
"scope": "window"
2546+
},
2547+
"git.optimisticUpdate": {
2548+
"type": "boolean",
2549+
"default": true,
2550+
"markdownDescription": "%config.optimisticUpdate%",
2551+
"scope": "resource",
2552+
"tags": [
2553+
"experimental"
2554+
]
25462555
}
25472556
}
25482557
},

extensions/git/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
"config.repositoryScanMaxDepth": "Controls the depth used when scanning workspace folders for Git repositories when `#git.autoRepositoryDetection#` is set to `true` or `subFolders`. Can be set to `-1` for no limit.",
237237
"config.useIntegratedAskPass": "Controls whether GIT_ASKPASS should be overwritten to use the integrated version.",
238238
"config.mergeEditor": "Open the merge editor for files that are currently under conflict.",
239+
"config.optimisticUpdate": "Controls whether to optimistically update the state of the Source Control view after running git commands.",
239240
"submenu.explorer": "Git",
240241
"submenu.commit": "Commit",
241242
"submenu.commit.amend": "Amend",

extensions/git/src/commands.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ export class CommandCenter {
15711571
repository: Repository,
15721572
getCommitMessage: () => Promise<string | undefined>,
15731573
opts: CommitOptions
1574-
): Promise<boolean> {
1574+
): Promise<void> {
15751575
const config = workspace.getConfiguration('git', Uri.file(repository.root));
15761576
let promptToSaveFilesBeforeCommit = config.get<'always' | 'staged' | 'never'>('promptToSaveFilesBeforeCommit');
15771577

@@ -1611,7 +1611,7 @@ export class CommandCenter {
16111611
noStagedChanges = repository.indexGroup.resourceStates.length === 0;
16121612
noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0;
16131613
} else if (pick !== commit) {
1614-
return false; // do not commit on cancel
1614+
return; // do not commit on cancel
16151615
}
16161616
}
16171617
}
@@ -1621,7 +1621,7 @@ export class CommandCenter {
16211621
const suggestSmartCommit = config.get<boolean>('suggestSmartCommit') === true;
16221622

16231623
if (!suggestSmartCommit) {
1624-
return false;
1624+
return;
16251625
}
16261626

16271627
// prompt the user if we want to commit all or not
@@ -1635,9 +1635,9 @@ export class CommandCenter {
16351635
config.update('enableSmartCommit', true, true);
16361636
} else if (pick === never) {
16371637
config.update('suggestSmartCommit', false, true);
1638-
return false;
1638+
return;
16391639
} else if (pick !== yes) {
1640-
return false; // do not commit on cancel
1640+
return; // do not commit on cancel
16411641
}
16421642
}
16431643

@@ -1683,7 +1683,7 @@ export class CommandCenter {
16831683
const answer = await window.showInformationMessage(l10n.t('There are no changes to commit.'), commitAnyway);
16841684

16851685
if (answer !== commitAnyway) {
1686-
return false;
1686+
return;
16871687
}
16881688

16891689
opts.empty = true;
@@ -1692,7 +1692,7 @@ export class CommandCenter {
16921692
if (opts.noVerify) {
16931693
if (!config.get<boolean>('allowNoVerifyCommit')) {
16941694
await window.showErrorMessage(l10n.t('Commits without verification are not allowed, please enable them with the "git.allowNoVerifyCommit" setting.'));
1695-
return false;
1695+
return;
16961696
}
16971697

16981698
if (config.get<boolean>('confirmNoVerifyCommit')) {
@@ -1704,15 +1704,15 @@ export class CommandCenter {
17041704
if (pick === neverAgain) {
17051705
config.update('confirmNoVerifyCommit', false, true);
17061706
} else if (pick !== yes) {
1707-
return false;
1707+
return;
17081708
}
17091709
}
17101710
}
17111711

17121712
const message = await getCommitMessage();
17131713

17141714
if (!message && !opts.amend && !opts.useEditor) {
1715-
return false;
1715+
return;
17161716
}
17171717

17181718
if (opts.all && smartCommitChanges === 'tracked') {
@@ -1738,21 +1738,19 @@ export class CommandCenter {
17381738
}
17391739

17401740
if (!pick) {
1741-
return false;
1741+
return;
17421742
} else if (pick === commitToNewBranch) {
17431743
const branchName = await this.promptForBranchName(repository);
17441744

17451745
if (!branchName) {
1746-
return false;
1746+
return;
17471747
}
17481748

17491749
await repository.branch(branchName, true);
17501750
}
17511751
}
17521752

17531753
await repository.commit(message, opts);
1754-
1755-
return true;
17561754
}
17571755

17581756
private async commitWithAnyInput(repository: Repository, opts: CommitOptions): Promise<void> {
@@ -1790,11 +1788,7 @@ export class CommandCenter {
17901788
return _message;
17911789
};
17921790

1793-
const didCommit = await this.smartCommit(repository, getCommitMessage, opts);
1794-
1795-
if (message && didCommit) {
1796-
repository.inputBox.value = await repository.getInputTemplate();
1797-
}
1791+
await this.smartCommit(repository, getCommitMessage, opts);
17981792
}
17991793

18001794
@command('git.commit', { repository: true })

0 commit comments

Comments
 (0)