From 4e2b78524873cd6fc2efbe89a3b3920c60b959a3 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Sat, 23 Jul 2022 21:17:55 +0200 Subject: [PATCH] Feat: Allow to set branch --- plugin/plugin.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index 4fd66d5..6def189 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -26,6 +26,7 @@ type Args struct { Folder string `envconfig:"PLUGIN_FOLDER"` SshKey string `envconfig:"PLUGIN_SSH_KEY"` GitRemote string `envconfig:"PLUGIN_GIT_REMOTE"` + GitBranch string `envconfig:"PLUGIN_GIT_BRANCH"` GitRemoteFromDrone string `envconfig:"DRONE_GIT_SSH_URL"` } @@ -87,6 +88,10 @@ func checkArgs(args *Args) error { args.GitRemote = args.GitRemoteFromDrone } + if args.GitBranch == "" { + args.GitBranch = BRANCH_NAME + } + return nil } @@ -127,7 +132,7 @@ func copyFiles(args Args) error { func initRepo(args Args) error { cmd := exec.Command( "git", - "init", "-b", BRANCH_NAME, "/tmp/pages") + "init", "-b", args.GitBranch, "/tmp/pages") if err := execute(cmd); err != nil { return err @@ -149,7 +154,7 @@ func doCommit(args Args) error { } func push(args Args) error { - return execute(repo.RemotePushNamedBranch(args.GitRemote, BRANCH_NAME, BRANCH_NAME, true, false)) + return execute(repo.RemotePushNamedBranch(args.GitRemote, args.GitBranch, args.GitBranch, true, false)) } func execute(cmd *exec.Cmd) error {