From c43d4c1605896dcfa998e2c871dfc3e13a3ee7b8 Mon Sep 17 00:00:00 2001 From: Eitan Joffe Date: Thu, 11 Jan 2024 16:16:56 -0800 Subject: [PATCH] Check for backslashes in remote branch name Fixes #332 commit-id:a7c1a3c3 --- cmd/spr/main.go | 6 ++++++ config/config_parser/config_parser.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/cmd/spr/main.go b/cmd/spr/main.go index f857d94..13781d1 100644 --- a/cmd/spr/main.go +++ b/cmd/spr/main.go @@ -40,6 +40,12 @@ func main() { } cfg := config_parser.ParseConfig(gitcmd) + + err = config_parser.CheckConfig(cfg) + if err != nil { + fmt.Println(err) + os.Exit(2) + } gitcmd = realgit.NewGitCmd(cfg) ctx := context.Background() diff --git a/config/config_parser/config_parser.go b/config/config_parser/config_parser.go index ce09978..37150f0 100644 --- a/config/config_parser/config_parser.go +++ b/config/config_parser/config_parser.go @@ -6,6 +6,7 @@ import ( "os" "path" "path/filepath" + "strings" "github.com/ejoffe/rake" "github.com/ejoffe/spr/config" @@ -63,6 +64,13 @@ func ParseConfig(gitcmd git.GitInterface) *config.Config { return cfg } +func CheckConfig(cfg *config.Config) error { + if strings.Contains(cfg.Repo.GitHubBranch, "/") { + return errors.New("Remote branch name must not contain backslashes '/'") + } + return nil +} + func RepoConfigFilePath(gitcmd git.GitInterface) string { rootdir := gitcmd.RootDir() filepath := filepath.Clean(path.Join(rootdir, ".spr.yml"))