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
5 changed files with 96 additions and 2 deletions

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 () => {