Skip to content

Commit 09dacc9

Browse files
committed
fix: handle stash failures
1 parent ee59907 commit 09dacc9

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

README.md

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@ You should use the class named sourceTracking.
1515

1616
## TODO
1717

18-
NUT for compatibility checks
18+
NUT for tracking file compatibility check logic
1919
pollSourceMembers should better handle aggregated types. ex:
2020

2121
```
22-
DEBUG Could not find 2 SourceMembers: AuraDefinition__pageTemplate_2_7_3/pageTemplate_2_7_3.cmp-meta.xml,[object Object],CustomObject__Account,[object Object]
22+
DEBUG Could not find 2 SourceMembers (using ebikes): AuraDefinition__pageTemplate_2_7_3/pageTemplate_2_7_3.cmp-meta.xml,[object Object],CustomObject__Account,[object Object]
2323
```
2424

25-
push/pull throw on conflict, but don't provide errors for --json
26-
27-
- SDR sets all retrieve FileResponse as `Changed` even if it didn't exist locally. That's going to yield slightly different json output on a `pull` than toolbelt did. See `remoteChanges.nut.ts > remote changes:add > can pull the add`. Fixing in pull is less optimal than fixing in SDR (because source:retrieve is also currently reporting those as `Changed` instead of `Created`)
28-
work around our gitignore stash trick...sometimes it gets in the incomplete state. What if there is no gitignore? All kinds of error handling issues around that
29-
3025
### Enhancements
3126

32-
- status can "mark ignores"
33-
- why does push take so long?
3427
- for updating ST after deploy/retrieve, we need a quick way for those commands to ask, "is this an ST org?" OR a graceful "ifSupported" wrapper for those methods.
3528
- ensureRemoteTracking could have 2 options in an object
3629
1. `ensureQueryHasReturned` which will make sure the query has run at least once

src/shared/localShadowRepo.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
5050
private packageDirs!: NamedPackageDir[];
5151
private status!: StatusRow[];
5252
private logger!: Logger;
53-
private stashed = false;
5453
private options: ShadowRepoOptions;
5554

5655
public constructor(options: ShadowRepoOptions) {
@@ -80,10 +79,16 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
8079
await git.init({ fs, dir: this.projectPath, gitdir: this.gitDir, defaultBranch: 'main' });
8180
}
8281

82+
/**
83+
* Delete the local tracking files
84+
*
85+
* @returns the deleted directory
86+
*/
8387
public async delete(): Promise<string> {
8488
if (typeof fs.promises.rm === 'function') {
8589
await fs.promises.rm(this.gitDir, { recursive: true, force: true });
8690
} else {
91+
// when node 12 support is over, switch to promise version
8792
fs.rmdirSync(this.gitDir, { recursive: true });
8893
}
8994
return this.gitDir;
@@ -108,6 +113,7 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
108113
// filter out hidden files and __tests__ patterns, regardless of gitignore
109114
filter: (f) => !f.includes(`${path.sep}.`) && !f.includes('__tests__'),
110115
});
116+
// isomorphic-git stores things in unix-style tree. Convert to windows-style if necessary
111117
if (os.type() === 'Windows_NT') {
112118
this.status = this.status.map((row) => [path.normalize(row[FILE]), row[HEAD], row[WORKDIR], row[3]]);
113119
}
@@ -222,22 +228,18 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
222228
}
223229

224230
private async stashIgnoreFile(): Promise<void> {
225-
if (!this.stashed) {
226-
this.stashed = true;
227-
await fs.promises.rename(
228-
path.join(this.projectPath, '.gitignore'),
229-
path.join(this.projectPath, '.BAK.gitignore')
230-
);
231+
const originalLocation = path.join(this.projectPath, '.gitignore');
232+
// another process may have already stashed the file
233+
if (fs.existsSync(originalLocation)) {
234+
await fs.promises.rename(originalLocation, path.join(this.projectPath, '.BAK.gitignore'));
231235
}
232236
}
233237

234238
private async unStashIgnoreFile(): Promise<void> {
235-
if (this.stashed) {
236-
this.stashed = false;
237-
await fs.promises.rename(
238-
path.join(this.projectPath, '.BAK.gitignore'),
239-
path.join(this.projectPath, '.gitignore')
240-
);
239+
const stashedLocation = path.join(this.projectPath, '.gitignore');
240+
// another process may have already un-stashed the file
241+
if (fs.existsSync(stashedLocation)) {
242+
await fs.promises.rename(stashedLocation, path.join(this.projectPath, '.gitignore'));
241243
}
242244
}
243245
}

0 commit comments

Comments
 (0)