chore: refactor / docstrings
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
decentral1se 2024-12-21 19:22:26 +01:00
parent 0bb25a00ec
commit 3f29084664
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 5 additions and 6 deletions

View File

@ -48,7 +48,7 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error {
return nil
}
// Set the default branch for the passed repo as "main"
// SwitchToMain sets the default branch to "main".
func SwitchToMain(repo *git.Repository) error {
ref := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/heads/main"))
if err := repo.Storer.SetReference(ref); err != nil {

View File

@ -8,17 +8,15 @@ import (
"github.com/go-git/go-git/v5/storage/memory"
)
// Verify that SwitchToMain has the desired effect on the repo
func TestSwitchToMain(t *testing.T) {
storage := memory.NewStorage()
repo, err := git.Init(storage, nil)
repo, err := git.Init(memory.NewStorage(), nil)
if err != nil {
t.Fatalf("failed to create in-memory repository: %v", err)
}
err = SwitchToMain(repo)
if err != nil {
if err = SwitchToMain(repo); err != nil {
t.Fatalf("SwitchToMain failed: %v", err)
}
ref, err := repo.Reference(plumbing.HEAD, false)
if err != nil {
t.Fatalf("failed to get HEAD reference: %v", err)
@ -26,6 +24,7 @@ func TestSwitchToMain(t *testing.T) {
if ref.Target().String() != "refs/heads/main" {
t.Errorf("expected HEAD to point to 'refs/heads/main', got %s", ref.Target().String())
}
cfg, err := repo.Config()
if err != nil {
t.Fatalf("failed to get repository config: %v", err)