Skip to content

Commit

Permalink
Git - Optimistic UI plumbing (#165237)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru committed Nov 4, 2022
1 parent 2423a7a commit b208b87
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 90 deletions.
9 changes: 9 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,15 @@
"default": false,
"markdownDescription": "%config.mergeEditor%",
"scope": "window"
},
"git.optimisticUpdate": {
"type": "boolean",
"default": true,
"markdownDescription": "%config.optimisticUpdate%",
"scope": "resource",
"tags": [
"experimental"
]
}
}
},
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
"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.",
"config.useIntegratedAskPass": "Controls whether GIT_ASKPASS should be overwritten to use the integrated version.",
"config.mergeEditor": "Open the merge editor for files that are currently under conflict.",
"config.optimisticUpdate": "Controls whether to optimistically update the state of the Source Control view after running git commands.",
"submenu.explorer": "Git",
"submenu.commit": "Commit",
"submenu.commit.amend": "Amend",
Expand Down
30 changes: 12 additions & 18 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ export class CommandCenter {
repository: Repository,
getCommitMessage: () => Promise<string | undefined>,
opts: CommitOptions
): Promise<boolean> {
): Promise<void> {
const config = workspace.getConfiguration('git', Uri.file(repository.root));
let promptToSaveFilesBeforeCommit = config.get<'always' | 'staged' | 'never'>('promptToSaveFilesBeforeCommit');

Expand Down Expand Up @@ -1611,7 +1611,7 @@ export class CommandCenter {
noStagedChanges = repository.indexGroup.resourceStates.length === 0;
noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0;
} else if (pick !== commit) {
return false; // do not commit on cancel
return; // do not commit on cancel
}
}
}
Expand All @@ -1621,7 +1621,7 @@ export class CommandCenter {
const suggestSmartCommit = config.get<boolean>('suggestSmartCommit') === true;

if (!suggestSmartCommit) {
return false;
return;
}

// prompt the user if we want to commit all or not
Expand All @@ -1635,9 +1635,9 @@ export class CommandCenter {
config.update('enableSmartCommit', true, true);
} else if (pick === never) {
config.update('suggestSmartCommit', false, true);
return false;
return;
} else if (pick !== yes) {
return false; // do not commit on cancel
return; // do not commit on cancel
}
}

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

if (answer !== commitAnyway) {
return false;
return;
}

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

if (config.get<boolean>('confirmNoVerifyCommit')) {
Expand All @@ -1704,15 +1704,15 @@ export class CommandCenter {
if (pick === neverAgain) {
config.update('confirmNoVerifyCommit', false, true);
} else if (pick !== yes) {
return false;
return;
}
}
}

const message = await getCommitMessage();

if (!message && !opts.amend && !opts.useEditor) {
return false;
return;
}

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

if (!pick) {
return false;
return;
} else if (pick === commitToNewBranch) {
const branchName = await this.promptForBranchName(repository);

if (!branchName) {
return false;
return;
}

await repository.branch(branchName, true);
}
}

await repository.commit(message, opts);

return true;
}

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

const didCommit = await this.smartCommit(repository, getCommitMessage, opts);

if (message && didCommit) {
repository.inputBox.value = await repository.getInputTemplate();
}
await this.smartCommit(repository, getCommitMessage, opts);
}

@command('git.commit', { repository: true })
Expand Down
Loading

0 comments on commit b208b87

Please sign in to comment.