Skip to content

push_repo_memory fails with sparse-checkout error on first run when creating orphan branch #23558

@jaroslawgajewski

Description

@jaroslawgajewski

Problem Description

The push_repo_memory.cjs script fails when the target memory branch doesn't exist yet and needs to create an orphan branch. The failure occurs during the git add . step with a sparse-checkout error.

Error Message

Root Cause

The script correctly runs git sparse-checkout disable at line 125 before branch operations
When the target memory branch doesn't exist, it creates an orphan branch via git checkout --orphan (line 144)
The git checkout --orphan + git rm -rf . sequence resets the Git working tree state and re-enables sparse-checkout behavior
The subsequent git add . (line 328) fails because files fall outside the sparse-checkout definition
Steps to Reproduce
Set up a repository with sparse-checkout enabled during initial checkout
Run a workflow that uses push_repo_memory with a memory branch name that doesn't exist yet
The script will attempt to create an orphan branch and stage files
git add . fails with sparse-checkout error

Expected Behavior

The script should successfully stage and commit files to the new orphan memory branch regardless of sparse-checkout configuration.

Actual Behavior

The script fails with a Git sparse-checkout error when trying to stage files.

Workaround

The issue only occurs on the first run for a given memory branch. Subsequent runs succeed because:

The branch already exists (no orphan branch creation needed)
If no changes are detected, the script exits early before hitting git add .

Proposed Solution

Add a second git sparse-checkout disable after orphan branch creation in push_repo_memory.cjs:

// Line 147, after orphan branch creation:execGitSync(["rm", "-r", "-f", "--ignore-unmatch", "."], { stdio: "pipe" });// Re-disable sparse checkout - orphan branch creation can re-activate it  try {  execGitSync(["sparse-checkout", "disable"], { stdio: "pipe" });} catch (_) {  // safe to ignore if sparse-checkout wasn't enabled}core.info(`Created orphan branch: ${branchName}`);

Alternative: Change git add . to git add --sparse . at line 328 to explicitly allow staging files outside sparse-checkout definition.

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions