Skip to content

Commit 2593c5e

Browse files
authored
fix: update repository for catalog command (#3415)
1 parent b350dc1 commit 2593c5e

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

cli/commands/catalog/module/repo.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package module
33
import (
44
"context"
55
"fmt"
6+
"net/url"
67
"os"
78
"path/filepath"
89
"regexp"
@@ -194,7 +195,12 @@ func (repo *Repo) clone(ctx context.Context) error {
194195

195196
repo.logger.Infof("Cloning repository %q to temporary directory %q", repo.cloneURL, repo.path)
196197

197-
if err := getter.Get(repo.path, strings.Trim(sourceURL.String(), "/"), getter.WithContext(ctx)); err != nil {
198+
// We need to explicitly specify the reference, otherwise we will get an error:
199+
// "fatal: The empty string is not a valid pathspec. Use . instead if you wanted to match all paths"
200+
// when updating an existing repository.
201+
sourceURL.RawQuery = (url.Values{"ref": []string{"HEAD"}}).Encode()
202+
203+
if err := getter.Get(repo.path, strings.Trim(sourceURL.String(), "/"), getter.WithContext(ctx), getter.WithMode(getter.ClientModeDir)); err != nil {
198204
return errors.WithStackTrace(err)
199205
}
200206

test/integration_catalog_test.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package test_test
22

33
import (
44
"context"
5-
"os"
65
"path/filepath"
76
"testing"
87

@@ -15,14 +14,27 @@ import (
1514
"github.com/stretchr/testify/require"
1615
)
1716

18-
func TestScaffoldGitRepo(t *testing.T) {
17+
func TestCatalogGitRepoUpdate(t *testing.T) {
1918
t.Parallel()
2019

2120
ctx := context.Background()
2221

23-
tempDir, err := os.MkdirTemp("", "catalog-*")
22+
tempDir := t.TempDir()
23+
24+
_, err := module.NewRepo(ctx, log.New(), "github.com/gruntwork-io/terraform-fake-modules.git", tempDir)
2425
require.NoError(t, err)
2526

27+
_, err = module.NewRepo(ctx, log.New(), "github.com/gruntwork-io/terraform-fake-modules.git", tempDir)
28+
require.NoError(t, err)
29+
}
30+
31+
func TestScaffoldGitRepo(t *testing.T) {
32+
t.Parallel()
33+
34+
ctx := context.Background()
35+
36+
tempDir := t.TempDir()
37+
2638
repo, err := module.NewRepo(ctx, log.New(), "github.com/gruntwork-io/terraform-fake-modules.git", tempDir)
2739
require.NoError(t, err)
2840

@@ -36,8 +48,7 @@ func TestScaffoldGitModule(t *testing.T) {
3648

3749
ctx := context.Background()
3850

39-
tempDir, err := os.MkdirTemp("", "catalog-*")
40-
require.NoError(t, err)
51+
tempDir := t.TempDir()
4152

4253
repo, err := module.NewRepo(ctx, log.New(), "https://github.com/gruntwork-io/terraform-fake-modules.git", tempDir)
4354
require.NoError(t, err)
@@ -75,8 +86,7 @@ func TestScaffoldGitModuleHttps(t *testing.T) {
7586

7687
ctx := context.Background()
7788

78-
tempDir, err := os.MkdirTemp("", "catalog-*")
79-
require.NoError(t, err)
89+
tempDir := t.TempDir()
8090

8191
repo, err := module.NewRepo(ctx, log.New(), "https://github.com/gruntwork-io/terraform-fake-modules", tempDir)
8292
require.NoError(t, err)

0 commit comments

Comments
 (0)