Squash commit history for custom project template imports
What does this MR do and why?
Squash commit history for custom project template imports
Contributes to #351032 (closed)
Problem
Custom group and instance-level project templates retain full commit history when used to create new projects. This differs from built-in templates which compress everything into a single commit, causing inconsistent behavior and potential exposure of unwanted commit history.
Solution
Add RepositorySquashRestorer that runs during import of custom
template projects. After the repository is restored from the bundle,
it squashes the history into 2 commits: the original initial commit
plus a squashed commit containing all content from HEAD. This matches
built-in template behavior.
Key changes:
- Add
squash_commitsandinitial_commitmethods to Repository model - Add
initial_commitmethod toGitlab::Git::Repository - Create
RepositorySquashRestorerclass in EE - Modify EE
Importerto include squash restorer for template imports
References
- Issue: #351032 (closed)
- Built-in template squashing script:
scripts/vendor_template
Screenshots or screen recordings
| Before | After |
|---|---|
|
|
|
|
How to set up and validate locally
- Create a group and configure it as a custom project template group (Admin > Settings > Templates)
- Create a project in that group with multiple commits
- Create a new project using that template
- Verify the new project has only 2 commits:
- The original initial commit from the template
- A squashed commit with message "Initialize from template: <project_name>"
- Verify all files from the template are present in the new project
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.



