Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkg/branch/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *Service) List() (ListOutput, error) {
g.Go(func() error {
branches, err := git.GetAllBranches(repoPath)
if err != nil {
return nil
return err
}

defaultBranch, err := git.GetDefaultBranch(repoPath)
Expand Down Expand Up @@ -170,7 +170,9 @@ func (s *Service) List() (ListOutput, error) {
})
}

_ = branchGroup.Wait()
if err := branchGroup.Wait(); err != nil {
return err
}

mu.Lock()
output.Repositories = append(output.Repositories, repoBranches)
Expand All @@ -183,7 +185,9 @@ func (s *Service) List() (ListOutput, error) {
})
}

_ = g.Wait()
if err := g.Wait(); err != nil {
return ListOutput{}, err
}
return output, nil
}

Expand Down Expand Up @@ -260,7 +264,9 @@ func (s *Service) ExecuteCleanup(plan CleanupPlan, skipBranches []string) (Clean
})
}

_ = g.Wait()
if err := g.Wait(); err != nil {
return CleanupResult{}, err
}
return CleanupResult{
Deleted: deleted,
Skipped: skipped,
Expand Down
8 changes: 6 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,19 @@ func TestConfigManager_IsInitialized(t *testing.T) {
{
name: "initialized when flag is set",
setupFunc: func(cm *ConfigManager, tmpDir string) {
_ = cm.SetInitialized(true)
if err := cm.SetInitialized(true); err != nil {
panic(err)
}
},
want: true,
},
{
name: "initialized when repos dir has content",
setupFunc: func(cm *ConfigManager, tmpDir string) {
reposDir := cm.GetConfig().ReposDir
_ = os.MkdirAll(filepath.Join(reposDir, "some-repo"), 0o755)
if err := os.MkdirAll(filepath.Join(reposDir, "some-repo"), 0o755); err != nil {
panic(err)
}
},
want: true,
},
Expand Down
36 changes: 26 additions & 10 deletions pkg/git/worktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ func initGitRepo(t *testing.T, path string) {

cmd = exec.Command("git", "config", "user.email", "test@test.com")
cmd.Dir = path
_ = cmd.Run()
if err := cmd.Run(); err != nil {
t.Fatalf("failed to set git config email: %v", err)
}

cmd = exec.Command("git", "config", "user.name", "Test User")
cmd.Dir = path
_ = cmd.Run()
if err := cmd.Run(); err != nil {
t.Fatalf("failed to set git config name: %v", err)
}

testFile := filepath.Join(path, "README.md")
if err := os.WriteFile(testFile, []byte("# Test"), 0o644); err != nil {
Expand Down Expand Up @@ -110,7 +114,7 @@ func TestCreateWorktree(t *testing.T) {
t.Fatalf("CreateWorktree() error = %v", err)
}

if _, err := os.Stat(worktreePath); os.IsNotExist(err) {
if _, statErr := os.Stat(worktreePath); os.IsNotExist(statErr) {
t.Error("worktree directory was not created")
}

Expand Down Expand Up @@ -206,8 +210,8 @@ func TestListWorktrees(t *testing.T) {
}

worktreePath := filepath.Join(tmpDir, "worktree")
if err := CreateWorktree(mainRepoPath, worktreePath, "test-branch"); err != nil {
t.Fatalf("CreateWorktree() error = %v", err)
if createErr := CreateWorktree(mainRepoPath, worktreePath, "test-branch"); createErr != nil {
t.Fatalf("CreateWorktree() error = %v", createErr)
}

worktrees, err = ListWorktrees(mainRepoPath)
Expand Down Expand Up @@ -247,7 +251,9 @@ func TestBranchExists(t *testing.T) {
setupFunc: func(t *testing.T, repoPath string) {
cmd := exec.Command("git", "branch", "feature-branch")
cmd.Dir = repoPath
_ = cmd.Run()
if err := cmd.Run(); err != nil {
t.Fatalf("failed to create branch: %v", err)
}
},
want: true,
},
Expand Down Expand Up @@ -299,8 +305,14 @@ func TestIsBranchCheckedOut(t *testing.T) {
t.Error("expected branch to be checked out")
}

realWorktreePath, _ := filepath.EvalSymlinks(worktreePath)
realLocation, _ := filepath.EvalSymlinks(location)
realWorktreePath, err := filepath.EvalSymlinks(worktreePath)
if err != nil {
t.Fatalf("EvalSymlinks(worktreePath) error = %v", err)
}
realLocation, err := filepath.EvalSymlinks(location)
if err != nil {
t.Fatalf("EvalSymlinks(location) error = %v", err)
}
if realLocation != realWorktreePath {
t.Errorf("location = %s, want %s", realLocation, realWorktreePath)
}
Expand Down Expand Up @@ -332,11 +344,15 @@ func TestGetAllBranches(t *testing.T) {

cmd := exec.Command("git", "branch", "branch1")
cmd.Dir = repoPath
_ = cmd.Run()
if err := cmd.Run(); err != nil {
t.Fatalf("failed to create branch1: %v", err)
}

cmd = exec.Command("git", "branch", "branch2")
cmd.Dir = repoPath
_ = cmd.Run()
if err := cmd.Run(); err != nil {
t.Fatalf("failed to create branch2: %v", err)
}

branches, err := GetAllBranches(repoPath)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/workspace/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func (s *Service) SyncMainRepos(repos []RepositorySpec) []SyncResult {
})
}

_ = g.Wait()
if err := g.Wait(); err != nil {
return results
}
return results
}

Expand Down Expand Up @@ -123,7 +125,9 @@ func (s *Service) Create(input CreateInput) (CreateOutput, error) {
wg.Add(1)
go func() {
defer wg.Done()
_ = sem.Acquire(ctx, 1)
if err := sem.Acquire(ctx, 1); err != nil {
return
}
defer sem.Release(1)

targetPath := filepath.Join(workspacePath, repo.Name)
Expand Down