Skip to content

Commit 16dc7f8

Browse files
committed
wip: checkpoint
1 parent 53bd037 commit 16dc7f8

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

cli/pkg/release/providers/docs.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log/slog"
66
"os"
77
"path/filepath"
8+
"time"
89

910
"github.com/input-output-hk/catalyst-forge/cli/pkg/earthly"
1011
"github.com/input-output-hk/catalyst-forge/cli/pkg/events"
@@ -82,7 +83,22 @@ func (r *DocsReleaser) Release() error {
8283
}
8384

8485
r.logger.Info("Checking out branch", "branch", r.config.Branch)
85-
if err := git.CheckoutBranch(r.project.Repo, r.config.Branch, git.GitCheckoutRemote()); err != nil {
86+
if err := git.CheckoutBranch(
87+
r.project.Repo,
88+
r.config.Branch,
89+
git.GitCheckoutRemote(),
90+
); err != nil {
91+
return fmt.Errorf("failed to checkout branch: %w", err)
92+
}
93+
94+
tempBranch := generateTempBranch()
95+
r.logger.Info("Creating orphan branch", "branch", tempBranch)
96+
if err := git.CheckoutBranch(
97+
r.project.Repo,
98+
tempBranch,
99+
git.GitCheckoutOrphan(),
100+
git.GitCheckoutCreate(),
101+
); err != nil {
86102
return fmt.Errorf("failed to checkout branch: %w", err)
87103
}
88104

@@ -191,6 +207,12 @@ func (r *DocsReleaser) clean(targetPath string) error {
191207
return nil
192208
}
193209

210+
// generateBranchName generates a temporary branch name.
211+
func generateTempBranch() string {
212+
timestamp := time.Now().Format("20060102-150405")
213+
return fmt.Sprintf("%s-%s", "forge-gh-pages", timestamp)
214+
}
215+
194216
// run runs the release target.
195217
func (r *DocsReleaser) run(path string) error {
196218
return r.runner.RunTarget(

lib/tools/git/util.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
type gitCheckoutOptions struct {
2222
create bool
2323
forceClean bool
24+
orphan bool
2425
remote bool
2526
}
2627

@@ -43,6 +44,14 @@ func GitCheckoutForceClean() GitCheckoutOption {
4344
}
4445
}
4546

47+
// GitCheckoutOrphan sets the orphan option for the Git checkout.
48+
func GitCheckoutOrphan() GitCheckoutOption {
49+
return func(o *gitCheckoutOptions) {
50+
o.orphan = true
51+
}
52+
}
53+
54+
// GitCheckoutRemote sets the remote option for the Git checkout.
4655
func GitCheckoutRemote() GitCheckoutOption {
4756
return func(o *gitCheckoutOptions) {
4857
o.remote = true
@@ -115,15 +124,20 @@ func CheckoutBranch(r *git.Repository, branch string, opts ...GitCheckoutOption)
115124
create = false
116125
}
117126

118-
var branchRef string
127+
var branchRef plumbing.ReferenceName
119128
if options.remote {
120-
branchRef = fmt.Sprintf("refs/remotes/origin/%s", branch)
129+
branchRef = plumbing.ReferenceName(fmt.Sprintf("refs/remotes/origin/%s", branch))
130+
} else if options.orphan {
131+
branchRef = plumbing.NewHashReference(
132+
plumbing.NewBranchReferenceName(branch),
133+
plumbing.ZeroHash,
134+
).Name()
121135
} else {
122-
branchRef = fmt.Sprintf("refs/heads/%s", branch)
136+
branchRef = plumbing.NewBranchReferenceName(branch)
123137
}
124138

125139
if err := wt.Checkout(&git.CheckoutOptions{
126-
Branch: plumbing.ReferenceName(branchRef),
140+
Branch: branchRef,
127141
Create: create,
128142
}); err != nil {
129143
return fmt.Errorf("failed to checkout branch: %w", err)

0 commit comments

Comments
 (0)