Add command to delete remote tag (fix #104845)

This commit is contained in:
Guillaume Poussel 2021-10-02 18:06:33 +02:00
parent a4342f3add
commit 6fdc1154a7
5 changed files with 63 additions and 1 deletions

View file

@ -340,6 +340,11 @@
"title": "%command.deleteTag%",
"category": "Git"
},
{
"command": "git.deleteRemoteTag",
"title": "%command.deleteRemoteTag%",
"category": "Git"
},
{
"command": "git.fetch",
"title": "%command.fetch%",
@ -783,6 +788,10 @@
"command": "git.deleteTag",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
},
{
"command": "git.deleteRemoteTag",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
},
{
"command": "git.fetch",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
@ -1614,6 +1623,10 @@
{
"command": "git.deleteTag",
"group": "tags@2"
},
{
"command": "git.deleteRemoteTag",
"group": "tags@3"
}
]
},

View file

@ -58,6 +58,7 @@
"command.rebase": "Rebase Branch...",
"command.createTag": "Create Tag",
"command.deleteTag": "Delete Tag",
"command.deleteRemoteTag": "Delete Remote Tag",
"command.fetch": "Fetch",
"command.fetchPrune": "Fetch (Prune)",
"command.fetchAll": "Fetch From All Remotes",

View file

@ -1952,6 +1952,7 @@ export class CommandCenter {
@command('git.deleteTag', { repository: true })
async deleteTag(repository: Repository): Promise<void> {
console.log(repository.refs);
const picks = repository.refs.filter(ref => ref.type === RefType.Tag)
.map(ref => new TagItem(ref));
@ -1970,6 +1971,43 @@ export class CommandCenter {
await repository.deleteTag(choice.label);
}
@command('git.deleteRemoteTag', { repository: true })
async deleteRemoteTag(repository: Repository): Promise<void> {
const remotePicks = repository.remotes
.filter(r => r.pushUrl !== undefined)
.map(r => ({ label: r.name, description: r.pushUrl! }));
if (remotePicks.length === 0) {
window.showErrorMessage(localize('no remotes to push', "Your repository has no remotes configured to push to."));
return;
}
const tagPicks = repository.refs.filter(ref => ref.type === RefType.Tag)
.map(ref => new TagItem(ref));
if (tagPicks.length === 0) {
window.showWarningMessage(localize('no tags', "This repository has no tags."));
return;
}
const tagPickPlaceholder = localize('select a tag to delete from remote', 'Select a tag to delete from remote');
const tagPick = await window.showQuickPick(tagPicks, { placeHolder: tagPickPlaceholder });
if (!tagPick) {
return;
}
const tagName = tagPick.label;
const remotePickPlaceholder = localize('pick remote delete tag', "Pick a remote to delete the tag '{0}' from:", tagName);
const remotePick = await window.showQuickPick(remotePicks, { placeHolder: remotePickPlaceholder });
if (!remotePick) {
return;
}
const remoteName = remotePick.label;
await repository.deleteRemoteTag(remoteName, tagName);
}
@command('git.fetch', { repository: true })
async fetch(repository: Repository): Promise<void> {
if (repository.remotes.length === 0) {

View file

@ -1485,7 +1485,12 @@ export class Repository {
}
async deleteTag(name: string): Promise<void> {
let args = ['tag', '-d', name];
const args = ['tag', '-d', name];
await this.exec(args);
}
async deleteRemoteTag(remoteName: string, tagName: string): Promise<void> {
const args = ['push', '--delete', remoteName, tagName];
await this.exec(args);
}

View file

@ -331,6 +331,7 @@ export const enum Operation {
Ignore = 'Ignore',
Tag = 'Tag',
DeleteTag = 'DeleteTag',
DeleteRemoteTag = 'DeleteRemoteTag',
Stash = 'Stash',
CheckIgnore = 'CheckIgnore',
GetObjectDetails = 'GetObjectDetails',
@ -1287,6 +1288,10 @@ export class Repository implements Disposable {
await this.run(Operation.DeleteTag, () => this.repository.deleteTag(name));
}
async deleteRemoteTag(remoteName: string, tagName: string): Promise<void> {
await this.run(Operation.DeleteRemoteTag, () => this.repository.deleteRemoteTag(remoteName, tagName));
}
async checkout(treeish: string, opts?: { detached?: boolean; }): Promise<void> {
await this.run(Operation.Checkout, () => this.repository.checkout(treeish, [], opts));
}