Path: blob/main/dev/preview/previewctl/pkg/util/git.go
2501 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package util56import (7"os/exec"89"github.com/cockroachdb/errors"10)1112var (13ErrBranchNotExist = errors.New("branch doesn't exist")14)1516func BranchFromGit(branch string) (string, error) {17if branch == "" {18out, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()19if err != nil {20return "", errors.Wrap(err, "Could not retrieve branch name.")21}2223branch = string(out)24} else {25_, err := exec.Command("git", "rev-parse", "--verify", branch).Output()26if err != nil {27return "", errors.CombineErrors(err, ErrBranchNotExist)28}29}3031return branch, nil32}333435