Skip to content

Commit

Permalink
fix: support windows path on commits with \\
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Sep 16, 2021
1 parent 4339e46 commit 5712af4
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/shared/localShadowRepo.ts
Expand Up @@ -6,7 +6,7 @@
*/
/* eslint-disable no-console */

import { join as pathJoin, normalize } from 'path';
import * as path from 'path';
import * as os from 'os';
import * as fs from 'fs';
import { AsyncCreatable } from '@salesforce/kit';
Expand All @@ -17,11 +17,11 @@ import * as git from 'isomorphic-git';
* returns the full path to where we store the shadow repo
*/
const getGitDir = (orgId: string, projectPath: string): string => {
return pathJoin(projectPath, '.sfdx', 'orgs', orgId, 'localSourceTracking');
return path.join(projectPath, '.sfdx', 'orgs', orgId, 'localSourceTracking');
};

const toFilenames = (rows: StatusRow[]): string[] =>
os.type() === 'Windows_NT' ? rows.map((row) => normalize(row[FILE])) : rows.map((row) => row[FILE]);
// filenames were normalized when read from isogit
const toFilenames = (rows: StatusRow[]): string[] => rows.map((row) => row[FILE]);

interface ShadowRepoOptions {
orgId: string;
Expand Down Expand Up @@ -106,8 +106,11 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
gitdir: this.gitDir,
filepaths: this.packageDirs.map((dir) => dir.path),
// filter out hidden files and __tests__ patterns, regardless of gitignore
filter: (f) => !f.includes('/.') && !f.includes('__tests__'),
filter: (f) => !f.includes(`${path.sep}.`) && !f.includes('__tests__'),
});
if (os.type() === 'Windows_NT') {
this.status = this.status.map((row) => [path.normalize(row[FILE]), row[HEAD], row[WORKDIR], row[3]]);
}
await this.unStashIgnoreFile();
}
return this.status;
Expand Down Expand Up @@ -192,9 +195,10 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {

await this.stashIgnoreFile();

// these are stored in posix/style/path format. We have to convert inbound stuff from windows
if (os.type() === 'Windows_NT') {
deployedFiles = deployedFiles.map((filepath) => normalize(filepath));
deployedFiles = deletedFiles.map((filepath) => normalize(filepath));
deployedFiles = deployedFiles.map((filepath) => path.normalize(filepath).split(path.sep).join(path.posix.sep));
deployedFiles = deletedFiles.map((filepath) => path.normalize(filepath).split(path.sep).join(path.posix.sep));
}

try {
Expand All @@ -220,14 +224,20 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
private async stashIgnoreFile(): Promise<void> {
if (!this.stashed) {
this.stashed = true;
await fs.promises.rename(pathJoin(this.projectPath, '.gitignore'), pathJoin(this.projectPath, '.BAK.gitignore'));
await fs.promises.rename(
path.join(this.projectPath, '.gitignore'),
path.join(this.projectPath, '.BAK.gitignore')
);
}
}

private async unStashIgnoreFile(): Promise<void> {
if (this.stashed) {
this.stashed = false;
await fs.promises.rename(pathJoin(this.projectPath, '.BAK.gitignore'), pathJoin(this.projectPath, '.gitignore'));
await fs.promises.rename(
path.join(this.projectPath, '.BAK.gitignore'),
path.join(this.projectPath, '.gitignore')
);
}
}
}

0 comments on commit 5712af4

Please sign in to comment.