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 files changed, 14 insertions(+), 14 deletions(-) diff --git a/knotserver/git/branch.go b/knotserver/git/branch.go index f8ee62ca..3aa7ff69 100644 --- a/knotserver/git/branch.go +++ b/knotserver/git/branch.go @@ -141,6 +141,19 @@ func (g *GitRepo) Branches(opts *BranchesOptions) ([]types.Branch, error) { 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 index 5d888852..212f25e0 100644 --- a/knotserver/git/git.go +++ b/knotserver/git/git.go @@ -122,7 +122,7 @@ func (g *GitRepo) Commits(offset, limit int) ([]*object.Commit, error) { 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) @@ -252,19 +252,6 @@ func (g *GitRepo) Submodule(path string) (*config.Submodule, error) { 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 { ref := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.NewBranchReferenceName(branch)) return g.r.Storer.SetReference(ref) -- 2.51.2