From cb5045bc9d59d4b6f60eef02015ec89d5128cac6 Mon Sep 17 00:00:00 2001
From: Andreas Jaekle <andreas@jaekle.net>
Date: Mon, 8 Apr 2024 09:58:43 +0200
Subject: [PATCH] feat: allow to set custom push options (#7)

---
 README.md           |  3 ++-
 pkg/provider/git.go | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 571aff8..a0aafb2 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,8 @@ To use this plugin you need to include the following block in your
 | auth_username    | git                         | The name of the user to use for authentication.    |
 | auth_password    |                             | The password to use for basic auth or the SSH key. |
 | auth_private_key |                             | The path to an SSH private key file.               |
-| git_path         | .                           | The path to the Git repository                     |
+| git_path         | .                           | The path to the Git repository.                    |
+| push_options     |                             | The push options for the git tag push.             |
 
 ### Authentication
 
diff --git a/pkg/provider/git.go b/pkg/provider/git.go
index 9e81d9b..c816043 100644
--- a/pkg/provider/git.go
+++ b/pkg/provider/git.go
@@ -28,6 +28,7 @@ type Repository struct {
 	remoteName    string
 	auth          transport.AuthMethod
 	repo          *git.Repository
+	pushOptions   map[string]string
 }
 
 func (repo *Repository) Init(config map[string]string) error {
@@ -68,6 +69,15 @@ func (repo *Repository) Init(config map[string]string) error {
 		repo.auth = nil
 	}
 
+	if config["push_options"] != "" {
+		options := strings.Split(config["push_options"], ",")
+		repo.pushOptions = make(map[string]string, len(options))
+		for _, o := range options {
+			key, value, _ := strings.Cut(o, "=")
+			repo.pushOptions[key] = value
+		}
+	}
+
 	gitPath := config["git_path"]
 	if gitPath == "" {
 		gitPath = "."
@@ -201,7 +211,8 @@ func (repo *Repository) CreateRelease(release *provider.CreateReleaseConfig) err
 		RefSpecs: []config.RefSpec{
 			config.RefSpec(fmt.Sprintf("refs/tags/%s:refs/tags/%s", tag, tag)),
 		},
-		Auth: repo.auth,
+		Auth:    repo.auth,
+		Options: repo.pushOptions,
 	})
 	return err
 }
-- 
GitLab