Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git - Optimistic UI plumbing + commit action #165237

Merged
merged 10 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1570,7 +1570,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 @@ -1610,7 +1610,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 @@ -1620,7 +1620,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 @@ -1634,9 +1634,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 @@ -1682,7 +1682,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 @@ -1691,7 +1691,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 @@ -1703,15 +1703,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 @@ -1737,21 +1737,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 @@ -1789,11 +1787,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