Merge branch 'master' into pr/107958

This commit is contained in:
João Moreno
2020-11-10 11:59:25 +01:00
1255 changed files with 47690 additions and 33323 deletions

View File

@@ -6,7 +6,7 @@
import { lstat, Stats } from 'fs';
import * as os from 'os';
import * as path from 'path';
import { commands, Disposable, LineChange, MessageOptions, OutputChannel, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection } from 'vscode';
import { commands, Disposable, LineChange, MessageOptions, OutputChannel, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider } from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import * as nls from 'vscode-nls';
import { Branch, GitErrorCodes, Ref, RefType, Status, CommitOptions, RemoteSourceProvider } from './api/git';
@@ -31,14 +31,14 @@ class CheckoutItem implements QuickPickItem {
constructor(protected ref: Ref) { }
async run(repository: Repository): Promise<void> {
async run(repository: Repository, opts?: { detached?: boolean }): Promise<void> {
const ref = this.ref.name;
if (!ref) {
return;
}
await repository.checkout(ref);
await repository.checkout(ref, opts);
}
}
@@ -99,32 +99,36 @@ class MergeItem implements QuickPickItem {
}
}
class CreateBranchItem implements QuickPickItem {
class RebaseItem implements QuickPickItem {
constructor(private cc: CommandCenter) { }
get label(): string { return this.ref.name || ''; }
description: string = '';
get label(): string { return '$(plus) ' + localize('create branch', 'Create new branch...'); }
get description(): string { return ''; }
get alwaysShow(): boolean { return true; }
constructor(readonly ref: Ref) { }
async run(repository: Repository): Promise<void> {
await this.cc.branch(repository);
if (this.ref?.name) {
await repository.rebase(this.ref.name);
}
}
}
class CreateBranchItem implements QuickPickItem {
get label(): string { return '$(plus) ' + localize('create branch', 'Create new branch...'); }
get description(): string { return ''; }
get alwaysShow(): boolean { return true; }
}
class CreateBranchFromItem implements QuickPickItem {
constructor(private cc: CommandCenter) { }
get label(): string { return '$(plus) ' + localize('create branch from', 'Create new branch from...'); }
get description(): string { return ''; }
get alwaysShow(): boolean { return true; }
}
async run(repository: Repository): Promise<void> {
await this.cc.branch(repository);
}
class CheckoutDetachedItem implements QuickPickItem {
get label(): string { return '$(debug-disconnect) ' + localize('checkout detached', 'Checkout detached...'); }
get description(): string { return ''; }
get alwaysShow(): boolean { return true; }
}
class HEADItem implements QuickPickItem {
@@ -203,18 +207,53 @@ async function categorizeResourceByResolution(resources: Resource[]): Promise<{
function createCheckoutItems(repository: Repository): CheckoutItem[] {
const config = workspace.getConfiguration('git');
const checkoutType = config.get<string>('checkoutType') || 'all';
const includeTags = checkoutType === 'all' || checkoutType === 'tags';
const includeRemotes = checkoutType === 'all' || checkoutType === 'remote';
const checkoutTypeConfig = config.get<string | string[]>('checkoutType');
let checkoutTypes: string[];
const heads = repository.refs.filter(ref => ref.type === RefType.Head)
.map(ref => new CheckoutItem(ref));
const tags = (includeTags ? repository.refs.filter(ref => ref.type === RefType.Tag) : [])
.map(ref => new CheckoutTagItem(ref));
const remoteHeads = (includeRemotes ? repository.refs.filter(ref => ref.type === RefType.RemoteHead) : [])
.map(ref => new CheckoutRemoteHeadItem(ref));
if (checkoutTypeConfig === 'all' || !checkoutTypeConfig || checkoutTypeConfig.length === 0) {
checkoutTypes = ['local', 'remote', 'tags'];
} else if (typeof checkoutTypeConfig === 'string') {
checkoutTypes = [checkoutTypeConfig];
} else {
checkoutTypes = checkoutTypeConfig;
}
return [...heads, ...tags, ...remoteHeads];
const processors = checkoutTypes.map(getCheckoutProcessor)
.filter(p => !!p) as CheckoutProcessor[];
for (const ref of repository.refs) {
for (const processor of processors) {
processor.onRef(ref);
}
}
return processors.reduce<CheckoutItem[]>((r, p) => r.concat(...p.items), []);
}
class CheckoutProcessor {
private refs: Ref[] = [];
get items(): CheckoutItem[] { return this.refs.map(r => new this.ctor(r)); }
constructor(private type: RefType, private ctor: { new(ref: Ref): CheckoutItem }) { }
onRef(ref: Ref): void {
if (ref.type === this.type) {
this.refs.push(ref);
}
}
}
function getCheckoutProcessor(type: string): CheckoutProcessor | undefined {
switch (type) {
case 'local':
return new CheckoutProcessor(RefType.Head, CheckoutItem);
case 'remote':
return new CheckoutProcessor(RefType.RemoteHead, CheckoutRemoteHeadItem);
case 'tags':
return new CheckoutProcessor(RefType.Tag, CheckoutTagItem);
}
return undefined;
}
function sanitizeRemoteName(name: string) {
@@ -232,6 +271,7 @@ enum PushType {
Push,
PushTo,
PushFollowTags,
PushTags
}
interface PushOptions {
@@ -240,9 +280,27 @@ interface PushOptions {
silent?: boolean;
}
class CommandErrorOutputTextDocumentContentProvider implements TextDocumentContentProvider {
private items = new Map<string, string>();
set(uri: Uri, contents: string): void {
this.items.set(uri.path, contents);
}
delete(uri: Uri): void {
this.items.delete(uri.path);
}
provideTextDocumentContent(uri: Uri): string | undefined {
return this.items.get(uri.path);
}
}
export class CommandCenter {
private disposables: Disposable[];
private commandErrors = new CommandErrorOutputTextDocumentContentProvider();
constructor(
private git: Git,
@@ -259,6 +317,8 @@ export class CommandCenter {
return commands.registerCommand(commandId, command);
}
});
this.disposables.push(workspace.registerTextDocumentContentProvider('git-output', this.commandErrors));
}
@command('git.setLogLevel')
@@ -333,7 +393,9 @@ export class CommandCenter {
right = toGitUri(resource.resourceUri, resource.resourceGroupType === ResourceGroupType.Index ? 'index' : 'wt', { submoduleOf: repository.root });
}
} else {
if (resource.type !== Status.DELETED_BY_THEM) {
if (resource.type === Status.DELETED_BY_US || resource.type === Status.DELETED_BY_THEM) {
left = toGitUri(resource.resourceUri, '~1');
} else {
left = this.getLeftResource(resource);
}
@@ -363,7 +425,7 @@ export class CommandCenter {
}
if (!left) {
await commands.executeCommand<void>('vscode.open', right, opts, title);
await commands.executeCommand<void>('vscode.open', right, { ...opts, override: resource.type === Status.BOTH_MODIFIED ? false : undefined }, title);
} else {
await commands.executeCommand<void>('vscode.diff', left, right, title, opts);
}
@@ -458,8 +520,7 @@ export class CommandCenter {
}
}
@command('git.clone')
async clone(url?: string, parentPath?: string): Promise<void> {
async cloneRepository(url?: string, parentPath?: string, options: { recursive?: boolean } = {}): Promise<void> {
if (!url || typeof url !== 'string') {
url = await pickRemoteSource(this.model, {
providerLabel: provider => localize('clonefrom', "Clone from {0}", provider.name),
@@ -515,38 +576,57 @@ export class CommandCenter {
const repositoryPath = await window.withProgress(
opts,
(progress, token) => this.git.clone(url!, parentPath!, progress, token)
(progress, token) => this.git.clone(url!, { parentPath: parentPath!, progress, recursive: options.recursive }, token)
);
let message = localize('proposeopen', "Would you like to open the cloned repository?");
const open = localize('openrepo', "Open");
const openNewWindow = localize('openreponew', "Open in New Window");
const choices = [open, openNewWindow];
const config = workspace.getConfiguration('git');
const openAfterClone = config.get<'always' | 'alwaysNewWindow' | 'whenNoFolderOpen' | 'prompt'>('openAfterClone');
const addToWorkspace = localize('add', "Add to Workspace");
if (workspace.workspaceFolders) {
message = localize('proposeopen2', "Would you like to open the cloned repository, or add it to the current workspace?");
choices.push(addToWorkspace);
enum PostCloneAction { Open, OpenNewWindow, AddToWorkspace }
let action: PostCloneAction | undefined = undefined;
if (openAfterClone === 'always') {
action = PostCloneAction.Open;
} else if (openAfterClone === 'alwaysNewWindow') {
action = PostCloneAction.OpenNewWindow;
} else if (openAfterClone === 'whenNoFolderOpen' && !workspace.workspaceFolders) {
action = PostCloneAction.Open;
}
const result = await window.showInformationMessage(message, ...choices);
if (action === undefined) {
let message = localize('proposeopen', "Would you like to open the cloned repository?");
const open = localize('openrepo', "Open");
const openNewWindow = localize('openreponew', "Open in New Window");
const choices = [open, openNewWindow];
const addToWorkspace = localize('add', "Add to Workspace");
if (workspace.workspaceFolders) {
message = localize('proposeopen2', "Would you like to open the cloned repository, or add it to the current workspace?");
choices.push(addToWorkspace);
}
const result = await window.showInformationMessage(message, ...choices);
action = result === open ? PostCloneAction.Open
: result === openNewWindow ? PostCloneAction.OpenNewWindow
: result === addToWorkspace ? PostCloneAction.AddToWorkspace : undefined;
}
const openFolder = result === open;
/* __GDPR__
"clone" : {
"outcome" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"openFolder": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true }
}
*/
this.telemetryReporter.sendTelemetryEvent('clone', { outcome: 'success' }, { openFolder: openFolder ? 1 : 0 });
this.telemetryReporter.sendTelemetryEvent('clone', { outcome: 'success' }, { openFolder: action === PostCloneAction.Open || action === PostCloneAction.OpenNewWindow ? 1 : 0 });
const uri = Uri.file(repositoryPath);
if (openFolder) {
if (action === PostCloneAction.Open) {
commands.executeCommand('vscode.openFolder', uri, { forceReuseWindow: true });
} else if (result === addToWorkspace) {
} else if (action === PostCloneAction.AddToWorkspace) {
workspace.updateWorkspaceFolders(workspace.workspaceFolders!.length, 0, { uri });
} else if (result === openNewWindow) {
} else if (action === PostCloneAction.OpenNewWindow) {
commands.executeCommand('vscode.openFolder', uri, { forceNewWindow: true });
}
} catch (err) {
@@ -572,6 +652,16 @@ export class CommandCenter {
}
}
@command('git.clone')
async clone(url?: string, parentPath?: string): Promise<void> {
this.cloneRepository(url, parentPath);
}
@command('git.cloneRecursive')
async cloneRecursive(url?: string, parentPath?: string): Promise<void> {
this.cloneRepository(url, parentPath, { recursive: true });
}
@command('git.init')
async init(skipFolderPrompt = false): Promise<void> {
let repositoryPath: string | undefined = undefined;
@@ -738,7 +828,10 @@ export class CommandCenter {
try {
document = await workspace.openTextDocument(uri);
} catch (error) {
await commands.executeCommand('vscode.open', uri, opts);
await commands.executeCommand('vscode.open', uri, {
...opts,
override: arg instanceof Resource && arg.type === Status.BOTH_MODIFIED ? false : undefined
});
continue;
}
@@ -830,6 +923,27 @@ export class CommandCenter {
}
}
@command('git.rename', { repository: true })
async rename(repository: Repository, fromUri: Uri): Promise<void> {
if (!fromUri) {
return;
}
const from = path.relative(repository.root, fromUri.path);
let to = await window.showInputBox({
value: from,
valueSelection: [from.length - path.basename(from).length, from.length]
});
to = to?.trim();
if (!to) {
return;
}
await repository.move(from, to);
}
@command('git.stage')
async stage(...resourceStates: SourceControlResourceState[]): Promise<void> {
this.outputChannel.appendLine(`git.stage ${resourceStates.length}`);
@@ -1198,7 +1312,7 @@ export class CommandCenter {
if (scmResources.length === 1) {
if (untrackedCount > 0) {
message = localize('confirm delete', "Are you sure you want to DELETE {0}?\nThis is IRREVERSIBLE!\nThis file will be FOREVER LOST.", path.basename(scmResources[0].resourceUri.fsPath));
message = localize('confirm delete', "Are you sure you want to DELETE {0}?\nThis is IRREVERSIBLE!\nThis file will be FOREVER LOST if you proceed.", path.basename(scmResources[0].resourceUri.fsPath));
yes = localize('delete file', "Delete file");
} else {
if (scmResources[0].type === Status.DELETED) {
@@ -1303,7 +1417,7 @@ export class CommandCenter {
private async _cleanTrackedChanges(repository: Repository, resources: Resource[]): Promise<void> {
const message = resources.length === 1
? localize('confirm discard all single', "Are you sure you want to discard changes in {0}?", path.basename(resources[0].resourceUri.fsPath))
: localize('confirm discard all', "Are you sure you want to discard ALL changes in {0} files?\nThis is IRREVERSIBLE!\nYour current working set will be FOREVER LOST.", resources.length);
: localize('confirm discard all', "Are you sure you want to discard ALL changes in {0} files?\nThis is IRREVERSIBLE!\nYour current working set will be FOREVER LOST if you proceed.", resources.length);
const yes = resources.length === 1
? localize('discardAll multiple', "Discard 1 File")
: localize('discardAll', "Discard All {0} Files", resources.length);
@@ -1317,7 +1431,7 @@ export class CommandCenter {
}
private async _cleanUntrackedChange(repository: Repository, resource: Resource): Promise<void> {
const message = localize('confirm delete', "Are you sure you want to DELETE {0}?\nThis is IRREVERSIBLE!\nThis file will be FOREVER LOST.", path.basename(resource.resourceUri.fsPath));
const message = localize('confirm delete', "Are you sure you want to DELETE {0}?\nThis is IRREVERSIBLE!\nThis file will be FOREVER LOST if you proceed.", path.basename(resource.resourceUri.fsPath));
const yes = localize('delete file', "Delete file");
const pick = await window.showWarningMessage(message, { modal: true }, yes);
@@ -1329,7 +1443,7 @@ export class CommandCenter {
}
private async _cleanUntrackedChanges(repository: Repository, resources: Resource[]): Promise<void> {
const message = localize('confirm delete multiple', "Are you sure you want to DELETE {0} files?", resources.length);
const message = localize('confirm delete multiple', "Are you sure you want to DELETE {0} files?\nThis is IRREVERSIBLE!\nThese files will be FOREVER LOST if you proceed.", resources.length);
const yes = localize('delete files', "Delete Files");
const pick = await window.showWarningMessage(message, { modal: true }, yes);
@@ -1374,7 +1488,7 @@ export class CommandCenter {
? localize('unsaved files single', "The following file has unsaved changes which won't be included in the commit if you proceed: {0}.\n\nWould you like to save it before committing?", path.basename(documents[0].uri.fsPath))
: localize('unsaved files', "There are {0} unsaved files.\n\nWould you like to save them before committing?", documents.length);
const saveAndCommit = localize('save and commit', "Save All & Commit");
const commit = localize('commit', "Commit Anyway");
const commit = localize('commit', "Commit Staged Changes");
const pick = await window.showWarningMessage(message, { modal: true }, saveAndCommit, commit);
if (pick === saveAndCommit) {
@@ -1401,7 +1515,7 @@ export class CommandCenter {
}
// prompt the user if we want to commit all or not
const message = localize('no staged changes', "There are no staged changes to commit.\n\nWould you like to automatically stage all your changes and commit them directly?");
const message = localize('no staged changes', "There are no staged changes to commit.\n\nWould you like to stage all your changes and commit them directly?");
const yes = localize('yes', "Yes");
const always = localize('always', "Always");
const never = localize('never', "Never");
@@ -1435,10 +1549,18 @@ export class CommandCenter {
// no staged changes and no tracked unstaged changes
|| (noStagedChanges && smartCommitChanges === 'tracked' && repository.workingTreeGroup.resourceStates.every(r => r.type === Status.UNTRACKED))
)
// amend allows changing only the commit message
&& !opts.amend
&& !opts.empty
) {
window.showInformationMessage(localize('no changes', "There are no changes to commit."));
return false;
const commitAnyway = localize('commit anyway', "Create Empty Commit");
const answer = await window.showInformationMessage(localize('no changes', "There are no changes to commit."), commitAnyway);
if (answer !== commitAnyway) {
return false;
}
opts.empty = true;
}
if (opts.noVerify) {
@@ -1667,20 +1789,38 @@ export class CommandCenter {
}
@command('git.checkout', { repository: true })
async checkout(repository: Repository, treeish: string): Promise<boolean> {
if (typeof treeish === 'string') {
await repository.checkout(treeish);
async checkout(repository: Repository, treeish?: string): Promise<boolean> {
return this._checkout(repository, { treeish });
}
@command('git.checkoutDetached', { repository: true })
async checkoutDetached(repository: Repository, treeish?: string): Promise<boolean> {
return this._checkout(repository, { detached: true, treeish });
}
private async _checkout(repository: Repository, opts?: { detached?: boolean, treeish?: string }): Promise<boolean> {
if (typeof opts?.treeish === 'string') {
await repository.checkout(opts?.treeish, opts);
return true;
}
const createBranch = new CreateBranchItem(this);
const createBranchFrom = new CreateBranchFromItem(this);
const picks = [createBranch, createBranchFrom, ...createCheckoutItems(repository)];
const placeHolder = localize('select a ref to checkout', 'Select a ref to checkout');
const createBranch = new CreateBranchItem();
const createBranchFrom = new CreateBranchFromItem();
const checkoutDetached = new CheckoutDetachedItem();
const picks: QuickPickItem[] = [];
if (!opts?.detached) {
picks.push(createBranch, createBranchFrom, checkoutDetached);
}
picks.push(...createCheckoutItems(repository));
const quickpick = window.createQuickPick();
quickpick.items = picks;
quickpick.placeholder = placeHolder;
quickpick.placeholder = opts?.detached
? localize('select a ref to checkout detached', 'Select a ref to checkout in detached mode')
: localize('select a ref to checkout', 'Select a ref to checkout');
quickpick.show();
const choice = await new Promise<QuickPickItem | undefined>(c => quickpick.onDidAccept(() => c(quickpick.activeItems[0])));
@@ -1694,8 +1834,31 @@ export class CommandCenter {
await this._branch(repository, quickpick.value);
} else if (choice === createBranchFrom) {
await this._branch(repository, quickpick.value, true);
} else if (choice === checkoutDetached) {
return this._checkout(repository, { detached: true });
} else {
await (choice as CheckoutItem).run(repository);
const item = choice as CheckoutItem;
try {
await item.run(repository, opts);
} catch (err) {
if (err.gitErrorCode !== GitErrorCodes.DirtyWorkTree) {
throw err;
}
const force = localize('force', "Force Checkout");
const stash = localize('stashcheckout', "Stash & Checkout");
const choice = await window.showWarningMessage(localize('local changes', "Your local changes would be overwritten by checkout."), { modal: true }, force, stash);
if (choice === force) {
await this.cleanAll(repository);
await item.run(repository, opts);
} else if (choice === stash) {
await this.stash(repository);
await item.run(repository, opts);
await this.stashPopLatest(repository);
}
}
}
return true;
@@ -1848,6 +2011,44 @@ export class CommandCenter {
await choice.run(repository);
}
@command('git.rebase', { repository: true })
async rebase(repository: Repository): Promise<void> {
const config = workspace.getConfiguration('git');
const checkoutType = config.get<string>('checkoutType') || 'all';
const includeRemotes = checkoutType === 'all' || checkoutType === 'remote';
const heads = repository.refs.filter(ref => ref.type === RefType.Head)
.filter(ref => ref.name !== repository.HEAD?.name)
.filter(ref => ref.name || ref.commit);
const remoteHeads = (includeRemotes ? repository.refs.filter(ref => ref.type === RefType.RemoteHead) : [])
.filter(ref => ref.name || ref.commit);
const picks = [...heads, ...remoteHeads]
.map(ref => new RebaseItem(ref));
// set upstream branch as first
if (repository.HEAD?.upstream) {
const upstreamName = `${repository.HEAD?.upstream.remote}/${repository.HEAD?.upstream.name}`;
const index = picks.findIndex(e => e.ref.name === upstreamName);
if (index > -1) {
const [ref] = picks.splice(index, 1);
ref.description = '(upstream)';
picks.unshift(ref);
}
}
const placeHolder = localize('select a branch to rebase onto', 'Select a branch to rebase onto');
const choice = await window.showQuickPick<RebaseItem>(picks, { placeHolder });
if (!choice) {
return;
}
await choice.run(repository);
}
@command('git.createTag', { repository: true })
async createTag(repository: Repository): Promise<void> {
const inputTagName = await window.showInputBox({
@@ -2025,6 +2226,10 @@ export class CommandCenter {
return;
}
if (pushOptions.pushType === PushType.PushTags) {
await repository.pushTags(undefined, forcePushMode);
}
if (!repository.HEAD || !repository.HEAD.name) {
if (!pushOptions.silent) {
window.showWarningMessage(localize('nobranch', "Please check out a branch to push to a remote."));
@@ -2096,6 +2301,21 @@ export class CommandCenter {
await this._push(repository, { pushType: PushType.PushFollowTags, forcePush: true });
}
@command('git.cherryPick', { repository: true })
async cherryPick(repository: Repository): Promise<void> {
const hash = await window.showInputBox({
placeHolder: localize('commit hash', "Commit Hash"),
prompt: localize('provide commit hash', "Please provide the commit hash"),
ignoreFocusOut: true
});
if (!hash) {
return;
}
await repository.cherryPick(hash);
}
@command('git.pushTo', { repository: true })
async pushTo(repository: Repository): Promise<void> {
await this._push(repository, { pushType: PushType.PushTo });
@@ -2106,6 +2326,11 @@ export class CommandCenter {
await this._push(repository, { pushType: PushType.PushTo, forcePush: true });
}
@command('git.pushTags', { repository: true })
async pushTags(repository: Repository): Promise<void> {
await this._push(repository, { pushType: PushType.PushTags });
}
@command('git.addRemote', { repository: true })
async addRemote(repository: Repository): Promise<string | undefined> {
const url = await pickRemoteSource(this.model, {
@@ -2139,6 +2364,7 @@ export class CommandCenter {
}
await repository.addRemote(name, url);
await repository.fetch(name);
return name;
}
@@ -2352,7 +2578,45 @@ export class CommandCenter {
return;
}
const message = await this.getStashMessage();
const config = workspace.getConfiguration('git', Uri.file(repository.root));
const promptToSaveFilesBeforeStashing = config.get<'always' | 'staged' | 'never'>('promptToSaveFilesBeforeStash');
if (promptToSaveFilesBeforeStashing !== 'never') {
let documents = workspace.textDocuments
.filter(d => !d.isUntitled && d.isDirty && isDescendant(repository.root, d.uri.fsPath));
if (promptToSaveFilesBeforeStashing === 'staged' || repository.indexGroup.resourceStates.length > 0) {
documents = documents
.filter(d => repository.indexGroup.resourceStates.some(s => pathEquals(s.resourceUri.fsPath, d.uri.fsPath)));
}
if (documents.length > 0) {
const message = documents.length === 1
? localize('unsaved stash files single', "The following file has unsaved changes which won't be included in the stash if you proceed: {0}.\n\nWould you like to save it before stashing?", path.basename(documents[0].uri.fsPath))
: localize('unsaved stash files', "There are {0} unsaved files.\n\nWould you like to save them before stashing?", documents.length);
const saveAndStash = localize('save and stash', "Save All & Stash");
const stash = localize('stash', "Stash Anyway");
const pick = await window.showWarningMessage(message, { modal: true }, saveAndStash, stash);
if (pick === saveAndStash) {
await Promise.all(documents.map(d => d.save()));
} else if (pick !== stash) {
return; // do not stash on cancel
}
}
}
let message: string | undefined;
if (config.get<boolean>('useCommitInputAsStashMessage') && (!repository.sourceControl.commitTemplate || repository.inputBox.value !== repository.sourceControl.commitTemplate)) {
message = repository.inputBox.value;
}
message = await window.showInputBox({
value: message,
prompt: localize('provide stash message', "Optionally provide a stash message"),
placeHolder: localize('stash message', "Stash message")
});
if (typeof message === 'undefined') {
return;
@@ -2361,13 +2625,6 @@ export class CommandCenter {
await repository.createStash(message, includeUntracked);
}
private async getStashMessage(): Promise<string | undefined> {
return await window.showInputBox({
prompt: localize('provide stash message', "Optionally provide a stash message"),
placeHolder: localize('stash message', "Stash message")
});
}
@command('git.stash', { repository: true })
stash(repository: Repository): Promise<void> {
return this._stash(repository);
@@ -2435,6 +2692,16 @@ export class CommandCenter {
return;
}
// request confirmation for the operation
const yes = localize('yes', "Yes");
const result = await window.showWarningMessage(
localize('sure drop', "Are you sure you want to drop the stash: {0}?", stash.description),
yes
);
if (result !== yes) {
return;
}
await repository.dropStash(stash.index);
}
@@ -2498,7 +2765,11 @@ export class CommandCenter {
@command('git.rebaseAbort', { repository: true })
async rebaseAbort(repository: Repository): Promise<void> {
await repository.rebaseAbort();
if (repository.rebaseCommit) {
await repository.rebaseAbort();
} else {
await window.showInformationMessage(localize('no rebase', "No rebase in progress."));
}
}
private createCommand(id: string, key: string, method: Function, options: CommandOptions): (...args: any[]) => any {
@@ -2549,6 +2820,31 @@ export class CommandCenter {
const outputChannel = this.outputChannel as OutputChannel;
choices.set(openOutputChannelChoice, () => outputChannel.show());
const showCommandOutputChoice = localize('show command output', "Show Command Output");
if (err.stderr) {
choices.set(showCommandOutputChoice, async () => {
const timestamp = new Date().getTime();
const uri = Uri.parse(`git-output:/git-error-${timestamp}`);
let command = 'git';
if (err.gitArgs) {
command = `${command} ${err.gitArgs.join(' ')}`;
} else if (err.gitCommand) {
command = `${command} ${err.gitCommand}`;
}
this.commandErrors.set(uri, `> ${command}\n${err.stderr}`);
try {
const doc = await workspace.openTextDocument(uri);
await window.showTextDocument(doc);
} finally {
this.commandErrors.delete(uri);
}
});
}
switch (err.gitErrorCode) {
case GitErrorCodes.DirtyWorkTree:
message = localize('clean repo', "Please clean your repository working tree before checkout.");