mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Git - Add support for git stash --staged (#169539)
Add support for git stash --staged
This commit is contained in:
parent
cfd3aad843
commit
2c8b54bbbf
|
@ -577,6 +577,12 @@
|
|||
"category": "Git",
|
||||
"enablement": "!operationInProgress"
|
||||
},
|
||||
{
|
||||
"command": "git.stashStaged",
|
||||
"title": "%command.stashStaged%",
|
||||
"category": "Git",
|
||||
"enablement": "!operationInProgress && gitVersion2.35"
|
||||
},
|
||||
{
|
||||
"command": "git.stashPop",
|
||||
"title": "%command.stashPop%",
|
||||
|
@ -1056,6 +1062,10 @@
|
|||
"command": "git.stash",
|
||||
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
|
||||
},
|
||||
{
|
||||
"command": "git.stashStaged",
|
||||
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && gitVersion2.35"
|
||||
},
|
||||
{
|
||||
"command": "git.stashPop",
|
||||
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
|
||||
|
@ -1882,28 +1892,33 @@
|
|||
"group": "stash@2"
|
||||
},
|
||||
{
|
||||
"command": "git.stashApplyLatest",
|
||||
"command": "git.stashStaged",
|
||||
"when": "gitVersion2.35",
|
||||
"group": "stash@3"
|
||||
},
|
||||
{
|
||||
"command": "git.stashApply",
|
||||
"command": "git.stashApplyLatest",
|
||||
"group": "stash@4"
|
||||
},
|
||||
{
|
||||
"command": "git.stashPopLatest",
|
||||
"command": "git.stashApply",
|
||||
"group": "stash@5"
|
||||
},
|
||||
{
|
||||
"command": "git.stashPop",
|
||||
"command": "git.stashPopLatest",
|
||||
"group": "stash@6"
|
||||
},
|
||||
{
|
||||
"command": "git.stashDrop",
|
||||
"command": "git.stashPop",
|
||||
"group": "stash@7"
|
||||
},
|
||||
{
|
||||
"command": "git.stashDropAll",
|
||||
"command": "git.stashDrop",
|
||||
"group": "stash@8"
|
||||
},
|
||||
{
|
||||
"command": "git.stashDropAll",
|
||||
"group": "stash@9"
|
||||
}
|
||||
],
|
||||
"git.tags": [
|
||||
|
|
|
@ -88,6 +88,7 @@
|
|||
"command.rebaseAbort": "Abort Rebase",
|
||||
"command.stashIncludeUntracked": "Stash (Include Untracked)",
|
||||
"command.stash": "Stash",
|
||||
"command.stashStaged": "Stash (Staged)",
|
||||
"command.stashPop": "Pop Stash...",
|
||||
"command.stashPopLatest": "Pop Latest Stash",
|
||||
"command.stashApply": "Apply Stash...",
|
||||
|
|
|
@ -2907,14 +2907,21 @@ export class CommandCenter {
|
|||
await commands.executeCommand('revealFileInOS', resourceState.resourceUri);
|
||||
}
|
||||
|
||||
private async _stash(repository: Repository, includeUntracked = false): Promise<void> {
|
||||
private async _stash(repository: Repository, includeUntracked = false, staged = false): Promise<void> {
|
||||
const noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0
|
||||
&& (!includeUntracked || repository.untrackedGroup.resourceStates.length === 0);
|
||||
const noStagedChanges = repository.indexGroup.resourceStates.length === 0;
|
||||
|
||||
if (noUnstagedChanges && noStagedChanges) {
|
||||
window.showInformationMessage(l10n.t('There are no changes to stash.'));
|
||||
return;
|
||||
if (staged) {
|
||||
if (noStagedChanges) {
|
||||
window.showInformationMessage(l10n.t('There are no staged changes to stash.'));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (noUnstagedChanges && noStagedChanges) {
|
||||
window.showInformationMessage(l10n.t('There are no changes to stash.'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const config = workspace.getConfiguration('git', Uri.file(repository.root));
|
||||
|
@ -2962,7 +2969,7 @@ export class CommandCenter {
|
|||
}
|
||||
|
||||
try {
|
||||
await repository.createStash(message, includeUntracked);
|
||||
await repository.createStash(message, includeUntracked, staged);
|
||||
} catch (err) {
|
||||
if (/You do not have the initial commit yet/.test(err.stderr || '')) {
|
||||
window.showInformationMessage(l10n.t('The repository does not have any commits. Please make an initial commit before creating a stash.'));
|
||||
|
@ -2978,6 +2985,11 @@ export class CommandCenter {
|
|||
return this._stash(repository);
|
||||
}
|
||||
|
||||
@command('git.stashStaged', { repository: true })
|
||||
stashStaged(repository: Repository): Promise<void> {
|
||||
return this._stash(repository, false, true);
|
||||
}
|
||||
|
||||
@command('git.stashIncludeUntracked', { repository: true })
|
||||
stashIncludeUntracked(repository: Repository): Promise<void> {
|
||||
return this._stash(repository, true);
|
||||
|
|
|
@ -1910,7 +1910,7 @@ export class Repository {
|
|||
}
|
||||
}
|
||||
|
||||
async createStash(message?: string, includeUntracked?: boolean): Promise<void> {
|
||||
async createStash(message?: string, includeUntracked?: boolean, staged?: boolean): Promise<void> {
|
||||
try {
|
||||
const args = ['stash', 'push'];
|
||||
|
||||
|
@ -1918,6 +1918,10 @@ export class Repository {
|
|||
args.push('-u');
|
||||
}
|
||||
|
||||
if (staged) {
|
||||
args.push('-S');
|
||||
}
|
||||
|
||||
if (message) {
|
||||
args.push('-m', message);
|
||||
}
|
||||
|
|
|
@ -119,6 +119,7 @@ async function createModel(context: ExtensionContext, logger: LogOutputChannel,
|
|||
model.registerPostCommitCommandsProvider(postCommitCommandsProvider);
|
||||
|
||||
checkGitVersion(info);
|
||||
commands.executeCommand('setContext', 'gitVersion2.35', git.compareGitVersionTo('2.35') >= 0);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -1907,14 +1907,14 @@ export class Repository implements Disposable {
|
|||
return await this.repository.getStashes();
|
||||
}
|
||||
|
||||
async createStash(message?: string, includeUntracked?: boolean): Promise<void> {
|
||||
async createStash(message?: string, includeUntracked?: boolean, staged?: boolean): Promise<void> {
|
||||
const indexResources = [...this.indexGroup.resourceStates.map(r => r.resourceUri.fsPath)];
|
||||
const workingGroupResources = [
|
||||
...this.workingTreeGroup.resourceStates.map(r => r.resourceUri.fsPath),
|
||||
...!staged ? this.workingTreeGroup.resourceStates.map(r => r.resourceUri.fsPath) : [],
|
||||
...includeUntracked ? this.untrackedGroup.resourceStates.map(r => r.resourceUri.fsPath) : []];
|
||||
|
||||
return await this.run(OperationKind.Stash, async () => {
|
||||
await this.repository.createStash(message, includeUntracked);
|
||||
await this.repository.createStash(message, includeUntracked, staged);
|
||||
this.closeDiffEditors(indexResources, workingGroupResources);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue