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
|
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 {
|
func SwitchToMain(repo *git.Repository) error {
|
||||||
ref := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/heads/main"))
|
ref := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/heads/main"))
|
||||||
if err := repo.Storer.SetReference(ref); err != nil {
|
if err := repo.Storer.SetReference(ref); err != nil {
|
||||||
|
@ -8,17 +8,15 @@ import (
|
|||||||
"github.com/go-git/go-git/v5/storage/memory"
|
"github.com/go-git/go-git/v5/storage/memory"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Verify that SwitchToMain has the desired effect on the repo
|
|
||||||
func TestSwitchToMain(t *testing.T) {
|
func TestSwitchToMain(t *testing.T) {
|
||||||
storage := memory.NewStorage()
|
repo, err := git.Init(memory.NewStorage(), nil)
|
||||||
repo, err := git.Init(storage, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create in-memory repository: %v", err)
|
t.Fatalf("failed to create in-memory repository: %v", err)
|
||||||
}
|
}
|
||||||
err = SwitchToMain(repo)
|
if err = SwitchToMain(repo); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("SwitchToMain failed: %v", err)
|
t.Fatalf("SwitchToMain failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ref, err := repo.Reference(plumbing.HEAD, false)
|
ref, err := repo.Reference(plumbing.HEAD, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to get HEAD reference: %v", err)
|
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" {
|
if ref.Target().String() != "refs/heads/main" {
|
||||||
t.Errorf("expected HEAD to point to 'refs/heads/main', got %s", ref.Target().String())
|
t.Errorf("expected HEAD to point to 'refs/heads/main', got %s", ref.Target().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := repo.Config()
|
cfg, err := repo.Config()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to get repository config: %v", err)
|
t.Fatalf("failed to get repository config: %v", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user