Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(cli): remove .git folder when creating project from git template#13239

Open
OlegHQ wants to merge 2 commits intoserverless:mainfrom
OlegHQ:fix/remove-git-folder-from-template
Open

fix(cli): remove .git folder when creating project from git template#13239
OlegHQ wants to merge 2 commits intoserverless:mainfrom
OlegHQ:fix/remove-git-folder-from-template

Conversation

@OlegHQ
Copy link

@OlegHQ OlegHQ commented Jan 9, 2026

When creating a project from a git template URL, the .git folder is copied to the new project, causing git to track the template repository instead of being ready for a new repository.

This change removes the .git folder after cloning the template, so the new project starts fresh without any git history.

Verification

Environment: Darwin (arm64)
Runtime: Node.js v24.11.1

Test Steps

  1. npm install
  2. npm run test:unit -w @serverlessinc/sf-core -- --testPathPattern=download.test

Results

Test Suites: 24 passed, 24 total
Tests: 368 passed, 368 total

All unit tests pass, including new tests that verify the .git folder removal behavior.

Closes: #11978

OlegHQ added 2 commits January 9, 2026 22:40
When using `--template-url` with a plain Git URL (e.g., [email protected]:...
or https://example.com/repo.git), the template is cloned via git clone.
Previously, the .git folder was left in the new project, causing it to
point to the template repository instead of being a fresh project.

This change:
- Adds git clone support for plain Git URLs (both HTTPS and SSH)
- Removes the .git folder after cloning to disassociate from template repo
- Handles SSH URLs (git@...) that cannot be parsed as standard URLs
- Adds test coverage for the new git clone and .git removal behavior

Fixes serverless#11978
- Replace child_process.exec() with spawn() using array arguments
- Add input validation to reject URLs with shell metacharacters
- Remove console.error in favor of silent error handling
- Add test for command injection prevention
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Mmarzex
Copy link
Contributor

Mmarzex commented Jan 9, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@OlegHQ
Copy link
Author

OlegHQ commented Jan 9, 2026

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

creating a project from private git repo copies the .git folder

2 participants