diff --git a/extensions/git/package.json b/extensions/git/package.json index 9c4fda1baeb..daf74ad475b 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -119,6 +119,16 @@ "title": "Undo Last Commit", "category": "Git" }, + { + "command": "git.checkout", + "title": "Checkout to...", + "category": "Git" + }, + { + "command": "git.branch", + "title": "Create Branch...", + "category": "Git" + }, { "command": "git.pull", "title": "Pull", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 71372a50a37..fedc616db14 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -295,34 +295,6 @@ export class CommandCenter { return await this.model.clean(...this.model.workingTreeGroup.resources); } - @CommandCenter.Command('git.checkout') - @CommandCenter.CatchErrors - async checkout(): Promise { - const config = workspace.getConfiguration('git'); - const checkoutType = config.get('checkoutType'); - const includeTags = checkoutType === 'all' || checkoutType === 'tags'; - const includeRemotes = checkoutType === 'all' || checkoutType === 'remote'; - - const heads = this.model.refs.filter(ref => ref.type === RefType.Head) - .map(ref => new CheckoutItem(ref)); - - const tags = (includeTags ? this.model.refs.filter(ref => ref.type === RefType.Tag) : []) - .map(ref => new CheckoutTagItem(ref)); - - const remoteHeads = (includeRemotes ? this.model.refs.filter(ref => ref.type === RefType.RemoteHead) : []) - .map(ref => new CheckoutRemoteHeadItem(ref)); - - const picks = [...heads, ...tags, ...remoteHeads]; - const placeHolder = 'Select a ref to checkout'; - const choice = await window.showQuickPick(picks, { placeHolder }); - - if (!choice) { - return; - } - - await choice.run(this.model); - } - @CommandCenter.Command('git.commitStaged') @CommandCenter.CatchErrors async commitStaged(): Promise { @@ -353,6 +325,50 @@ export class CommandCenter { await Promise.reject('not implemented'); } + @CommandCenter.Command('git.checkout') + @CommandCenter.CatchErrors + async checkout(): Promise { + const config = workspace.getConfiguration('git'); + const checkoutType = config.get('checkoutType'); + const includeTags = checkoutType === 'all' || checkoutType === 'tags'; + const includeRemotes = checkoutType === 'all' || checkoutType === 'remote'; + + const heads = this.model.refs.filter(ref => ref.type === RefType.Head) + .map(ref => new CheckoutItem(ref)); + + const tags = (includeTags ? this.model.refs.filter(ref => ref.type === RefType.Tag) : []) + .map(ref => new CheckoutTagItem(ref)); + + const remoteHeads = (includeRemotes ? this.model.refs.filter(ref => ref.type === RefType.RemoteHead) : []) + .map(ref => new CheckoutRemoteHeadItem(ref)); + + const picks = [...heads, ...tags, ...remoteHeads]; + const placeHolder = 'Select a ref to checkout'; + const choice = await window.showQuickPick(picks, { placeHolder }); + + if (!choice) { + return; + } + + await choice.run(this.model); + } + + @CommandCenter.Command('git.branch') + @CommandCenter.CatchErrors + async branch(): Promise { + const result = await window.showInputBox({ + placeHolder: 'Branch name', + prompt: 'Please provide a branch name' + }); + + if (!result) { + return; + } + + const name = result.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-'); + await this.model.branch(name); + } + @CommandCenter.Command('git.pull') @CommandCenter.CatchErrors async pull(): Promise { diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index c874b8c2180..91df39977b0 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -322,6 +322,11 @@ export class Model { await this.update(); } + async branch(name: string): Promise { + await this.repository.branch(name, true); + await this.update(); + } + async checkout(treeish: string): Promise { await this.repository.checkout(treeish, []); await this.update();