This commit is contained in:
Thomas
2026-03-12 23:41:12 +01:00
parent 8049c505a0
commit 7c1a20465a
10 changed files with 1057 additions and 120 deletions

View File

@@ -82,3 +82,36 @@ func TagExists(dir, tag string) (bool, error) {
}
return strings.TrimSpace(out) == tag, nil
}
// BranchExists returns true if the given local branch exists.
func BranchExists(dir, branch string) (bool, error) {
out, err := Run(dir, "branch", "--list", branch)
if err != nil {
return false, err
}
return strings.TrimSpace(out) != "", nil
}
// CheckoutBranch checks out an existing branch.
func CheckoutBranch(dir, branch string) error {
_, err := Run(dir, "checkout", branch)
return err
}
// CheckoutNewBranch creates and checks out a new branch from the given base.
func CheckoutNewBranch(dir, branch, base string) error {
_, err := Run(dir, "checkout", "-B", branch, base)
return err
}
// PushBranch force-pushes a branch to origin.
func PushBranch(dir, branch string) error {
_, err := Run(dir, "push", "--force-with-lease", "origin", branch)
return err
}
// FetchOrigin fetches from origin.
func FetchOrigin(dir string) error {
_, err := Run(dir, "fetch", "origin")
return err
}