-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: handle file move then edit scenario #601
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
da3448a
chore: oclif perf import from top-level
mshanemc 7ba53ae
feat: handle the move-then-modify scenario
mshanemc 1d5e9d0
Merge remote-tracking branch 'origin/main' into sm/file-moves-again
mshanemc 3e2ea76
test: update ut for behavior change
mshanemc ef0b1bd
refactor: reduce instanceof in favor of union narrowing
mshanemc 776c49a
Merge remote-tracking branch 'origin/main' into sm/file-moves-again
mshanemc be3a67a
test: nut unique test names, do session cleanup
mshanemc 78ac637
chore: merge conflicts
iowillhoit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import * as path from 'node:path'; | ||
import { TestSession } from '@salesforce/cli-plugins-testkit'; | ||
import { expect } from 'chai'; | ||
import * as fs from 'graceful-fs'; | ||
import { RegistryAccess } from '@salesforce/source-deploy-retrieve'; | ||
import { ProjectJson } from '@salesforce/schemas'; | ||
import { NamedPackageDir, PackageDir } from '@salesforce/core'; | ||
import { ShadowRepo } from '../../../src/shared/local/localShadowRepo'; | ||
|
||
describe('handles local files moves that also change the file', () => { | ||
let session: TestSession; | ||
let repo: ShadowRepo; | ||
let modifiedPackageDirs: PackageDir[]; | ||
const NOT_PROJECT_DIR = 'not-project-dir'; | ||
before(async () => { | ||
session = await TestSession.create({ | ||
project: { | ||
sourceDir: path.join('test', 'nuts', 'ebikes-lwc'), | ||
}, | ||
devhubAuthStrategy: 'NONE', | ||
}); | ||
// create the other dir | ||
const notProjectDir = path.join(session.project.dir, NOT_PROJECT_DIR, 'main', 'default', 'classes'); | ||
await fs.promises.mkdir(notProjectDir, { recursive: true }); | ||
|
||
// modify the project json to include the new dir | ||
const sfdxProjectJsonPath = path.join(session.project.dir, 'sfdx-project.json'); | ||
const originalProject = JSON.parse(await fs.promises.readFile(sfdxProjectJsonPath, 'utf8')) as ProjectJson; | ||
modifiedPackageDirs = [...originalProject.packageDirectories, { path: NOT_PROJECT_DIR }]; | ||
await fs.promises.writeFile( | ||
sfdxProjectJsonPath, | ||
JSON.stringify({ | ||
...originalProject, | ||
packageDirectories: modifiedPackageDirs, | ||
} satisfies ProjectJson) | ||
); | ||
}); | ||
|
||
after(async () => { | ||
// await session?.clean(); | ||
}); | ||
|
||
it('initialize the local tracking', async () => { | ||
expect(typeof process.env.SF_BETA_TRACK_FILE_MOVES).to.equal('undefined'); | ||
process.env.SF_BETA_TRACK_FILE_MOVES = 'true'; | ||
|
||
repo = await ShadowRepo.getInstance({ | ||
orgId: 'fakeOrgId', | ||
projectPath: session.project.dir, | ||
packageDirs: modifiedPackageDirs.map( | ||
(pd): NamedPackageDir => ({ ...pd, name: NOT_PROJECT_DIR, fullPath: path.join(session.project.dir, pd.path) }) | ||
), | ||
registry: new RegistryAccess(), | ||
}); | ||
|
||
// Commit the existing status | ||
const filesToSync = await repo.getChangedFilenames(); | ||
await repo.commitChanges({ deployedFiles: filesToSync }); | ||
|
||
expect(await repo.getChangedFilenames()).to.have.lengthOf(0); | ||
}); | ||
|
||
it('move a file and edit it. Only the delete is committed', async () => { | ||
// move all two classes to the new folder | ||
const classFolder = path.join('main', 'default', 'classes'); | ||
['OrderController.cls', 'OrderController.cls-meta.xml', 'PagedResult.cls', 'PagedResult.cls-meta.xml'].map((f) => | ||
fs.renameSync( | ||
path.join(session.project.dir, 'force-app', classFolder, f), | ||
path.join(session.project.dir, NOT_PROJECT_DIR, classFolder, f) | ||
) | ||
); | ||
const editedFilePath = path.join(NOT_PROJECT_DIR, classFolder, 'OrderController.cls'); | ||
// edit the contents of OrderController.cls | ||
fs.appendFileSync(path.join(session.project.dir, editedFilePath), '//comment'); | ||
await repo.getStatus(true); | ||
|
||
// all the deletes were committed | ||
expect(await repo.getDeleteFilenames()).to.deep.equal([]); | ||
// this is still considered an "add" because the moved file was changed | ||
expect(await repo.getAddFilenames()).to.deep.equal([editedFilePath]); | ||
|
||
delete process.env.SF_BETA_TRACK_FILE_MOVES; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the more complex result object, this made more sense to handle outside the ShadowRepo class