about summary refs log tree commit diff
path: root/internal/git/main.go
blob: 67e7d4d3368ba213df3ba013cb97f634c605281d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package git

import (
	"fmt"
	"os/exec"
	"strings"
)

func Root() (string, error) {
	cmd := exec.Command("git", "rev-parse", "--show-toplevel")
	output, err := cmd.Output()
	if err != nil {
		return "", fmt.Errorf("failed to get git repository: %s", err)
	}

	// The output includes the full path to the repository. To get just the name,
	// we can split the path by "/" and take the last part.
	pathParts := strings.Split(strings.TrimSpace(string(output)), "/")
	repoName := pathParts[len(pathParts)-1]

	return repoName, nil
}