Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #888 from ibrasho-forks/remove-vcs-directories-fro…
Browse files Browse the repository at this point in the history
…m-vendor

internal/gps: remove vcs (bzr & hg) directories when coping to vendor/
  • Loading branch information
sdboyer authored Jul 30, 2017
2 parents eb5b757 + 216ca2e commit 310c2c8
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 5 deletions.
29 changes: 26 additions & 3 deletions internal/gps/vcs_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ func (bs *baseVCSSource) exportRevisionTo(ctx context.Context, r Revision, to st
return unwrapVcsErr(err)
}

// TODO(sdboyer) this is a simplistic approach and relying on the tools
// themselves might make it faster, but git's the overwhelming case (and has
// its own method) so fine for now
return fs.CopyDir(bs.repo.LocalPath(), to)
}

Expand Down Expand Up @@ -353,6 +350,18 @@ type bzrSource struct {
baseVCSSource
}

func (s *bzrSource) exportRevisionTo(ctx context.Context, rev Revision, to string) error {
if err := s.baseVCSSource.exportRevisionTo(ctx, rev, to); err != nil {
return err
}

if err := os.RemoveAll(filepath.Join(to, ".bzr")); err != nil {
return err
}

return nil
}

func (s *bzrSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
r := s.repo

Expand Down Expand Up @@ -403,6 +412,20 @@ type hgSource struct {
baseVCSSource
}

func (s *hgSource) exportRevisionTo(ctx context.Context, rev Revision, to string) error {
// TODO: use hg instead of the generic approach in
// baseVCSSource.exportRevisionTo to make it faster.
if err := s.baseVCSSource.exportRevisionTo(ctx, rev, to); err != nil {
return err
}

if err := os.RemoveAll(filepath.Join(to, ".hg")); err != nil {
return err
}

return nil
}

func (s *hgSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
var vlist []PairedVersion

Expand Down
116 changes: 114 additions & 2 deletions internal/gps/vcs_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ import (
"context"
"io/ioutil"
"net/url"
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
"sync"
"testing"

"github.com/golang/dep/internal/test"
)

// Parent test that executes all the slow vcs interaction tests in parallel.
Expand Down Expand Up @@ -321,7 +325,7 @@ func testBzrSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Fatalf("Error on cloning git repo: %s", err)
t.Fatalf("Error on cloning bzr repo: %s", err)
}

src, ok := isrc.(*bzrSource)
Expand Down Expand Up @@ -433,7 +437,7 @@ func testHgSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Fatalf("Error on cloning git repo: %s", err)
t.Fatalf("Error on cloning hg repo: %s", err)
}

src, ok := isrc.(*hgSource)
Expand Down Expand Up @@ -520,6 +524,114 @@ func testHgSourceInteractions(t *testing.T) {
<-donech
}

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

// This test is slow, so skip it on -short
if testing.Short() {
t.Skip("Skipping hg source version fetching test in short mode")
}
requiresBins(t, "bzr")

h := test.NewHelper(t)
defer h.Cleanup()
h.TempDir("smcache")
cpath := h.Path("smcache")
repoPath := filepath.Join(h.Path("."), "repo")

rev := Revision("[email protected]")
n := "launchpad.net/govcstestbzrrepo"
un := "https://" + n
u, err := url.Parse(un)
if err != nil {
t.Errorf("URL was bad, lolwut? errtext: %s", err)
return
}
mb := maybeBzrSource{u}

ctx := context.Background()
superv := newSupervisor(ctx)
isrc, _, err := mb.try(ctx, cpath, newMemoryCache(), superv)
if err != nil {
t.Fatalf("unexpected error while setting up hgSource for test repo: %s", err)
}

err = isrc.initLocal(ctx)
if err != nil {
t.Fatalf("Error on cloning bzr repo: %s", err)
}

src, ok := isrc.(*bzrSource)
if !ok {
t.Fatalf("expected a bzrSource, got a %T", isrc)
}

if err := src.exportRevisionTo(ctx, rev, repoPath); err != nil {
t.Fatalf("unexpected error: %v", err)
}

_, err = os.Stat(filepath.Join(repoPath, ".bzr"))
if err == nil {
t.Fatal("expected .bzr/ to not exists")
} else if !os.IsNotExist(err) {
t.Fatalf("unexpected error: %v", err)
}
}

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

// This test is slow, so skip it on -short
if testing.Short() {
t.Skip("Skipping hg source version fetching test in short mode")
}
requiresBins(t, "hg")

h := test.NewHelper(t)
defer h.Cleanup()
h.TempDir("smcache")
cpath := h.Path("smcache")
repoPath := filepath.Join(h.Path("."), "repo")

rev := Revision("6f55e1f03d91f8a7cce35d1968eb60a2352e4d59")
n := "bitbucket.org/golang-dep/dep-test"
un := "https://" + n
u, err := url.Parse(un)
if err != nil {
t.Errorf("URL was bad, lolwut? errtext: %s", err)
return
}
mb := maybeHgSource{u}

ctx := context.Background()
superv := newSupervisor(ctx)
isrc, _, err := mb.try(ctx, cpath, newMemoryCache(), superv)
if err != nil {
t.Fatalf("unexpected error while setting up hgSource for test repo: %s", err)
}

err = isrc.initLocal(ctx)
if err != nil {
t.Fatalf("Error on cloning hg repo: %s", err)
}

src, ok := isrc.(*hgSource)
if !ok {
t.Fatalf("expected a hgSource, got a %T", isrc)
}

if err := src.exportRevisionTo(ctx, rev, repoPath); err != nil {
t.Fatalf("unexpected error: %v", err)
}

_, err = os.Stat(filepath.Join(repoPath, ".hg"))
if err == nil {
t.Fatal("expected .hg/ to not exists")
} else if !os.IsNotExist(err) {
t.Fatalf("unexpected error: %v", err)
}
}

// Fail a test if the specified binaries aren't installed.
func requiresBins(t *testing.T, bins ...string) {
for _, b := range bins {
Expand Down

0 comments on commit 310c2c8

Please sign in to comment.