mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
cleanup git delete tag command
This commit is contained in:
5
extensions/git/src/api/git.d.ts
vendored
5
extensions/git/src/api/git.d.ts
vendored
@@ -37,11 +37,6 @@ export interface Branch extends Ref {
|
||||
readonly behind?: number;
|
||||
}
|
||||
|
||||
export interface Tag extends Ref {
|
||||
readonly name: string;
|
||||
readonly message?: string;
|
||||
}
|
||||
|
||||
export interface Commit {
|
||||
readonly hash: string;
|
||||
readonly message: string;
|
||||
|
||||
@@ -15,7 +15,7 @@ import { lstat, Stats } from 'fs';
|
||||
import * as os from 'os';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { Ref, RefType, Branch, GitErrorCodes, Status, Tag } from './api/git';
|
||||
import { Ref, RefType, Branch, GitErrorCodes, Status } from './api/git';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -38,25 +38,6 @@ class CheckoutItem implements QuickPickItem {
|
||||
}
|
||||
}
|
||||
|
||||
class TagItem implements QuickPickItem {
|
||||
|
||||
get label(): string { return (this.tag.name || '').substr(0, 20); }
|
||||
get name(): string { return (this.tag.name || ''); }
|
||||
get description(): string {
|
||||
return (this.tag.message || '');
|
||||
}
|
||||
constructor(protected tag: Tag) { }
|
||||
|
||||
async run(repository: Repository): Promise<void> {
|
||||
const name = this.tag.name || '';
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
|
||||
await repository.deleteTag(name);
|
||||
}
|
||||
}
|
||||
|
||||
class CheckoutTagItem extends CheckoutItem {
|
||||
|
||||
get description(): string {
|
||||
@@ -232,9 +213,10 @@ function createCheckoutItems(repository: Repository): CheckoutItem[] {
|
||||
return [...heads, ...tags, ...remoteHeads];
|
||||
}
|
||||
|
||||
async function createTagItems(repository: Repository): Promise<TagItem[]> {
|
||||
const tags = await repository.getTags();
|
||||
return tags.map(tag => new TagItem(tag)) || [];
|
||||
class TagItem implements QuickPickItem {
|
||||
get label(): string { return this.ref.name ?? ''; }
|
||||
get description(): string { return this.ref.commit?.substr(0, 8) ?? ''; }
|
||||
constructor(readonly ref: Ref) { }
|
||||
}
|
||||
|
||||
enum PushType {
|
||||
@@ -1731,16 +1713,22 @@ export class CommandCenter {
|
||||
|
||||
@command('git.deleteTag', { repository: true })
|
||||
async deleteTag(repository: Repository): Promise<void> {
|
||||
const picks = await createTagItems(repository);
|
||||
if (!picks) {
|
||||
const picks = repository.refs.filter(ref => ref.type === RefType.Tag)
|
||||
.map(ref => new TagItem(ref));
|
||||
|
||||
if (picks.length === 0) {
|
||||
window.showWarningMessage(localize('no tags', "This repository has no tags."));
|
||||
return;
|
||||
}
|
||||
|
||||
const placeHolder = localize('select a tag to delete', 'Select a tag to delete');
|
||||
const choice = await window.showQuickPick<TagItem>(picks, { placeHolder });
|
||||
const choice = await window.showQuickPick(picks, { placeHolder });
|
||||
|
||||
if (!choice) {
|
||||
return;
|
||||
}
|
||||
await repository.deleteTag(choice.name);
|
||||
|
||||
await repository.deleteTag(choice.label);
|
||||
}
|
||||
|
||||
@command('git.fetch', { repository: true })
|
||||
|
||||
@@ -15,7 +15,7 @@ import { assign, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp,
|
||||
import { CancellationToken, Progress } from 'vscode';
|
||||
import { URI } from 'vscode-uri';
|
||||
import { detectEncoding } from './encoding';
|
||||
import { Ref, RefType, Branch, Remote, GitErrorCodes, LogOptions, Change, Status, Tag } from './api/git';
|
||||
import { Ref, RefType, Branch, Remote, GitErrorCodes, LogOptions, Change, Status } from './api/git';
|
||||
import * as byline from 'byline';
|
||||
import { StringDecoder } from 'string_decoder';
|
||||
|
||||
@@ -1332,21 +1332,6 @@ export class Repository {
|
||||
await this.run(args);
|
||||
}
|
||||
|
||||
async getTags(): Promise<Tag[]> {
|
||||
let args = ['tag', '-n1'];
|
||||
const result = await this.run(args);
|
||||
return result.stdout.trim().split('\n')
|
||||
.map(line => line.trim().split('\0'))
|
||||
.map(([line]) => {
|
||||
const name = line.split(' ')[0];
|
||||
return {
|
||||
name: name,
|
||||
message: line.replace(name, '').trim() || '',
|
||||
type: RefType.Tag
|
||||
} as Tag;
|
||||
});
|
||||
}
|
||||
|
||||
async clean(paths: string[]): Promise<void> {
|
||||
const pathsByGroup = groupBy(paths, p => path.dirname(p));
|
||||
const groups = Object.keys(pathsByGroup).map(k => pathsByGroup[k]);
|
||||
|
||||
@@ -13,7 +13,7 @@ import * as path from 'path';
|
||||
import * as nls from 'vscode-nls';
|
||||
import * as fs from 'fs';
|
||||
import { StatusBarCommands } from './statusbar';
|
||||
import { Branch, Ref, Remote, RefType, GitErrorCodes, Status, LogOptions, Change, Tag } from './api/git';
|
||||
import { Branch, Ref, Remote, RefType, GitErrorCodes, Status, LogOptions, Change } from './api/git';
|
||||
import { IFileWatcher, watch } from './watch';
|
||||
|
||||
const timeout = (millis: number) => new Promise(c => setTimeout(c, millis));
|
||||
@@ -293,7 +293,6 @@ export const enum Operation {
|
||||
Ignore = 'Ignore',
|
||||
Tag = 'Tag',
|
||||
DeleteTag = 'DeleteTag',
|
||||
GetTags = 'GetTags',
|
||||
Stash = 'Stash',
|
||||
CheckIgnore = 'CheckIgnore',
|
||||
GetObjectDetails = 'GetObjectDetails',
|
||||
@@ -1027,10 +1026,6 @@ export class Repository implements Disposable {
|
||||
await this.run(Operation.DeleteTag, () => this.repository.deleteTag(name));
|
||||
}
|
||||
|
||||
async getTags(): Promise<Tag[]> {
|
||||
return await this.run(Operation.GetTags, () => this.repository.getTags());
|
||||
}
|
||||
|
||||
async checkout(treeish: string): Promise<void> {
|
||||
await this.run(Operation.Checkout, () => this.repository.checkout(treeish, []));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user