replace code-descriptive comments with method level comments
This commit is contained in:
parent
730fef09a3
commit
28c7676413
@ -48,13 +48,12 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the default branch for the passed repo as "main"
|
||||||
func SwitchToMain(repo *git.Repository) error {
|
func SwitchToMain(repo *git.Repository) error {
|
||||||
// Create and set the 'main' branch as default
|
|
||||||
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 {
|
||||||
return fmt.Errorf("set reference: %s", err)
|
return fmt.Errorf("set reference: %s", err)
|
||||||
}
|
}
|
||||||
// Update the repository configuration
|
|
||||||
cfg, err := repo.Config()
|
cfg, err := repo.Config()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("repo config: %s", err)
|
return fmt.Errorf("repo config: %s", err)
|
||||||
|
@ -8,21 +8,17 @@ 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) {
|
||||||
// Create a new in-memory repository
|
|
||||||
storage := memory.NewStorage()
|
storage := memory.NewStorage()
|
||||||
repo, err := git.Init(storage, 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the function under test
|
|
||||||
err = SwitchToMain(repo)
|
err = SwitchToMain(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("SwitchToMain failed: %v", err)
|
t.Fatalf("SwitchToMain failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that HEAD points to the 'main' branch
|
|
||||||
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)
|
||||||
@ -30,8 +26,6 @@ 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())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that the default branch is set to 'main' in the config
|
|
||||||
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