Skip to content

Commit

Permalink
Merge pull request #103 from Masterminds/fixes
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
mattfarina authored Mar 28, 2022
2 parents f94282d + 74ab476 commit 77abf17
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 182 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/linux-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
pull_request:
push:
branches:
- master

name: Linux Tests
jobs:
test:
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.18.x]
platform:
- ubuntu-latest
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Lint
run: make lint
- name: Install dependencies
run: sudo apt install subversion mercurial bzr
- name: Test
run: make test
33 changes: 33 additions & 0 deletions .github/workflows/windows-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on:
pull_request:
push:
branches:
- master

name: Windows Tests
jobs:
test:
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.18.x]
platform:
- windows-latest
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Install dependencies
run: choco install svn hg
- name: Test
run: go test -v
env:
# Skipping bzr tests on Windows as bzr does not install properly there.
# bzr development stopped in 2017 (when last change landed). The official
# windows installer is still bzr 2.5. The installer does not setup working
# cacerts. This needs to be manually modified to get working. Skipping
# tests in this environment as there are environment problems.
SKIP_BZR: "true"
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
linters:
disable-all: true
enable:
- deadcode
- dupl
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- nakedret
- revive
- structcheck
- unused
- varcheck
- staticcheck

linters-settings:
gofmt:
simplify: true
goimports:
local-prefixes: helm.sh/helm/v3
dupl:
threshold: 400
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

48 changes: 13 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
.PHONY: setup
setup:
go get -u gopkg.in/alecthomas/gometalinter.v1
gometalinter.v1 --install
GOLANGCI_LINT_VERSION?=1.45.0
GOLANGCI_LINT_SHA256?=ca06a2b170f41a9e1e34d40ca88b15b8fed2d7e37310f0c08b7fc244c34292a9
GOLANGCI_LINT=/usr/local/bin/golangci-lint

$(GOLANGCI_LINT):
curl -sSLO https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz
shasum -a 256 golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz | grep "^${GOLANGCI_LINT_SHA256} " > /dev/null
tar -xf golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz
sudo mv golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint /usr/local/bin/golangci-lint
rm -rf golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64*

.PHONY: test
test: validate lint
test:
@echo "==> Running tests"
go test -v

.PHONY: validate
validate:
# misspell finds the work adresář (used in bzr.go) as a mispelling of
# address. It finds adres. An issue has been filed at
# https://github.com/client9/misspell/issues/99. In the meantime adding
# adres to the ignore list.
@echo "==> Running static validations"
@gometalinter.v1 \
--disable-all \
--linter "misspell:misspell -i adres -j 1 {path}/*.go:PATH:LINE:COL:MESSAGE" \
--enable deadcode \
--severity deadcode:error \
--enable gofmt \
--enable gosimple \
--enable ineffassign \
--enable misspell \
--enable vet \
--tests \
--vendor \
--deadline 60s \
./... || exit_code=1

.PHONY: lint
lint:
@echo "==> Running linters"
@gometalinter.v1 \
--disable-all \
--enable golint \
--vendor \
--deadline 60s \
./... || :
lint: $(GOLANGCI_LINT)
@$(GOLANGCI_LINT) run
26 changes: 0 additions & 26 deletions appveyor.yml

This file was deleted.

16 changes: 16 additions & 0 deletions bzr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"path/filepath"
"time"

//"log"
"os"
"testing"
Expand All @@ -17,6 +18,9 @@ var _ Repo = &BzrRepo{}
// repos these tests are structured to work together.

func TestBzr(t *testing.T) {
if os.Getenv("SKIP_BZR") == "true" {
t.Skip("Skipping bzr tests")
}

tempDir, err := ioutil.TempDir("", "go-vcs-bzr-tests")
if err != nil {
Expand Down Expand Up @@ -236,6 +240,10 @@ func TestBzr(t *testing.T) {
}

func TestBzrCheckLocal(t *testing.T) {
if os.Getenv("SKIP_BZR") == "true" {
t.Skip("Skipping bzr tests")
}

// Verify repo.CheckLocal fails for non-Bzr directories.
// TestBzr is already checking on a valid repo
tempDir, err := ioutil.TempDir("", "go-vcs-bzr-tests")
Expand Down Expand Up @@ -263,6 +271,10 @@ func TestBzrCheckLocal(t *testing.T) {
}

func TestBzrPing(t *testing.T) {
if os.Getenv("SKIP_BZR") == "true" {
t.Skip("Skipping bzr tests")
}

tempDir, err := ioutil.TempDir("", "go-vcs-bzr-tests")
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -296,6 +308,10 @@ func TestBzrPing(t *testing.T) {
}

func TestBzrInit(t *testing.T) {
if os.Getenv("SKIP_BZR") == "true" {
t.Skip("Skipping bzr tests")
}

tempDir, err := ioutil.TempDir("", "go-vcs-bzr-tests")
repoDir := tempDir + "/repo"
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ func (s *GitRepo) ExportDir(dir string) error {
}

// and now, the horror of submodules
path = EscapePathSeparator(dir + "$path" + string(os.PathSeparator))
out, err = s.RunFromDir("git", "submodule", "foreach", "--recursive", "git checkout-index -f -a --prefix="+path)
handleSubmodules(s, dir)

s.log(out)
if err != nil {
return NewLocalError("Error while exporting submodule sources", err, string(out))
Expand Down
4 changes: 4 additions & 0 deletions git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"path/filepath"
"time"

//"log"
"os"
"testing"
Expand Down Expand Up @@ -572,6 +573,9 @@ func TestGitSubmoduleHandling2(t *testing.T) {

exportDir := filepath.Join(tempDir2, "src")

tl := testLogger(t)
repo.Logger = tl

err = repo.ExportDir(exportDir)
if err != nil {
t.Errorf("Unable to export Git repo. Err was %s", err)
Expand Down
13 changes: 13 additions & 0 deletions git_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !windows
// +build !windows

package vcs

import "os"

func handleSubmodules(g *GitRepo, dir string) ([]byte, error) {
// Generate path
path := EscapePathSeparator(dir + "$path" + string(os.PathSeparator))

return g.RunFromDir("git", "submodule", "foreach", "--recursive", "git checkout-index -f -a --prefix="+path)
}
47 changes: 47 additions & 0 deletions git_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//go:build windows
// +build windows

package vcs

import (
"os"
"path/filepath"
"strings"
)

func handleSubmodules(g *GitRepo, dir string) ([]byte, error) {
// Get the submodule directories
out, err := g.RunFromDir("git", "submodule", "foreach", "--quiet", "--recursive", "echo $sm_path")
if err != nil {
return out, err
}
cleanOut := strings.TrimSpace(string(out))
pths := strings.Split(strings.ReplaceAll(cleanOut, "\r\n", "\n"), "\n")

// Create the new directories. Directories are sometimes not created under
// Windows
for _, pth := range pths {
fpth := filepath.Join(dir + pth)
os.MkdirAll(fpth, 0755)
}

// checkout-index for each submodule. Using $path or $sm_path while iterating
// over the submodules does not work in Windows when called from Go.
var cOut []byte
for _, pth := range pths {
// Get the path to the submodule in the exported location
fpth := EscapePathSeparator(filepath.Join(dir, pth) + string(os.PathSeparator))

// Call checkout-index directly in the submodule rather than in the
// parent project. This stils git submodule foreach that has trouble
// on Windows within Go where $sm_path isn't being handled properly
c := g.CmdFromDir("git", "checkout-index", "-f", "-a", "--prefix="+fpth)
c.Dir = filepath.Join(c.Dir, pth)
out, err := c.CombinedOutput()
cOut = append(cOut, out...)
if err != nil {
return cOut, err
}
}
return cOut, nil
}
8 changes: 0 additions & 8 deletions glide.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/masterminds/vcs

go 1.17
Loading

0 comments on commit 77abf17

Please sign in to comment.