From 785c2c0fed8af914d7f11b00d7d0a23339883f09 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:20:22 +0000 Subject: [PATCH] Bump github.com/hashicorp/go-getter from 1.7.4 to 1.7.5 Bumps [github.com/hashicorp/go-getter](https://github.com/hashicorp/go-getter) from 1.7.4 to 1.7.5. - [Release notes](https://github.com/hashicorp/go-getter/releases) - [Changelog](https://github.com/hashicorp/go-getter/blob/main/.goreleaser.yml) - [Commits](https://github.com/hashicorp/go-getter/compare/v1.7.4...v1.7.5) --- updated-dependencies: - dependency-name: github.com/hashicorp/go-getter dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../github.com/hashicorp/go-getter/get_git.go | 81 +++++++++++++++---- vendor/modules.txt | 2 +- 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 9dbdaa5b7..9b21e05ec 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-getter v1.7.4 // indirect + github.com/hashicorp/go-getter v1.7.5 // indirect github.com/hashicorp/go-hclog v0.16.1 // indirect github.com/hashicorp/go-multierror v1.1.0 // indirect github.com/hashicorp/go-plugin v1.3.0 // indirect diff --git a/go.sum b/go.sum index 45607cbe9..19fd729b2 100644 --- a/go.sum +++ b/go.sum @@ -392,8 +392,8 @@ github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-getter v1.5.3/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI= -github.com/hashicorp/go-getter v1.7.4 h1:3yQjWuxICvSpYwqSayAdKRFcvBl1y/vogCxczWSmix0= -github.com/hashicorp/go-getter v1.7.4/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744= +github.com/hashicorp/go-getter v1.7.5 h1:dT58k9hQ/vbxNMwoI5+xFYAJuv6152UNvdHokfI5wE4= +github.com/hashicorp/go-getter v1.7.5/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v0.16.1 h1:IVQwpTGNRRIHafnTs2dQLIk4ENtneRIEEJWOVDqz99o= diff --git a/vendor/github.com/hashicorp/go-getter/get_git.go b/vendor/github.com/hashicorp/go-getter/get_git.go index 289317532..f38e0d29c 100644 --- a/vendor/github.com/hashicorp/go-getter/get_git.go +++ b/vendor/github.com/hashicorp/go-getter/get_git.go @@ -125,7 +125,7 @@ func (g *GitGetter) Get(dst string, u *url.URL) error { return err } if err == nil { - err = g.update(ctx, dst, sshKeyFile, ref, depth) + err = g.update(ctx, dst, sshKeyFile, u, ref, depth) } else { err = g.clone(ctx, dst, sshKeyFile, u, ref, depth) } @@ -228,28 +228,64 @@ func (g *GitGetter) clone(ctx context.Context, dst, sshKeyFile string, u *url.UR return nil } -func (g *GitGetter) update(ctx context.Context, dst, sshKeyFile, ref string, depth int) error { - // Determine if we're a branch. If we're NOT a branch, then we just - // switch to master prior to checking out - cmd := exec.CommandContext(ctx, "git", "show-ref", "-q", "--verify", "refs/heads/"+ref) +func (g *GitGetter) update(ctx context.Context, dst, sshKeyFile string, u *url.URL, ref string, depth int) error { + // Remove all variations of .git directories + err := removeCaseInsensitiveGitDirectory(dst) + if err != nil { + return err + } + + // Initialize the git repository + cmd := exec.CommandContext(ctx, "git", "init") + cmd.Dir = dst + err = getRunCommand(cmd) + if err != nil { + return err + } + + // Add the git remote + cmd = exec.CommandContext(ctx, "git", "remote", "add", "origin", "--", u.String()) + cmd.Dir = dst + err = getRunCommand(cmd) + if err != nil { + return err + } + + // Fetch the remote ref + cmd = exec.CommandContext(ctx, "git", "fetch", "--tags") + cmd.Dir = dst + err = getRunCommand(cmd) + if err != nil { + return err + } + + // Fetch the remote ref + cmd = exec.CommandContext(ctx, "git", "fetch", "origin", "--", ref) cmd.Dir = dst + err = getRunCommand(cmd) + if err != nil { + return err + } - if getRunCommand(cmd) != nil { - // Not a branch, switch to default branch. This will also catch - // non-existent branches, in which case we want to switch to default - // and then checkout the proper branch later. - ref = findDefaultBranch(ctx, dst) + // Reset the branch to the fetched ref + cmd = exec.CommandContext(ctx, "git", "reset", "--hard", "FETCH_HEAD") + cmd.Dir = dst + err = getRunCommand(cmd) + if err != nil { + return err } - // We have to be on a branch to pull - if err := g.checkout(ctx, dst, ref); err != nil { + // Checkout ref branch + err = g.checkout(ctx, dst, ref) + if err != nil { return err } + // Pull the latest changes from the ref branch if depth > 0 { - cmd = exec.CommandContext(ctx, "git", "pull", "--depth", strconv.Itoa(depth), "--ff-only") + cmd = exec.CommandContext(ctx, "git", "pull", "origin", "--depth", strconv.Itoa(depth), "--ff-only", "--", ref) } else { - cmd = exec.CommandContext(ctx, "git", "pull", "--ff-only") + cmd = exec.CommandContext(ctx, "git", "pull", "origin", "--ff-only", "--", ref) } cmd.Dir = dst @@ -377,3 +413,20 @@ func checkGitVersion(ctx context.Context, min string) error { return nil } + +// removeCaseInsensitiveGitDirectory removes all .git directory variations +func removeCaseInsensitiveGitDirectory(dst string) error { + files, err := os.ReadDir(dst) + if err != nil { + return fmt.Errorf("Failed to read the destination directory %s during git update", dst) + } + for _, f := range files { + if strings.EqualFold(f.Name(), ".git") && f.IsDir() { + err := os.RemoveAll(filepath.Join(dst, f.Name())) + if err != nil { + return fmt.Errorf("Failed to remove the .git directory in the destination directory %s during git update", dst) + } + } + } + return nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index fe75f3f8b..7708c40f6 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -213,7 +213,7 @@ github.com/hashicorp/go-checkpoint # github.com/hashicorp/go-cleanhttp v0.5.2 ## explicit; go 1.13 github.com/hashicorp/go-cleanhttp -# github.com/hashicorp/go-getter v1.7.4 +# github.com/hashicorp/go-getter v1.7.5 ## explicit; go 1.13 github.com/hashicorp/go-getter github.com/hashicorp/go-getter/helper/url