fix: use unique names for initial commits (cherry-pick #27171 for 3.4) (#27198)

Signed-off-by: Sean Liao <sean@liao.dev>
Co-authored-by: Sean Liao <sean@liao.dev>
This commit is contained in:
argo-cd-cherry-pick-bot[bot] 2026-04-06 16:47:33 -04:00 committed by GitHub
parent 33247b96fe
commit 0a29bfd093
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -1045,7 +1045,7 @@ func (m *nativeGitClient) CheckoutOrOrphan(branch string, submoduleEnabled bool)
}
// Make an empty initial commit.
out, err = m.runCmd(ctx, "commit", "--allow-empty", "-m", "Initial commit")
out, err = m.runCmd(ctx, "commit", "--allow-empty", "-m", "Initial commit for "+branch)
if err != nil {
return out, fmt.Errorf("failed to commit initial commit: %w", err)
}

View file

@ -697,6 +697,11 @@ func Test_nativeGitClient_CheckoutOrOrphan(t *testing.T) {
currentCommitHash := strings.TrimSpace(string(gitCurrentCommitHash))
require.NotEqual(t, baseCommitHash, currentCommitHash)
gitCurrentCommitMessage, err := outputCmd(ctx, tempDir, "git", "log", "--format=%B", "-n", "1", "HEAD")
require.NoError(t, err)
currentCommitMessage := strings.TrimSpace(string(gitCurrentCommitMessage))
require.Contains(t, currentCommitMessage, expectedBranch)
// get commit count on current branch, verify 1 -> orphan
gitCommitCount, err := outputCmd(ctx, tempDir, "git", "rev-list", "--count", actualBranch)
require.NoError(t, err)