fix: ignore .git folder on template download - #13702
Conversation
Fixes serverless#11978. When downloading a template, specifically via --template-url, we should ensure the .git directory is not included so the new project doesn't inherit the remote of the template.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesTemplate cleanup
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
I have read the CLA Document and I hereby sign the CLA |
marceli1404
left a comment
There was a problem hiding this comment.
The change is minimal and safe — removeFileOrDirectory swallows ENOENT (verified in packages/sf-core/src/utils/fs/index.js), so this is a no-op when .git isn't present, and placing it after copyDirContents covers the case where the template source contains a .git directory.
A few suggestions:
-
Verify the repro path: the archive-zip downloads for GitHub (
/archive/<branch>.zip), Bitbucket (/get/<branch>.zip) and GitLab (/-/archive/) generally exclude.git. For a plain git URL (e.g.git@bitbucket.org:team/repo.git),parsePlainGitURLreturns the raw URL asdownloadUrlanddownloadDataFromUrifetches it directly — so it's worth confirming which input from #11978 actually produces a.gitin the downloaded content, to make sure this fix addresses the real source. -
Test:
tests/unit/utils/https/download.test.jsalready mocksremoveFileOrDirectory— an easy, meaningful assertion would be that it's called withpath.join(newServicePath, '.git')during a successful download. -
Minor: alternatively
.gitcould be filtered out of the sourcedirectorybeforecopyDirContents, but the post-copy removal is simpler and equally correct.
Fixes #11978
When downloading a template via
--template-url, the.gitdirectory from the repository was being copied over, meaning the new project erroneously inherited the remote of the template repository. This fix ensures the.gitfolder is removed upon template download.Summary by CodeRabbit
.gitmetadata from the source template.