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

Commit 77df563

Browse files
authored
Merge pull request #780 from ibrasho-forks/fix-prune-bug-on-windows
dep: update calculatePrune to not assume "/" as file separator
2 parents f16f7a8 + 30ba901 commit 77df563

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

txn_writer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ fail:
530530
return failerr
531531
}
532532

533+
// calculatePrune returns the paths of the packages to be deleted from vendorDir.
533534
func calculatePrune(vendorDir string, keep []string, logger *log.Logger) ([]string, error) {
534535
if logger != nil {
535536
logger.Println("Calculating prune. Checking the following packages:")
@@ -547,7 +548,7 @@ func calculatePrune(vendorDir string, keep []string, logger *log.Logger) ([]stri
547548
return nil
548549
}
549550

550-
name := strings.TrimPrefix(path, vendorDir+"/")
551+
name := strings.TrimPrefix(path, vendorDir+string(filepath.Separator))
551552
if logger != nil {
552553
logger.Printf(" %s", name)
553554
}

txn_writer_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88
"io/ioutil"
99
"os"
1010
"path/filepath"
11+
"sort"
1112
"strings"
1213
"testing"
1314

15+
"reflect"
16+
1417
"github.com/golang/dep/internal/test"
1518
"github.com/pkg/errors"
1619
)
@@ -567,3 +570,35 @@ func TestSafeWriter_VendorDotGitPreservedWithForceVendor(t *testing.T) {
567570
t.Fatal(err)
568571
}
569572
}
573+
574+
func TestCalculatePrune(t *testing.T) {
575+
h := test.NewHelper(t)
576+
defer h.Cleanup()
577+
578+
vendorDir := "vendor"
579+
h.TempDir(vendorDir)
580+
h.TempDir(filepath.Join(vendorDir, "github.com/keep/pkg/sub"))
581+
h.TempDir(filepath.Join(vendorDir, "github.com/prune/pkg/sub"))
582+
583+
toKeep := []string{
584+
filepath.FromSlash("github.com/keep/pkg"),
585+
filepath.FromSlash("github.com/keep/pkg/sub"),
586+
}
587+
588+
got, err := calculatePrune(h.Path(vendorDir), toKeep, nil)
589+
if err != nil {
590+
t.Fatal(err)
591+
}
592+
593+
sort.Sort(byLen(got))
594+
595+
want := []string{
596+
h.Path(filepath.Join(vendorDir, "github.com/prune/pkg/sub")),
597+
h.Path(filepath.Join(vendorDir, "github.com/prune/pkg")),
598+
h.Path(filepath.Join(vendorDir, "github.com/prune")),
599+
}
600+
601+
if !reflect.DeepEqual(want, got) {
602+
t.Fatalf("calculated prune paths are not as expected.\n(WNT) %s\n(GOT) %s", want, got)
603+
}
604+
}

0 commit comments

Comments
 (0)