Skip to content

Commit

Permalink
fix: update repository for catalog command (#3415)
Browse files Browse the repository at this point in the history
  • Loading branch information
levkohimins committed Sep 18, 2024
1 parent b350dc1 commit 2593c5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cli/commands/catalog/module/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package module
import (
"context"
"fmt"
"net/url"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -194,7 +195,12 @@ func (repo *Repo) clone(ctx context.Context) error {

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

if err := getter.Get(repo.path, strings.Trim(sourceURL.String(), "/"), getter.WithContext(ctx)); err != nil {
// We need to explicitly specify the reference, otherwise we will get an error:
// "fatal: The empty string is not a valid pathspec. Use . instead if you wanted to match all paths"
// when updating an existing repository.
sourceURL.RawQuery = (url.Values{"ref": []string{"HEAD"}}).Encode()

if err := getter.Get(repo.path, strings.Trim(sourceURL.String(), "/"), getter.WithContext(ctx), getter.WithMode(getter.ClientModeDir)); err != nil {
return errors.WithStackTrace(err)
}

Expand Down
24 changes: 17 additions & 7 deletions test/integration_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package test_test

import (
"context"
"os"
"path/filepath"
"testing"

Expand All @@ -15,14 +14,27 @@ import (
"github.com/stretchr/testify/require"
)

func TestScaffoldGitRepo(t *testing.T) {
func TestCatalogGitRepoUpdate(t *testing.T) {
t.Parallel()

ctx := context.Background()

tempDir, err := os.MkdirTemp("", "catalog-*")
tempDir := t.TempDir()

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

_, err = module.NewRepo(ctx, log.New(), "github.com/gruntwork-io/terraform-fake-modules.git", tempDir)
require.NoError(t, err)
}

func TestScaffoldGitRepo(t *testing.T) {
t.Parallel()

ctx := context.Background()

tempDir := t.TempDir()

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

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

ctx := context.Background()

tempDir, err := os.MkdirTemp("", "catalog-*")
require.NoError(t, err)
tempDir := t.TempDir()

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

ctx := context.Background()

tempDir, err := os.MkdirTemp("", "catalog-*")
require.NoError(t, err)
tempDir := t.TempDir()

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

0 comments on commit 2593c5e

Please sign in to comment.