feat: implement Git: Push Tags command (#110096)

Related to #109799
This commit is contained in:
Scott Davis 2020-11-09 15:00:44 +00:00 committed by GitHub
parent e3754e6f8d
commit 7e5609afa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 4 deletions

View file

@ -379,6 +379,11 @@
"title": "%command.pushToForce%",
"category": "Git"
},
{
"command": "git.pushTags",
"title": "%command.pushTags%",
"category": "Git"
},
{
"command": "git.pushWithTags",
"title": "%command.pushFollowTags%",
@ -784,6 +789,10 @@
"command": "git.pushWithTagsForce",
"when": "config.git.enabled && !git.missing && config.git.allowForcePush && gitOpenRepositoryCount != 0"
},
{
"command": "git.pushTags",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
},
{
"command": "git.addRemote",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"

View file

@ -68,6 +68,7 @@
"command.pushToForce": "Push to... (Force)",
"command.pushFollowTags": "Push (Follow Tags)",
"command.pushFollowTagsForce": "Push (Follow Tags, Force)",
"command.pushTags": "Push Tags",
"command.addRemote": "Add Remote...",
"command.removeRemote": "Remove Remote",
"command.sync": "Sync",

View file

@ -271,6 +271,7 @@ enum PushType {
Push,
PushTo,
PushFollowTags,
PushTags
}
interface PushOptions {
@ -2222,6 +2223,10 @@ export class CommandCenter {
return;
}
if (pushOptions.pushType === PushType.PushTags) {
await repository.pushTags(undefined, forcePushMode);
}
if (!repository.HEAD || !repository.HEAD.name) {
if (!pushOptions.silent) {
window.showWarningMessage(localize('nobranch', "Please check out a branch to push to a remote."));
@ -2303,6 +2308,11 @@ export class CommandCenter {
await this._push(repository, { pushType: PushType.PushTo, forcePush: true });
}
@command('git.pushTags', { repository: true })
async pushTags(repository: Repository): Promise<void> {
await this._push(repository, { pushType: PushType.PushTags });
}
@command('git.addRemote', { repository: true })
async addRemote(repository: Repository): Promise<string | undefined> {
const url = await pickRemoteSource(this.model, {

View file

@ -1649,7 +1649,7 @@ export class Repository {
}
}
async push(remote?: string, name?: string, setUpstream: boolean = false, tags = false, forcePushMode?: ForcePushMode): Promise<void> {
async push(remote?: string, name?: string, setUpstream: boolean = false, followTags = false, forcePushMode?: ForcePushMode, tags = false): Promise<void> {
const args = ['push'];
if (forcePushMode === ForcePushMode.ForceWithLease) {
@ -1662,10 +1662,14 @@ export class Repository {
args.push('-u');
}
if (tags) {
if (followTags) {
args.push('--follow-tags');
}
if (tags) {
args.push('--tags');
}
if (remote) {
args.push(remote);
}

View file

@ -1221,6 +1221,10 @@ export class Repository implements Disposable {
await this.run(Operation.Push, () => this._push(remote, undefined, false, true, forcePushMode));
}
async pushTags(remote?: string, forcePushMode?: ForcePushMode): Promise<void> {
await this.run(Operation.Push, () => this._push(remote, undefined, false, false, forcePushMode, true));
}
async blame(path: string): Promise<string> {
return await this.run(Operation.Blame, () => this.repository.blame(path));
}
@ -1440,9 +1444,9 @@ export class Repository implements Disposable {
return ignored;
}
private async _push(remote?: string, refspec?: string, setUpstream: boolean = false, tags = false, forcePushMode?: ForcePushMode): Promise<void> {
private async _push(remote?: string, refspec?: string, setUpstream: boolean = false, followTags = false, forcePushMode?: ForcePushMode, tags = false): Promise<void> {
try {
await this.repository.push(remote, refspec, setUpstream, tags, forcePushMode);
await this.repository.push(remote, refspec, setUpstream, followTags, forcePushMode, tags);
} catch (err) {
if (!remote || !refspec) {
throw err;