Skip to content

Commit

Permalink
fix(blueprint): Handle file names with spaces during resynth (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
aggagen authored Oct 11, 2023
1 parent 54aa552 commit c98b263
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/blueprints/blueprint/src/differences/differences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ export function generateDifferencePatch(intendedOldFile: string, intendedNewFile
}

// todo clean up in the future to use a stream
let rawDiff = cp.execSync([
'git',
'diff',
'--binary',
'--no-index',
oldFile,
newFile,
'| cat',
].join(' '), { maxBuffer: 999_990_999_999 }).toString();
const args = ['diff', '--binary', '--no-index', oldFile, newFile];
const diffCommand = cp.spawnSync('git', args, { maxBuffer: 999_990_999_999 });
if (diffCommand.error) {
throw new Error(`git diff failed: ${diffCommand.error}`);
}

// git diff returns 0 if there is no diff and 1 if there is a diff. Otherwise, the status indicates an
// error:
if (diffCommand.status !== 0 && diffCommand.status !== 1) {
throw new Error(`git diff failed: ${diffCommand.stderr.toString()}`);
}

let rawDiff = diffCommand.stdout.toString();
if (rawDiff.length) {
rawDiff = rawDiff.replace(/^(.*)$/m, `diff --git a/${destination} b/${destination}`);
rawDiff = rawDiff.replace(`--- a${oldFile}`, `--- a/${destination}`);
Expand All @@ -39,4 +42,4 @@ export function writeDifferencePatch(bundle: string, identifier: string, filePat
const diffPath = path.join(bundle, BUNDLE_PATH_SRC_DIFF, identifier, filePath);
fs.mkdirSync(path.dirname(diffPath), { recursive: true });
fs.writeFileSync(diffPath, patch);
}
}

0 comments on commit c98b263

Please sign in to comment.