Skip to content

Commit ae918ff

Browse files
fix(webhook): keep parent commit for change analysis
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent dbd868f commit ae918ff

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

internal/webhook/gitops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func cloneRepo(ctx context.Context, repoURL, repoRoot, dest, namespace, branch s
212212

213213
opts := &git.CloneOptions{
214214
URL: repoURL,
215-
Depth: 1,
215+
Depth: 2,
216216
}
217217
if branch != "" {
218218
opts.ReferenceName = plumbing.NewBranchReferenceName(branch)

internal/webhook/gitops_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ func TestGitOps_CloneRepo(t *testing.T) {
137137
}
138138
}
139139

140+
func TestGitOps_CloneRepo_KeepsParentCommitForHEADTildeOne(t *testing.T) {
141+
bareDir := initBareRepo(t)
142+
addFileToBareRepo(t, bareDir, "second.txt", "second")
143+
destRoot := t.TempDir()
144+
ns := "test-ns"
145+
146+
if err := CloneOrPullBranch(context.Background(), bareDir, destRoot, ns, "main", nil); err != nil {
147+
t.Fatalf("CloneOrPullBranch failed: %v", err)
148+
}
149+
150+
dest := RepoDir(destRoot, ns)
151+
cmd := exec.Command("git", "rev-parse", "HEAD~1")
152+
cmd.Dir = dest
153+
if out, err := cmd.CombinedOutput(); err != nil {
154+
t.Fatalf("expected HEAD~1 to exist in cloned webhook repo: %v\n%s", err, out)
155+
}
156+
}
157+
140158
func TestGitOps_CloneFailurePreservesExistingNonRepoDir(t *testing.T) {
141159
destRoot := t.TempDir()
142160
ns := "test-ns"

0 commit comments

Comments
 (0)