From 7cc34bc03102ca6eca57aa5c4f341776f76c11e9 Mon Sep 17 00:00:00 2001 From: Colton Donnelly Date: Thu, 18 Jan 2024 19:32:54 +0000 Subject: [PATCH 1/2] lock when there isnt a package dir either --- internal/cli/cmds.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/cli/cmds.go b/internal/cli/cmds.go index 666197a1..9512234d 100644 --- a/internal/cli/cmds.go +++ b/internal/cli/cmds.go @@ -216,7 +216,14 @@ func maybeLock(ctx context.Context, b api.LanguageBackend, forceLock bool) bool return false } - if forceLock || !util.Exists(b.Lockfile) || store.HasSpecfileChanged(b) { + shouldLock := forceLock || !util.Exists(b.Lockfile) || store.HasSpecfileChanged(b) + if !shouldLock { + if packageDir := b.GetPackageDir(); packageDir != "" { + shouldLock = !util.Exists(packageDir) + } + } + + if shouldLock { b.Lock(ctx) return true } From db20f5387a1fc4e210077877fc8b0710b60909b8 Mon Sep 17 00:00:00 2001 From: Colton Donnelly Date: Thu, 18 Jan 2024 19:45:28 +0000 Subject: [PATCH 2/2] update lock test --- test-suite/Lock_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test-suite/Lock_test.go b/test-suite/Lock_test.go index a6df6336..c52ea124 100644 --- a/test-suite/Lock_test.go +++ b/test-suite/Lock_test.go @@ -30,6 +30,7 @@ func TestLock(t *testing.T) { } func doLock(bt testUtils.BackendT) { + // test absence of lock file for _, tmpl := range standardTemplates { template := bt.Backend.Name + "/" + tmpl + "/" @@ -57,4 +58,29 @@ func doLock(bt testUtils.BackendT) { } }) } + + // test absence of package dir + bt.Subtest(bt.Backend.Name + "/no-package-dir", func(bt testUtils.BackendT) { + bt.AddTestFile(bt.Backend.Name+"/many-deps/"+bt.Backend.Specfile, bt.Backend.Specfile) + + specDeps := bt.UpmListSpecFile() + + bt.UpmLock() + + lockDeps := bt.UpmListLockFile() + + for _, specDep := range specDeps { + found := false + for _, lockDep := range lockDeps { + if specDep.Name == lockDep.Name { + found = true + break + } + } + + if !found { + bt.Fail("expected %s in lock file", specDep.Name) + } + } + }) }