chore: refactor / docstrings
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0bb25a00ec
commit
3f29084664
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user