Skip to content

Commit

Permalink
fix(branch): 75 add validation before checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Martinez committed Mar 25, 2023
1 parent 136870e commit 8b17dd1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions controllers/git/checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ func CheckBranchExist(branch string) bool {
_, _, err := shell.Out("git rev-parse --verify " + branch)
return err == nil
}

func CheckBranchExistOnOrigin(branch string) bool {
_, _, err := shell.Out("git ls-remote --heads origin " + branch)
return err == nil
}
23 changes: 23 additions & 0 deletions pkg/git/Checkers/BranchChecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package checkers
import (
"fmt"
"log"
"os"

"github.com/Minnek-Digital-Studio/cominnek/config"
git_controller "github.com/Minnek-Digital-Studio/cominnek/controllers/git"
Expand Down Expand Up @@ -38,6 +39,28 @@ func GetChanges() {
func CheckBranch(mainCmd string) {
branch := "develop"

if !git_controller.CheckBranchExist(branch) {
println("\nBranch develop not found\n")

if !git_controller.CheckBranchExist("master") {
println("\nBranch master not found\n")
color.Red("Please create a master branch first\n")
os.Exit(1)
}

if !git_controller.CheckBranchExistOnOrigin("develop") {
println("\nBranch develop not found on origin\n")
color.Yellow("Creating a new branch \n")
shell.ExecuteCommand("git branch develop master", false)
shell.ExecuteCommand("git checkout develop", false)
shell.ExecuteCommand("git push origin develop", false)
color.Green("\nBranch develop created\n\n")
} else {
color.Yellow("Getting branch develop from origin\n")
shell.ExecuteCommand("git checkout develop", false)
}
}

if config.AppData.Branch.Type == "hotfix" || config.AppData.Branch.Type == "support" {
branch = "master"
}
Expand Down

0 comments on commit 8b17dd1

Please sign in to comment.