Skip to content

fix: auto-match layout template tag to CLI version in kratos new - #3870

Open
waterWang wants to merge 3 commits into
go-kratos:mainfrom
waterWang:fix/kratos-new-version-match
Open

fix: auto-match layout template tag to CLI version in kratos new#3870
waterWang wants to merge 3 commits into
go-kratos:mainfrom
waterWang:fix/kratos-new-version-match

Conversation

@waterWang

Copy link
Copy Markdown

Description

Fixes #3868

Bug 1: Template version doesn't match CLI version

When using kratos new (e.g. v2.9.2 CLI), the command always clones the main branch of kratos-layout, which currently contains the v3 template. This causes a mismatch: a v2.x CLI generates a v3 project template.

Fix: Inject the CLI version (release) into the project package via project.CLIVersion. When no explicit -b flag is given and the default service layout is used, the layout tag is automatically matched to the CLI version (e.g. CLI v2.9.2 → tag v2.9.2).

Bug 2: -b v2.9.2 (tag) fails on repeated runs

When -b is a tag, git clone -b <tag> checks out a detached HEAD. The Pull() method in repo.go calls git symbolic-ref HEAD which fails on detached HEAD, causing kratos new to fail on the second project creation.

Fix: In Pull(), when git symbolic-ref HEAD fails (detached HEAD), fall back to git fetch origin <ref> + git checkout <ref> instead of returning an error.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kratos 命令行工具创建的模板与自身版本不匹配

1 participant