diff --git a/pkg/client/client.go b/pkg/client/client.go index 744b8a68..25d2bc65 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1036,6 +1036,10 @@ func (c *KpmClient) DownloadFromGit(dep *pkg.Git, localPath string) (string, err msg = fmt.Sprintf("with commit '%s'", dep.Commit) } + if len(dep.Branch) != 0 { + msg = fmt.Sprintf("with branch '%s'", dep.Branch) + } + reporter.ReportMsgTo( fmt.Sprintf("cloning '%s' %s", dep.Url, msg), c.logWriter, diff --git a/pkg/cmd/cmd_update.go b/pkg/cmd/cmd_update.go index 32a2acc0..6cec4285 100644 --- a/pkg/cmd/cmd_update.go +++ b/pkg/cmd/cmd_update.go @@ -10,7 +10,6 @@ import ( "slices" "strings" - "github.com/dominikbraun/graph" "github.com/urfave/cli/v2" "golang.org/x/mod/module" "kcl-lang.io/kpm/pkg/client" @@ -131,8 +130,8 @@ func KpmUpdate(c *cli.Context, kpmcli *client.KpmClient) error { // GetModulesToUpdate validates if the packages is present in kcl.mod file and // find the latest version if version is not specified. Depending on the value of pkgVersion, -// modulesToUpgrade or modulesToDowngrade will be updated. -func GetModulesToUpdate(kclPkg *pkg.KclPkg, modulesToUpgrade []module.Version, modulesToDowngrade []module.Version, pkgInfo string) error { +// modulesToUpgrade or modulesToDowngrade will be updated. +func GetModulesToUpdate(kclPkg *pkg.KclPkg, modulesToUpgrade []module.Version, modulesToDowngrade []module.Version, pkgInfo string) error { pkgInfo = strings.TrimSpace(pkgInfo) pkgName, pkgVersion, err := ParseOciPkgNameAndVersion(pkgInfo) if err != nil { @@ -172,9 +171,9 @@ func GetModulesToUpdate(kclPkg *pkg.KclPkg, modulesToUpgrade []module.Version, return nil } -// InsertModuleToDeps checks whether module is present in the buildList and it is not the same as the target module, +// InsertModuleToDeps checks whether module is present in the buildList and it is not the same as the target module, // and inserts it to the dependencies of kclPkg -func InsertModuleToDeps(kclPkg *pkg.KclPkg, module module.Version, target module.Version, buildList []module.Version, reqs mvs.ReqsGraph) (error) { +func InsertModuleToDeps(kclPkg *pkg.KclPkg, module module.Version, target module.Version, buildList []module.Version, reqs mvs.ReqsGraph) error { if module.Path == target.Path || !slices.Contains(buildList, module) { return nil } @@ -196,4 +195,4 @@ func InsertModuleToDeps(kclPkg *pkg.KclPkg, module module.Version, target module } kclPkg.ModFile.Dependencies.Deps[module.Path] = d return nil -} \ No newline at end of file +} diff --git a/pkg/package/toml.go b/pkg/package/toml.go index c21ef54b..230c79a4 100644 --- a/pkg/package/toml.go +++ b/pkg/package/toml.go @@ -118,6 +118,7 @@ func (source *Source) MarshalTOML() string { const GIT_URL_PATTERN = "git = \"%s\"" const TAG_PATTERN = "tag = \"%s\"" const GIT_COMMIT_PATTERN = "commit = \"%s\"" +const GIT_BRANCH_PATTERN = "branch = \"%s\"" const VERSION_PATTERN = "version = \"%s\"" const SEPARATOR = ", " @@ -134,6 +135,12 @@ func (git *Git) MarshalTOML() string { sb.WriteString(SEPARATOR) sb.WriteString(fmt.Sprintf(GIT_COMMIT_PATTERN, git.Commit)) } + + if len(git.Branch) != 0 { + sb.WriteString(SEPARATOR) + sb.WriteString(fmt.Sprintf(GIT_BRANCH_PATTERN, git.Branch)) + } + if len(git.Version) != 0 { sb.WriteString(SEPARATOR) sb.WriteString(fmt.Sprintf(VERSION_PATTERN, git.Version)) @@ -367,6 +374,7 @@ func (source *Source) UnmarshalModTOML(data interface{}) error { const GIT_URL_FLAG = "git" const TAG_FLAG = "tag" const GIT_COMMIT_FLAG = "commit" +const GIT_BRANCH_FLAG = "branch" func (git *Git) UnmarshalModTOML(data interface{}) error { meta, ok := data.(map[string]interface{}) @@ -386,6 +394,10 @@ func (git *Git) UnmarshalModTOML(data interface{}) error { git.Commit = v } + if v, ok := meta[GIT_BRANCH_FLAG].(string); ok { + git.Branch = v + } + return nil } diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.env b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.env new file mode 100644 index 00000000..4c789529 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.env @@ -0,0 +1,2 @@ +KPM_HOME="" +KCLVM_VENDOR_HOME="" \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.input b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.input new file mode 100644 index 00000000..b69acba6 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.input @@ -0,0 +1 @@ +kpm --quiet run \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.stderr new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.stdout new file mode 100644 index 00000000..a2969d68 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_git_branch_dep/test_suite.stdout @@ -0,0 +1,17 @@ +a: + name: flask-demo + replicas: 1 + labels: + app: flask-demo + service: + type: NodePort + ports: + - port: 5000 + protocol: TCP + targetPort: 5000 + containers: + flaskdemo: + image: kcllang/flask_demo:8d31498e765ff67a2fa9933d4adffe067544b2fe + ports: + - protocol: TCP + containerPort: 5000 \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/kcl.mod new file mode 100644 index 00000000..875403f9 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "test_kpm_run_with_git_commit_dep" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", branch = "main" } diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/kcl.mod.lock new file mode 100644 index 00000000..4219f34d --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/kcl.mod.lock @@ -0,0 +1,7 @@ +[dependencies] + [dependencies.flask-demo-kcl-manifests] + name = "flask-demo-kcl-manifests" + full_name = "flask_manifests_0.0.1" + version = "0.0.1" + url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git" + branch = "main" diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/main.k b/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/main.k new file mode 100644 index 00000000..3d8edb2c --- /dev/null +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_git_branch_dep/main.k @@ -0,0 +1,3 @@ +import flask_demo_kcl_manifests as flask + +a = flask.config \ No newline at end of file