Skip to content

Commit

Permalink
Merge pull request #69 from vitessio/checkout-fetch-head
Browse files Browse the repository at this point in the history
Checkout FETCH_HEAD, not HEAD when setting up repos for cobradocs sync
  • Loading branch information
frouioui committed Dec 18, 2023
2 parents 61daa62 + ee86294 commit 76fd163
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion go/cobradocs_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ func setupRepo(ctx context.Context, repo *git.Repo, op string) error {
return errors.Wrapf(err, "Failed to clean the repository %s/%s to %s", repo.Owner, repo.Name, op)
}

if err := repo.Checkout(ctx, repo.DefaultBranch); err != nil {
return errors.Wrapf(err, "Failed to checkout %s in %s/%s to %s", repo.DefaultBranch, repo.Owner, repo.Name, op)
}

if err := repo.Fetch(ctx, "origin"); err != nil {
return errors.Wrapf(err, "Failed to fetch origin on repository %s/%s to %s", repo.Owner, repo.Name, op)
}

if err := repo.ResetHard(ctx, "HEAD"); err != nil {
if err := repo.ResetHard(ctx, "FETCH_HEAD"); err != nil {
return errors.Wrapf(err, "Failed to reset the repository %s/%s to %s", repo.Owner, repo.Name, op)
}

Expand Down
17 changes: 12 additions & 5 deletions go/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ import (
)

type Repo struct {
Owner string
Name string
LocalDir string
Owner string
Name string
DefaultBranch string
LocalDir string
}

func NewRepo(owner, name string) *Repo {
return &Repo{
Owner: owner,
Name: name,
Owner: owner,
Name: name,
DefaultBranch: "main",
}
}

Expand All @@ -42,6 +44,11 @@ func (r *Repo) WithLocalDir(dir string) *Repo {
return r
}

func (r *Repo) WithDefaultBranch(branch string) *Repo {
r.DefaultBranch = branch
return r
}

func (r *Repo) Add(ctx context.Context, arg ...string) error {
_, err := shell.NewContext(ctx, "git", append([]string{"add"}, arg...)...).InDir(r.LocalDir).Output()
return err
Expand Down
4 changes: 3 additions & 1 deletion go/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,9 @@ func (h *PullRequestHandler) previewCobraDocs(ctx context.Context, event github.
website := git.NewRepo(
prInfo.repoOwner,
"website",
).WithLocalDir(filepath.Join(h.Workdir(), "website"))
).WithDefaultBranch("prod").WithLocalDir(
filepath.Join(h.Workdir(), "website"),
)

_, err = h.createCobraDocsPreviewPR(ctx, client, vitess, website, event.GetPullRequest(), docsVersion, prInfo)
return err
Expand Down

0 comments on commit 76fd163

Please sign in to comment.