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
17 changes: 17 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ categories:
- title: "Other Changes"
labels:
- "*"
autolabeler:
- label: "feature"
branch:
- "/^feat/"
- label: "fix"
branch:
- "/^fix/"
- "/^bugfix/"
- "/^hotfix/"
- label: "docs"
branch:
- "/^docs/"
- label: "enhancement"
branch:
- "/^improve/"
- "/^refactor/"
- "/^chore/"
version-resolver:
major:
labels:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Release Drafter
on:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read
Expand All @@ -17,6 +18,12 @@ jobs:
pull-requests: write

steps:
# Brief delay to allow GitHub API to propagate commit/PR data.
# Without this, the GraphQL query for associated pull requests
# can return empty results when run immediately after a push.
- name: Wait for API propagation
run: sleep 10

- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 5 additions & 2 deletions internal/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ func (s *Service) Render(ctx context.Context, id string, progress func(msg strin
if err != nil {
return fmt.Errorf("getting default branch for %s: %w", repo.URL, err)
}
s.log().Debug("creating worktree with new branch", "path", worktreePath, "branch", repo.Branch, "from", defaultBranch)
if err := s.Git.AddWorktreeNewBranch(ctx, barePath, worktreePath, repo.Branch, defaultBranch); err != nil {
// Use the remote ref to ensure we branch from the latest fetched state,
// not a potentially stale local branch ref in the bare repo.
startPoint := "origin/" + defaultBranch
s.log().Debug("creating worktree with new branch", "path", worktreePath, "branch", repo.Branch, "from", startPoint)
if err := s.Git.AddWorktreeNewBranch(ctx, barePath, worktreePath, repo.Branch, startPoint); err != nil {
return fmt.Errorf("creating worktree for %s: %w", repo.URL, err)
}
progress(fmt.Sprintf(" └── %s (%s, new branch from %s) ✓", repoPath, repo.Branch, defaultBranch))
Expand Down
38 changes: 33 additions & 5 deletions internal/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import (

// mockRunner records calls without executing git.
type mockRunner struct {
clones []string
fetches []string
worktrees []string
removed []string
clones []string
fetches []string
worktrees []string
removed []string
startPoints []string

cloneErr error
fetchErr error
Expand Down Expand Up @@ -47,7 +48,8 @@ func (m *mockRunner) AddWorktree(_ context.Context, _, worktreePath, _ string) e
return os.MkdirAll(worktreePath, 0o755)
}

func (m *mockRunner) AddWorktreeNewBranch(_ context.Context, _, worktreePath, _, _ string) error {
func (m *mockRunner) AddWorktreeNewBranch(_ context.Context, _, worktreePath, _, startPoint string) error {
m.startPoints = append(m.startPoints, startPoint)
m.worktrees = append(m.worktrees, worktreePath)
if m.addWTErr != nil {
return m.addWTErr
Expand Down Expand Up @@ -415,6 +417,32 @@ func TestRenderAddWorktreeError(t *testing.T) {
}
}

func TestRenderNewBranchUsesRemoteRef(t *testing.T) {
svc, mock := testService(t)
ctx := context.Background()

st := state.NewState("Remote ref test", "Test new branch uses origin/ prefix", []state.Repo{
{URL: "github.com/org/repo", Branch: "feat/new-feature", Path: "./repo"},
})
if err := svc.Create("remote-ref", st); err != nil {
t.Fatal(err)
}

// branchExists=false triggers the new branch path
mock.branchExists = false
err := svc.Render(ctx, "remote-ref", noop)
if err != nil {
t.Fatalf("Render: %v", err)
}

if len(mock.startPoints) != 1 {
t.Fatalf("startPoints = %d, want 1", len(mock.startPoints))
}
if mock.startPoints[0] != "origin/main" {
t.Errorf("startPoint = %q, want origin/main", mock.startPoints[0])
}
}

func TestRenderNotFound(t *testing.T) {
svc, _ := testService(t)
ctx := context.Background()
Expand Down