Skip to content
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

Detect file moves in local source tracking #574

Merged
merged 46 commits into from
May 15, 2024
Merged

Detect file moves in local source tracking #574

merged 46 commits into from
May 15, 2024

Conversation

iowillhoit
Copy link
Contributor

@iowillhoit iowillhoit commented May 3, 2024

What does this PR do?

when a file is moved from one location to another within a project (ex: from force-app/main/default/classes to other-dir/classes) but has the same filename and content, it is NOT considered an add and a delete. Source tracking updates its local filesystem tracking to "clear" those changes.

This does not apply if you move files between different parents (ex: moving a field from Foo__c to Bar__c) or moving a file from one LWC to another--that still counts as an add a delete.

What issues does this PR fix or reference?

forcedotcom/cli#2682
@W-15354803@

src/shared/localShadowRepo.ts Outdated Show resolved Hide resolved
src/shared/localShadowRepo.ts Show resolved Hide resolved
const message = 'Files were found that have the same basename and hash. Skipping the commit of these files';
this.logger.warn(message);
await Lifecycle.getInstance().emitWarning(message);
await Lifecycle.getInstance().emitTelemetry({ eventName: 'moveFileHashBasenameCollisionsDetected' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're capturing telemetry anyway, let's capture the filenames

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're capturing telemetry anyway, let's capture the filenames.

and always Promise.all unrelated consecutive awaits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "ignore" Maps will not contain all of the filenames since we are "setting" over the top of the new values as we go. We could add some more logic to calculate them, but i don't know if it is worth the extra complexity. Telemetry will let us know how often this happens

src/shared/localShadowRepo.ts Show resolved Hide resolved
@iowillhoit iowillhoit changed the title WIP: File moves Detect file moves in local source tracking May 8, 2024
@mshanemc
Copy link
Contributor

mshanemc commented May 8, 2024

QA notes:
using deploy-retrieve 3.6.12-dev.2 (dev) w/ dreamhouse. Unless otherwise stated, using deploy preview to not bother the org about this stuff.

preview looks good before a deploy.
✅ running both this change and regular, the result is consistently 91 items to deploy.

retrieve preview
✅ shows empty, as does current

actual deploy
✅ correct, matches current sf
preview after deploy
✅ correct, matches current sf

create new packageDir and move a file to the same dir over there (other-dir/classes/FileUtilities.cls and its cls.-meta.xml)
✅ shows no changes.
📓 we should probably tell people in the instructions to keep stuff like that together

move GeoCodingService files the same way, with SF_LOG_LEVEL=trace DEBUG=* sf project deploy preview to view logs

[16:30:13.767] TRACE (sf:ShadowRepo): start: getStatus (noCache = false)
[16:30:13.800] TRACE (sf:ShadowRepo): start: getStatus (noCache = false)
[16:30:13.800] TRACE (sf:ShadowRepo): done: getStatus (noCache = false)
[16:30:13.848] DEBUG (sf:ShadowRepo): Files have moved. Committing moved files:
[16:30:13.848] DEBUG (sf:ShadowRepo): File 'force-app/main/default/classes/GeocodingServiceTest.cls' was moved to 'other-dir/classes/GeocodingServiceTest.cls'
File 'force-app/main/default/classes/GeocodingServiceTest.cls-meta.xml' was moved to 'other-dir/classes/GeocodingServiceTest.cls-meta.xml'
[16:30:13.848] DEBUG (sf:ShadowRepo): adding 2 files of 2 deployedFiles to git
[16:30:13.864] TRACE (sf:ShadowRepo): start: commitChanges git.commit
[16:30:13.885] TRACE (sf:ShadowRepo): start: getStatus (noCache = true)
[16:30:13.911] TRACE (sf:ShadowRepo): start: getStatus (noCache = false)
[16:30:13.911] TRACE (sf:ShadowRepo): done: getStatus (noCache = false)
[16:30:13.911] TRACE (sf:ShadowRepo): done: getStatus (noCache = true)
[16:30:13.911] TRACE (sf:ShadowRepo): done: commitChanges git.commit
[16:30:13.911] TRACE (sf:ShadowRepo): done: getStatus (noCache = false)

📓 the seems like a lot of getStatus being called. At least they're fast.

renaming an existing file [should still show up as a add + delete]
✅ yep
Screenshot 2024-05-08 at 4 39 31 PM
✅ put the name back and it disappears

moving a field from 1 custom object to another (test case from @VivekMChawla)
❌ removes from tracking. It probably shouldn't

File 'force-app/main/default/objects/Broker__c/fields/Title__c.field-meta.xml' was moved to 'force-app/main/default/objects/Property__c/fields/Title__c.field-meta.xml'

move an unresolvable file (README.md moved from force-app/main/default/objects/ to other-dir/classes/
✅ doesn't show up when created in force-app
✅ doesn't show up when moved

move an entire bundle

  • make lwc folder in other-dir (✅ preview works fine with empty folder)
  • move PropertySummary to new lwc folder
  • original lists the original LWC (📓 but twice, probably the result of various files resolving to the meta.xml. We should probably deduplicate those when type+path+fullname match)
Will Deploy [2] files.
 Type                     Fullname        Path                                                      
 ──────────────────────── ─────────────── ───────────────────────────────────────────────────────── 
 LightningComponentBundle propertySummary other-dir/lwc/propertySummary/propertySummary.js-meta.xml 
 LightningComponentBundle propertySummary other-dir/lwc/propertySummary/propertySummary.js-meta.xml 

✅ moving a whole LWC gives you the expected results and logs

File 'force-app/main/default/lwc/propertyLocation/propertyLocation.html' was moved to 'other-dir/lwc/propertyLocation/propertyLocation.html'
File 'force-app/main/default/lwc/propertyLocation/propertyLocation.js' was moved to 'other-dir/lwc/propertyLocation/propertyLocation.js'
File 'force-app/main/default/lwc/propertyLocation/propertyLocation.js-meta.xml' was moved to 'other-dir/lwc/propertyLocation/propertyLocation.js-meta.xml'

move customLabels file
✅ expected output, expected logs

deploy preview where we move a file and it's changed in the org [expect a conflict in the new location]

  • move customlabels AND edit it in the org
    ✅ shows as a retrieve from org (no conflict!)

@iowillhoit iowillhoit requested a review from a team as a code owner May 10, 2024 21:06
@mshanemc
Copy link
Contributor

QA notes:

✅ copy paste is treated as an add
✅ move classes to a different dir
✅ move a field from one obj in force-app to another
✅ move the entire object into other-dir
✅ move one field back to an empty object in force-app

@@ -75,5 +79,7 @@ describe('it detects image file moves ', () => {
expect(await repo.getChangedFilenames())
.to.be.an('array')
.with.lengthOf(0);

delete process.env.SF_BETA_TRACK_FILE_MOVES;
Copy link
Contributor

@mshanemc mshanemc May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I have a slight preference for doing these in an before|afterEach so that they next test added doesn't have to remember to unset it.

@mshanemc
Copy link
Contributor

QA:
✅ tested with env true, false and not set

@mshanemc mshanemc merged commit 06fdb1b into main May 15, 2024
32 checks passed
@mshanemc mshanemc deleted the ew/file-moves branch May 15, 2024 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants