From 1e0bcfac291e76984cfa208ce629f639f9a55be4 Mon Sep 17 00:00:00 2001
From: Eric Amodio <eamodio@gmail.com>
Date: Sun, 28 Feb 2021 01:03:47 -0500
Subject: [PATCH] Adds publish repository command

---
 CHANGELOG.md              |  1 +
 package.json              | 17 ++++++++++++++++-
 src/constants.ts          |  1 +
 src/views/viewCommands.ts |  9 +++++++++
 4 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index be3163f..792a0be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
   - _Toggles the file heatmap_
   - _Toggles the file changes since before the commit_
   - _Toggles the file changes from the commit_
+- Adds _Publish Repository_ command (`gitlens.publishRepository`) to publish the repository to a remote provider
 - Adds supported remote types in README &mdash; thanks to [PR #1371](https://github.com/eamodio/vscode-gitlens/pull/1371) by Vladislav Guleaev ([@vguleaev](https://github.com/vguleaev))
 
 ### Changed
diff --git a/package.json b/package.json
index b94f06d..be8256a 100644
--- a/package.json
+++ b/package.json
@@ -3808,6 +3808,12 @@
 				"icon": "$(cloud-upload)"
 			},
 			{
+				"command": "gitlens.views.publishRepository",
+				"title": "Publish Repository",
+				"category": "GitLens",
+				"icon": "$(cloud-upload)"
+			},
+			{
 				"command": "gitlens.views.pull",
 				"title": "Pull",
 				"category": "GitLens",
@@ -5457,6 +5463,10 @@
 					"when": "false"
 				},
 				{
+					"command": "gitlens.views.publishRepository",
+					"when": "false"
+				},
+				{
 					"command": "gitlens.views.pull",
 					"when": "false"
 				},
@@ -7906,11 +7916,16 @@
 					"group": "8_gitlens_actions_@2"
 				},
 				{
-					"command": "gitlens.views.addRemote",
+					"command": "gitlens.views.publishRepository",
 					"when": "!gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:status(\\-branch)?:upstream:none/",
 					"group": "inline@1"
 				},
 				{
+					"command": "gitlens.views.addRemote",
+					"when": "!gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:status(\\-branch)?:upstream:none/",
+					"group": "inline@2"
+				},
+				{
 					"command": "gitlens.views.publishBranch",
 					"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:status(\\-branch)?:upstream:none/",
 					"group": "inline@1"
diff --git a/src/constants.ts b/src/constants.ts
index c4d69e3..17c6da7 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -28,6 +28,7 @@ export enum BuiltInCommands {
 }
 
 export enum BuiltInGitCommands {
+	Publish = 'git.publish',
 	Pull = 'git.pull',
 	PullRebase = 'git.pullRebase',
 	Push = 'git.push',
diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts
index 14cccc3..4eef9c1 100644
--- a/src/views/viewCommands.ts
+++ b/src/views/viewCommands.ts
@@ -121,6 +121,7 @@ export class ViewCommands {
 
 		commands.registerCommand('gitlens.views.fetch', this.fetch, this);
 		commands.registerCommand('gitlens.views.publishBranch', this.publishBranch, this);
+		commands.registerCommand('gitlens.views.publishRepository', this.publishRepository, this);
 		commands.registerCommand('gitlens.views.pull', this.pull, this);
 		commands.registerCommand('gitlens.views.push', this.push, this);
 		commands.registerCommand('gitlens.views.pushWithForce', n => this.push(n, true), this);
@@ -453,6 +454,14 @@ export class ViewCommands {
 	}
 
 	@debug()
+	private publishRepository(node: BranchNode | BranchTrackingStatusNode) {
+		if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) {
+			return commands.executeCommand(BuiltInGitCommands.Publish, Uri.file(node.repoPath));
+		}
+		return Promise.resolve();
+	}
+
+	@debug()
 	private pull(node: RepositoryNode | BranchNode | BranchTrackingStatusNode) {
 		if (node instanceof RepositoryNode) return GitActions.pull(node.repo);
 		if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) {