Skip to content

Commit f402575

Browse files
committed
cleanup git delete tag command
1 parent 23a4df3 commit f402575

6 files changed

Lines changed: 17 additions & 60 deletions

File tree

extensions/git/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@
272272
"title": "%command.deleteTag%",
273273
"category": "Git"
274274
},
275-
{
276-
"command": "git.getTags",
277-
"title": "%command.getTags%",
278-
"category": "Git"
279-
},
280275
{
281276
"command": "git.fetch",
282277
"title": "%command.fetch%",

extensions/git/package.nls.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"command.merge": "Merge Branch...",
3939
"command.createTag": "Create Tag",
4040
"command.deleteTag": "Delete Tag",
41-
"command.getTags": "Get Tags",
4241
"command.fetch": "Fetch",
4342
"command.fetchPrune": "Fetch (Prune)",
4443
"command.fetchAll": "Fetch From All Remotes",

extensions/git/src/api/git.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ export interface Branch extends Ref {
3737
readonly behind?: number;
3838
}
3939

40-
export interface Tag extends Ref {
41-
readonly name: string;
42-
readonly message?: string;
43-
}
44-
4540
export interface Commit {
4641
readonly hash: string;
4742
readonly message: string;

extensions/git/src/commands.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { lstat, Stats } from 'fs';
1515
import * as os from 'os';
1616
import TelemetryReporter from 'vscode-extension-telemetry';
1717
import * as nls from 'vscode-nls';
18-
import { Ref, RefType, Branch, GitErrorCodes, Status, Tag } from './api/git';
18+
import { Ref, RefType, Branch, GitErrorCodes, Status } from './api/git';
1919

2020
const localize = nls.loadMessageBundle();
2121

@@ -38,25 +38,6 @@ class CheckoutItem implements QuickPickItem {
3838
}
3939
}
4040

41-
class TagItem implements QuickPickItem {
42-
43-
get label(): string { return (this.tag.name || '').substr(0, 20); }
44-
get name(): string { return (this.tag.name || ''); }
45-
get description(): string {
46-
return (this.tag.message || '');
47-
}
48-
constructor(protected tag: Tag) { }
49-
50-
async run(repository: Repository): Promise<void> {
51-
const name = this.tag.name || '';
52-
if (!name) {
53-
return;
54-
}
55-
56-
await repository.deleteTag(name);
57-
}
58-
}
59-
6041
class CheckoutTagItem extends CheckoutItem {
6142

6243
get description(): string {
@@ -232,9 +213,10 @@ function createCheckoutItems(repository: Repository): CheckoutItem[] {
232213
return [...heads, ...tags, ...remoteHeads];
233214
}
234215

235-
async function createTagItems(repository: Repository): Promise<TagItem[]> {
236-
const tags = await repository.getTags();
237-
return tags.map(tag => new TagItem(tag)) || [];
216+
class TagItem implements QuickPickItem {
217+
get label(): string { return this.ref.name ?? ''; }
218+
get description(): string { return this.ref.commit?.substr(0, 8) ?? ''; }
219+
constructor(readonly ref: Ref) { }
238220
}
239221

240222
enum PushType {
@@ -1731,16 +1713,22 @@ export class CommandCenter {
17311713

17321714
@command('git.deleteTag', { repository: true })
17331715
async deleteTag(repository: Repository): Promise<void> {
1734-
const picks = await createTagItems(repository);
1735-
if (!picks) {
1716+
const picks = repository.refs.filter(ref => ref.type === RefType.Tag)
1717+
.map(ref => new TagItem(ref));
1718+
1719+
if (picks.length === 0) {
17361720
window.showWarningMessage(localize('no tags', "This repository has no tags."));
1721+
return;
17371722
}
1723+
17381724
const placeHolder = localize('select a tag to delete', 'Select a tag to delete');
1739-
const choice = await window.showQuickPick<TagItem>(picks, { placeHolder });
1725+
const choice = await window.showQuickPick(picks, { placeHolder });
1726+
17401727
if (!choice) {
17411728
return;
17421729
}
1743-
await repository.deleteTag(choice.name);
1730+
1731+
await repository.deleteTag(choice.label);
17441732
}
17451733

17461734
@command('git.fetch', { repository: true })

extensions/git/src/git.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { assign, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp,
1515
import { CancellationToken, Progress } from 'vscode';
1616
import { URI } from 'vscode-uri';
1717
import { detectEncoding } from './encoding';
18-
import { Ref, RefType, Branch, Remote, GitErrorCodes, LogOptions, Change, Status, Tag } from './api/git';
18+
import { Ref, RefType, Branch, Remote, GitErrorCodes, LogOptions, Change, Status } from './api/git';
1919
import * as byline from 'byline';
2020
import { StringDecoder } from 'string_decoder';
2121

@@ -1332,21 +1332,6 @@ export class Repository {
13321332
await this.run(args);
13331333
}
13341334

1335-
async getTags(): Promise<Tag[]> {
1336-
let args = ['tag', '-n1'];
1337-
const result = await this.run(args);
1338-
return result.stdout.trim().split('\n')
1339-
.map(line => line.trim().split('\0'))
1340-
.map(([line]) => {
1341-
const name = line.split(' ')[0];
1342-
return {
1343-
name: name,
1344-
message: line.replace(name, '').trim() || '',
1345-
type: RefType.Tag
1346-
} as Tag;
1347-
});
1348-
}
1349-
13501335
async clean(paths: string[]): Promise<void> {
13511336
const pathsByGroup = groupBy(paths, p => path.dirname(p));
13521337
const groups = Object.keys(pathsByGroup).map(k => pathsByGroup[k]);

extensions/git/src/repository.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as path from 'path';
1313
import * as nls from 'vscode-nls';
1414
import * as fs from 'fs';
1515
import { StatusBarCommands } from './statusbar';
16-
import { Branch, Ref, Remote, RefType, GitErrorCodes, Status, LogOptions, Change, Tag } from './api/git';
16+
import { Branch, Ref, Remote, RefType, GitErrorCodes, Status, LogOptions, Change } from './api/git';
1717
import { IFileWatcher, watch } from './watch';
1818

1919
const timeout = (millis: number) => new Promise(c => setTimeout(c, millis));
@@ -293,7 +293,6 @@ export const enum Operation {
293293
Ignore = 'Ignore',
294294
Tag = 'Tag',
295295
DeleteTag = 'DeleteTag',
296-
GetTags = 'GetTags',
297296
Stash = 'Stash',
298297
CheckIgnore = 'CheckIgnore',
299298
GetObjectDetails = 'GetObjectDetails',
@@ -1027,10 +1026,6 @@ export class Repository implements Disposable {
10271026
await this.run(Operation.DeleteTag, () => this.repository.deleteTag(name));
10281027
}
10291028

1030-
async getTags(): Promise<Tag[]> {
1031-
return await this.run(Operation.GetTags, () => this.repository.getTags());
1032-
}
1033-
10341029
async checkout(treeish: string): Promise<void> {
10351030
await this.run(Operation.Checkout, () => this.repository.checkout(treeish, []));
10361031
}

0 commit comments

Comments
 (0)