Merge branch 'git-tag' of https://github.com/ashutoshdhundhara/vscode into ashutoshdhundhara-git-tag

This commit is contained in:
Joao Moreno 2017-08-10 15:38:26 +02:00
commit 0bd753f8a1
5 changed files with 96 additions and 2 deletions

View File

@ -187,6 +187,16 @@
"title": "%command.merge%",
"category": "Git"
},
{
"command": "git.createTag",
"title": "%command.createTag%",
"category": "Git"
},
{
"command": "git.showTags",
"title": "%command.showTags%",
"category": "Git"
},
{
"command": "git.pull",
"title": "%command.pull%",
@ -212,6 +222,11 @@
"title": "%command.pushTo%",
"category": "Git"
},
{
"command": "git.pushWithTags",
"title": "%command.pushWithTags%",
"category": "Git"
},
{
"command": "git.sync",
"title": "%command.sync%",
@ -347,6 +362,14 @@
"command": "git.pullFrom",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.showTags",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.createTag",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.push",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
@ -355,6 +378,10 @@
"command": "git.pushTo",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.pushWithTags",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"

View File

@ -24,11 +24,14 @@
"command.branch": "Create Branch...",
"command.deleteBranch": "Delete Branch...",
"command.merge": "Merge Branch...",
"command.createTag": "Create Tag",
"command.showTags": "Show Tags",
"command.pull": "Pull",
"command.pullRebase": "Pull (Rebase)",
"command.pullFrom": "Pull from...",
"command.push": "Push",
"command.pushTo": "Push to...",
"command.pushWithTags": "Push With Tags",
"command.sync": "Sync",
"command.publish": "Publish Branch",
"command.showOutput": "Show Git Output",

View File

@ -837,6 +837,31 @@ export class CommandCenter {
}
}
@command('git.createTag')
async createTag(): Promise<void> {
const inputTagName = await window.showInputBox({
placeHolder: localize('tag name', "Tag name"),
prompt: localize('provide tag name', "Please provide a tag name"),
ignoreFocusOut: true
});
if (!inputTagName) {
return;
}
const inputMessage = await window.showInputBox({
placeHolder: localize('tag message', "Message"),
prompt: localize('provide tag message', "Please provide a message"),
ignoreFocusOut: true
});
const name = inputTagName.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-');
const message = inputMessage || name;
await this.model.tag(name, message);
window.showInformationMessage(localize('tag creation success', "Successfully created tag."));
}
@command('git.pullFrom')
async pullFrom(): Promise<void> {
const remotes = this.model.remotes;
@ -903,6 +928,20 @@ export class CommandCenter {
await this.model.push();
}
@command('git.pushWithTags')
async pushWithTags(): Promise<void> {
const remotes = this.model.remotes;
if (remotes.length === 0) {
window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to."));
return;
}
await this.model.pushTags();
window.showInformationMessage(localize('push with tags success', "Successfully pushed with tags."));
}
@command('git.pushTo')
async pushTo(): Promise<void> {
const remotes = this.model.remotes;

View File

@ -677,6 +677,18 @@ export class Repository {
}
}
async tag(name: string, message: string, lightweight: boolean): Promise<void> {
let args = ['tag'];
if (lightweight) {
args.push(name);
} else {
args = args.concat(['-a', name, '-m', message]);
}
await this.run(args);
}
async clean(paths: string[]): Promise<void> {
const pathsByGroup = groupBy(paths, p => path.dirname(p));
const groups = Object.keys(pathsByGroup).map(k => pathsByGroup[k]);
@ -786,13 +798,17 @@ export class Repository {
}
}
async push(remote?: string, name?: string, setUpstream: boolean = false): Promise<void> {
async push(remote?: string, name?: string, setUpstream: boolean = false, tags = false): Promise<void> {
const args = ['push'];
if (setUpstream) {
args.push('-u');
}
if (tags) {
args.push('--tags');
}
if (remote) {
args.push(remote);
}

View File

@ -214,7 +214,8 @@ export enum Operation {
GetCommitTemplate = 1 << 15,
DeleteBranch = 1 << 16,
Merge = 1 << 17,
Ignore = 1 << 18
Ignore = 1 << 18,
Tag = 1 << 19
}
// function getOperationName(operation: Operation): string {
@ -465,6 +466,10 @@ export class Model implements Disposable {
await this.run(Operation.Merge, () => this.repository.merge(ref));
}
async tag(name: string, message: string): Promise<void> {
await this.run(Operation.Tag, () => this.repository.tag(name, message, false));
}
async checkout(treeish: string): Promise<void> {
await this.run(Operation.Checkout, () => this.repository.checkout(treeish, []));
}
@ -509,6 +514,10 @@ export class Model implements Disposable {
await this.run(Operation.Push, () => this.repository.push(remote, name, setUpstream));
}
async pushTags(remote?: string): Promise<void> {
await this.run(Operation.Push, () => this.repository.push(remote, undefined, false, true));
}
@throttle
async sync(): Promise<void> {
await this.run(Operation.Sync, async () => {