From b33d6b22437cf833ab427c7c8660f862c28dedc0 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Thu, 27 Jan 2022 16:54:42 -0700 Subject: [PATCH 1/2] Remove dependence on project, use cue.mod path. Ensure that we have done an init in this folder. Also, force a clean checkout of the tag we've chosen to upgrade to. Signed-off-by: Joel Longtine --- cmd/dagger/cmd/mod/get.go | 18 ++++++++++++++---- mod/repo.go | 3 ++- pkg/pkg.go | 6 +++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/cmd/dagger/cmd/mod/get.go b/cmd/dagger/cmd/mod/get.go index bcc48d15..08ae1efa 100644 --- a/cmd/dagger/cmd/mod/get.go +++ b/cmd/dagger/cmd/mod/get.go @@ -6,6 +6,8 @@ import ( "go.dagger.io/dagger/cmd/dagger/cmd/common" "go.dagger.io/dagger/cmd/dagger/logger" "go.dagger.io/dagger/mod" + "go.dagger.io/dagger/pkg" + "go.dagger.io/dagger/state" "go.dagger.io/dagger/telemetry" ) @@ -25,7 +27,15 @@ var getCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) + var err error + project := common.CurrentProject(ctx) + cueModPath := pkg.GetCueModParent() + // err = pkg.CueModInit(ctx, cueModPath) + _, err = state.Init(ctx, cueModPath) + if err != nil && err != state.ErrAlreadyInit { + lg.Fatal().Err(err).Msg("failed to initialize cue.mod") + } doneCh := common.TrackProjectCommand(ctx, cmd, project, nil, &telemetry.Property{ Name: "packages", Value: args, @@ -34,16 +44,16 @@ var getCmd = &cobra.Command{ var update = viper.GetBool("update") var processedRequires []*mod.Require - var err error + if update && len(args) == 0 { lg.Info().Msg("updating all installed packages...") - processedRequires, err = mod.UpdateInstalled(ctx, project.Path) + processedRequires, err = mod.UpdateInstalled(ctx, cueModPath) } else if update && len(args) > 0 { lg.Info().Msg("updating specified packages...") - processedRequires, err = mod.UpdateAll(ctx, project.Path, args) + processedRequires, err = mod.UpdateAll(ctx, cueModPath, args) } else if !update && len(args) > 0 { lg.Info().Msg("installing specified packages...") - processedRequires, err = mod.InstallAll(ctx, project.Path, args) + processedRequires, err = mod.InstallAll(ctx, cueModPath, args) } else { lg.Fatal().Msg("unrecognized update/install operation") } diff --git a/mod/repo.go b/mod/repo.go index efc894d3..c12f9f8e 100644 --- a/mod/repo.go +++ b/mod/repo.go @@ -84,7 +84,8 @@ func (r *repo) checkout(ctx context.Context, version string) error { } err = w.Checkout(&git.CheckoutOptions{ - Hash: *h, + Hash: *h, + Force: true, }) if err != nil { return err diff --git a/pkg/pkg.go b/pkg/pkg.go index c3dd2330..d4d96d0d 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -39,7 +39,7 @@ var ( func Vendor(ctx context.Context, p string) error { if p == "" { - p = getCueModParent() + p = GetCueModParent() } cuePkgDir := path.Join(p, "cue.mod", "pkg") @@ -141,8 +141,8 @@ func extractModules(dest string) error { }) } -// getCueModParent traverses the directory tree up through ancestors looking for a cue.mod folder -func getCueModParent() string { +// GetCueModParent traverses the directory tree up through ancestors looking for a cue.mod folder +func GetCueModParent() string { cwd, _ := os.Getwd() parentDir := cwd From 938444a08406d5e4454a92ea116a0587c0e5f81d Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 28 Jan 2022 10:09:38 -0700 Subject: [PATCH 2/2] Remove project + Project telemetry Signed-off-by: Joel Longtine --- cmd/dagger/cmd/mod/get.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cmd/dagger/cmd/mod/get.go b/cmd/dagger/cmd/mod/get.go index 08ae1efa..60ee43c2 100644 --- a/cmd/dagger/cmd/mod/get.go +++ b/cmd/dagger/cmd/mod/get.go @@ -3,12 +3,10 @@ package mod import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "go.dagger.io/dagger/cmd/dagger/cmd/common" "go.dagger.io/dagger/cmd/dagger/logger" "go.dagger.io/dagger/mod" "go.dagger.io/dagger/pkg" "go.dagger.io/dagger/state" - "go.dagger.io/dagger/telemetry" ) var getCmd = &cobra.Command{ @@ -29,17 +27,12 @@ var getCmd = &cobra.Command{ var err error - project := common.CurrentProject(ctx) cueModPath := pkg.GetCueModParent() // err = pkg.CueModInit(ctx, cueModPath) _, err = state.Init(ctx, cueModPath) if err != nil && err != state.ErrAlreadyInit { lg.Fatal().Err(err).Msg("failed to initialize cue.mod") } - doneCh := common.TrackProjectCommand(ctx, cmd, project, nil, &telemetry.Property{ - Name: "packages", - Value: args, - }) var update = viper.GetBool("update") @@ -68,7 +61,6 @@ var getCmd = &cobra.Command{ lg.Error().Err(err).Msg("error installing/updating packages") } - <-doneCh }, }