From 6869e4c3e28c6ca5269ada83258a17f8df321d93 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 21 Jan 2026 12:09:22 +0000 Subject: [PATCH] fix(cli): always skip branch-specific files when not on matching branch Branch-specific files (folder.dev.meta.yaml, settings.main.yaml, etc.) should ALWAYS be skipped if: 1. Not on any git branch 2. On a different branch than the file's branch name Previously, this filtering only happened when specificItems was configured. Now it applies unconditionally based on the file naming convention. Also refactored the path mapping logic to be clearer: - Branch-specific files for current branch -> map to base path - Regular base files -> add to map (unless it's a specific item) - Branch-specific files for other branches -> filtered out earlier Co-Authored-By: Claude Opus 4.5 --- cli/src/commands/sync/sync.ts | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/cli/src/commands/sync/sync.ts b/cli/src/commands/sync/sync.ts index 530a39831c..0986b2c5c3 100644 --- a/cli/src/commands/sync/sync.ts +++ b/cli/src/commands/sync/sync.ts @@ -1350,10 +1350,12 @@ export async function elementsToMap( // If getTypeStrFromPath can't determine the type, continue processing the file } - // Handle branch-specific files - skip files for other branches - if (specificItems && isBranchSpecificFile(path)) { + // Handle branch-specific files - ALWAYS skip files that don't match current branch + // This applies regardless of specificItems config - branch-specific files by naming + // convention should only be processed when on the matching branch + if (isBranchSpecificFile(path)) { if (!isCurrentBranchFile(path, branchOverride)) { - // Skip branch-specific files for other branches + // Skip branch-specific files for other branches (or when not on any branch) continue; } } @@ -1387,36 +1389,34 @@ export async function elementsToMap( } // Handle branch-specific path mapping after all filtering - if (specificItems) { - if (isCurrentBranchFile(path, branchOverride)) { - // This is a branch-specific file for current branch - // Safe to compute branch here since isCurrentBranchFile already validated it exists - const currentBranch = branchOverride || getCurrentGitBranch()!; - const basePath = fromBranchSpecificPath(path, currentBranch); - if (isSpecificItem(basePath, specificItems)) { - // Map to base path for push operations - map[basePath] = content; - processedBasePaths.add(basePath); - } else { - // Branch-specific file doesn't match pattern, skip it - continue; - } - } else if (!isBranchSpecificFile(path)) { - // This is a regular base file - if (processedBasePaths.has(path)) { - // Skip base file, we already processed branch-specific version - continue; - } - // If this base file is a specific item, skip it - we should only use branch-specific versions - if (isSpecificItem(path, specificItems)) { - continue; - } - map[path] = content; + if (isCurrentBranchFile(path, branchOverride)) { + // This is a branch-specific file for current branch - map to base path + const currentBranch = branchOverride || getCurrentGitBranch()!; + const basePath = fromBranchSpecificPath(path, currentBranch); + + // If specificItems is configured, only process if it matches the pattern + if (specificItems && !isSpecificItem(basePath, specificItems)) { + // Branch-specific file doesn't match pattern, skip it + continue; } - } else { - // No specific items configuration, use regular path - map[entry.path] = content; + + // Map to base path for push operations + map[basePath] = content; + processedBasePaths.add(basePath); + } else if (!isBranchSpecificFile(path)) { + // This is a regular base file + if (processedBasePaths.has(path)) { + // Skip base file, we already processed branch-specific version + continue; + } + // If specificItems is configured and this is a specific item, skip it + // (we should only use branch-specific versions for specific items) + if (specificItems && isSpecificItem(path, specificItems)) { + continue; + } + map[path] = content; } + // Note: branch-specific files for other branches are already filtered out above } return map; }