summaryrefslogtreecommitdiff
path: root/pkg/git/git.go
diff options
context:
space:
mode:
authorAnton Medvedev <anton@medv.io>2025-12-07 16:56:52 +0100
committerAnton Medvedev <anton@medv.io>2025-12-07 16:56:52 +0100
commit1441fb29d93481f7bea76bbfa2a9f289ed1ac4f0 (patch)
tree6d01f974638c519780406f67158c9160cf06e7cc /pkg/git/git.go
parent20a5d07b2a4620ace14c6a5f622ca45e27f9c20d (diff)
Refactor code by introducing `Ref` type
Diffstat (limited to 'pkg/git/git.go')
-rw-r--r--pkg/git/git.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/pkg/git/git.go b/pkg/git/git.go
index 9139261..7fc28fa 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -31,7 +31,7 @@ func Branches(repoDir string, filter *regexp.Regexp, defaultBranch string) ([]Re
if filter != nil && !filter.MatchString(line) && line != defaultBranch {
continue
}
- branches = append(branches, Ref(line))
+ branches = append(branches, NewRef(line))
}
return branches, nil
}
@@ -88,13 +88,13 @@ func Tags(repoDir string) ([]Tag, error) {
}
func Files(ref Ref, repoDir string) ([]Blob, error) {
- if ref == "" {
- ref = "HEAD"
+ if ref.IsEmpty() {
+ ref = NewRef("HEAD")
}
// -r: recurse into subtrees
// -l: include blob size
- cmd := exec.Command("git", "ls-tree", "--full-tree", "-r", "-l", string(ref))
+ cmd := exec.Command("git", "ls-tree", "--full-tree", "-r", "-l", ref.Ref())
if repoDir != "" {
cmd.Dir = repoDir
}
@@ -196,11 +196,11 @@ func Files(ref Ref, repoDir string) ([]Blob, error) {
}
func BlobContent(ref Ref, path string, repoDir string) ([]byte, bool, error) {
- if ref == "" {
- ref = "HEAD"
+ if ref.IsEmpty() {
+ ref = NewRef("HEAD")
}
// Use `git show ref:path` to get the blob content at that ref
- cmd := exec.Command("git", "show", string(ref)+":"+path)
+ cmd := exec.Command("git", "show", ref.Ref()+":"+path)
if repoDir != "" {
cmd.Dir = repoDir
}
@@ -233,7 +233,7 @@ func Commits(ref Ref, repoDir string) ([]Commit, error) {
"--date=unix",
"--pretty=format:" + strings.Join(format, "\x1F"),
"-z", // Separate the commits with NULs instead of newlines
- string(ref),
+ ref.Ref(),
}
cmd := exec.Command("git", args...)