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

Commit 310c2c8

Browse files
authored
Merge pull request #888 from ibrasho-forks/remove-vcs-directories-from-vendor
internal/gps: remove vcs (bzr & hg) directories when coping to vendor/
2 parents eb5b757 + 216ca2e commit 310c2c8

File tree

2 files changed

+140
-5
lines changed

2 files changed

+140
-5
lines changed

internal/gps/vcs_source.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ func (bs *baseVCSSource) exportRevisionTo(ctx context.Context, r Revision, to st
107107
return unwrapVcsErr(err)
108108
}
109109

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

@@ -353,6 +350,18 @@ type bzrSource struct {
353350
baseVCSSource
354351
}
355352

353+
func (s *bzrSource) exportRevisionTo(ctx context.Context, rev Revision, to string) error {
354+
if err := s.baseVCSSource.exportRevisionTo(ctx, rev, to); err != nil {
355+
return err
356+
}
357+
358+
if err := os.RemoveAll(filepath.Join(to, ".bzr")); err != nil {
359+
return err
360+
}
361+
362+
return nil
363+
}
364+
356365
func (s *bzrSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
357366
r := s.repo
358367

@@ -403,6 +412,20 @@ type hgSource struct {
403412
baseVCSSource
404413
}
405414

415+
func (s *hgSource) exportRevisionTo(ctx context.Context, rev Revision, to string) error {
416+
// TODO: use hg instead of the generic approach in
417+
// baseVCSSource.exportRevisionTo to make it faster.
418+
if err := s.baseVCSSource.exportRevisionTo(ctx, rev, to); err != nil {
419+
return err
420+
}
421+
422+
if err := os.RemoveAll(filepath.Join(to, ".hg")); err != nil {
423+
return err
424+
}
425+
426+
return nil
427+
}
428+
406429
func (s *hgSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
407430
var vlist []PairedVersion
408431

internal/gps/vcs_source_test.go

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import (
88
"context"
99
"io/ioutil"
1010
"net/url"
11+
"os"
1112
"os/exec"
13+
"path/filepath"
1214
"reflect"
1315
"strings"
1416
"sync"
1517
"testing"
18+
19+
"github.com/golang/dep/internal/test"
1620
)
1721

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

322326
err = isrc.initLocal(ctx)
323327
if err != nil {
324-
t.Fatalf("Error on cloning git repo: %s", err)
328+
t.Fatalf("Error on cloning bzr repo: %s", err)
325329
}
326330

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

434438
err = isrc.initLocal(ctx)
435439
if err != nil {
436-
t.Fatalf("Error on cloning git repo: %s", err)
440+
t.Fatalf("Error on cloning hg repo: %s", err)
437441
}
438442

439443
src, ok := isrc.(*hgSource)
@@ -520,6 +524,114 @@ func testHgSourceInteractions(t *testing.T) {
520524
<-donech
521525
}
522526

527+
func Test_bzrSource_exportRevisionTo_removeVcsFiles(t *testing.T) {
528+
t.Parallel()
529+
530+
// This test is slow, so skip it on -short
531+
if testing.Short() {
532+
t.Skip("Skipping hg source version fetching test in short mode")
533+
}
534+
requiresBins(t, "bzr")
535+
536+
h := test.NewHelper(t)
537+
defer h.Cleanup()
538+
h.TempDir("smcache")
539+
cpath := h.Path("smcache")
540+
repoPath := filepath.Join(h.Path("."), "repo")
541+
542+
rev := Revision("[email protected]")
543+
n := "launchpad.net/govcstestbzrrepo"
544+
un := "https://" + n
545+
u, err := url.Parse(un)
546+
if err != nil {
547+
t.Errorf("URL was bad, lolwut? errtext: %s", err)
548+
return
549+
}
550+
mb := maybeBzrSource{u}
551+
552+
ctx := context.Background()
553+
superv := newSupervisor(ctx)
554+
isrc, _, err := mb.try(ctx, cpath, newMemoryCache(), superv)
555+
if err != nil {
556+
t.Fatalf("unexpected error while setting up hgSource for test repo: %s", err)
557+
}
558+
559+
err = isrc.initLocal(ctx)
560+
if err != nil {
561+
t.Fatalf("Error on cloning bzr repo: %s", err)
562+
}
563+
564+
src, ok := isrc.(*bzrSource)
565+
if !ok {
566+
t.Fatalf("expected a bzrSource, got a %T", isrc)
567+
}
568+
569+
if err := src.exportRevisionTo(ctx, rev, repoPath); err != nil {
570+
t.Fatalf("unexpected error: %v", err)
571+
}
572+
573+
_, err = os.Stat(filepath.Join(repoPath, ".bzr"))
574+
if err == nil {
575+
t.Fatal("expected .bzr/ to not exists")
576+
} else if !os.IsNotExist(err) {
577+
t.Fatalf("unexpected error: %v", err)
578+
}
579+
}
580+
581+
func Test_hgSource_exportRevisionTo_removeVcsFiles(t *testing.T) {
582+
t.Parallel()
583+
584+
// This test is slow, so skip it on -short
585+
if testing.Short() {
586+
t.Skip("Skipping hg source version fetching test in short mode")
587+
}
588+
requiresBins(t, "hg")
589+
590+
h := test.NewHelper(t)
591+
defer h.Cleanup()
592+
h.TempDir("smcache")
593+
cpath := h.Path("smcache")
594+
repoPath := filepath.Join(h.Path("."), "repo")
595+
596+
rev := Revision("6f55e1f03d91f8a7cce35d1968eb60a2352e4d59")
597+
n := "bitbucket.org/golang-dep/dep-test"
598+
un := "https://" + n
599+
u, err := url.Parse(un)
600+
if err != nil {
601+
t.Errorf("URL was bad, lolwut? errtext: %s", err)
602+
return
603+
}
604+
mb := maybeHgSource{u}
605+
606+
ctx := context.Background()
607+
superv := newSupervisor(ctx)
608+
isrc, _, err := mb.try(ctx, cpath, newMemoryCache(), superv)
609+
if err != nil {
610+
t.Fatalf("unexpected error while setting up hgSource for test repo: %s", err)
611+
}
612+
613+
err = isrc.initLocal(ctx)
614+
if err != nil {
615+
t.Fatalf("Error on cloning hg repo: %s", err)
616+
}
617+
618+
src, ok := isrc.(*hgSource)
619+
if !ok {
620+
t.Fatalf("expected a hgSource, got a %T", isrc)
621+
}
622+
623+
if err := src.exportRevisionTo(ctx, rev, repoPath); err != nil {
624+
t.Fatalf("unexpected error: %v", err)
625+
}
626+
627+
_, err = os.Stat(filepath.Join(repoPath, ".hg"))
628+
if err == nil {
629+
t.Fatal("expected .hg/ to not exists")
630+
} else if !os.IsNotExist(err) {
631+
t.Fatalf("unexpected error: %v", err)
632+
}
633+
}
634+
523635
// Fail a test if the specified binaries aren't installed.
524636
func requiresBins(t *testing.T, bins ...string) {
525637
for _, b := range bins {

0 commit comments

Comments
 (0)