All checks were successful
continuous-integration/drone/push Build is passing
36 lines
905 B
Go
36 lines
905 B
Go
package git
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/go-git/go-git/v5"
|
|
"github.com/go-git/go-git/v5/plumbing"
|
|
"github.com/go-git/go-git/v5/storage/memory"
|
|
)
|
|
|
|
func TestSwitchToMain(t *testing.T) {
|
|
repo, err := git.Init(memory.NewStorage(), nil)
|
|
if err != nil {
|
|
t.Fatalf("failed to create in-memory repository: %v", err)
|
|
}
|
|
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)
|
|
}
|
|
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)
|
|
}
|
|
if cfg.Init.DefaultBranch != "main" {
|
|
t.Errorf("expected default branch to be 'main', got %s", cfg.Init.DefaultBranch)
|
|
}
|
|
}
|