From eaaec7704c101b8ed53d8b5b6913f456fff1888b Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Thu, 29 Jan 2026 06:50:14 +0000 Subject: [PATCH] knotserver/git: move git.Branch into branch.go makes more sense imo. Signed-off-by: oppiliappan --- knotserver/git/branch.go | 13 +++++++++++++ knotserver/git/git.go | 15 +-------------- 2 file(s) changed, 14 insertion(s)(+), 14 deletion(s)(-) diff --git a/knotserver/git/branch.go b/knotserver/git/branch.go --- a/knotserver/git/branch.go +++ b/knotserver/git/branch.go @@ -141,6 +141,19 @@ slices.Reverse(branches) return branches, nil } +func (g *GitRepo) Branch(name string) (*plumbing.Reference, error) { + ref, err := g.r.Reference(plumbing.NewBranchReferenceName(name), false) + if err != nil { + return nil, fmt.Errorf("branch: %w", err) + } + + if !ref.Name().IsBranch() { + return nil, fmt.Errorf("branch: %s is not a branch", ref.Name()) + } + + return ref, nil +} + func (g *GitRepo) DeleteBranch(branch string) error { ref := plumbing.NewBranchReferenceName(branch) return g.r.Storer.RemoveReference(ref) diff --git a/knotserver/git/git.go b/knotserver/git/git.go --- a/knotserver/git/git.go +++ b/knotserver/git/git.go @@ -122,7 +122,7 @@ func (g *GitRepo) TotalCommits() (int, error) { output, err := g.revList( g.h.String(), - fmt.Sprintf("--count"), + "--count", ) if err != nil { return 0, fmt.Errorf("failed to run rev-list: %w", err) @@ -250,19 +250,6 @@ } // path is not a submodule return nil, ErrNotSubmodule -} - -func (g *GitRepo) Branch(name string) (*plumbing.Reference, error) { - ref, err := g.r.Reference(plumbing.NewBranchReferenceName(name), false) - if err != nil { - return nil, fmt.Errorf("branch: %w", err) - } - - if !ref.Name().IsBranch() { - return nil, fmt.Errorf("branch: %s is not a branch", ref.Name()) - } - - return ref, nil } func (g *GitRepo) SetDefaultBranch(branch string) error { -- tangled.sh