Skip to content

Commit

Permalink
fix: remove windows line endings (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh authored Mar 21, 2024
1 parent 77764d5 commit ec5eb3e
Show file tree
Hide file tree
Showing 52 changed files with 7,592 additions and 20 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/golangci_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: golangci-lint
on:
pull_request:
workflow_dispatch:

jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest

12 changes: 8 additions & 4 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
- main
pull_request:
workflow_dispatch:
inputs:
enable_debug_tmate:
required: false
type: boolean
default: false

permissions:
contents: write
Expand Down Expand Up @@ -33,10 +38,9 @@ jobs:
go-version-file: go.mod
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
- name: (debug) Setup tmate session
if: ${{ inputs.enable_debug_tmate }}
uses: mxschmitt/action-tmate@v3

- name: test
run: |
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ build:

.PHONY: test
test:
# TODO: temporary hack return 0 for first release
@echo skipping tests
@go clean --testcache && go test -v ./...

12 changes: 10 additions & 2 deletions integration/bgps_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package integration

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
)

func TestBGPS(t *testing.T) {
var notFoundMsg string
if runtime.GOOS == "windows" {
notFoundMsg = "The system cannot find the path specified."
} else {
notFoundMsg = "no such file or directory"
}
tests := []struct {
dir string
input []string
Expand Down Expand Up @@ -67,8 +75,8 @@ func TestBGPS(t *testing.T) {
{"bisect", []string{}, "\x1b[48;2;204;204;255m\x1b[35m \ue0a0 main|BISECTING ↓[1]\x1b[0m", []string{"BGPS_CONFIG=../configs/color_overrides.toml"}},

// config errors
{"clean", []string{"--config=/fromparam/does/not/exist"}, "\x1b[31m bgps error(read config): open /fromparam/does/not/exist: no such file or directory\x1b[0m", nil},
{"configs", []string{}, "\x1b[31m bgps error(read config): open /fromenvvar/does/not/exist: no such file or directory\x1b[0m", []string{"BGPS_CONFIG=/fromenvvar/does/not/exist"}},
{"clean", []string{"--config=/fromparam/does/not/exist"}, fmt.Sprintf("\x1b[31m bgps error(read config): open /fromparam/does/not/exist: %s\x1b[0m", notFoundMsg), nil},
{"configs", []string{}, fmt.Sprintf("\x1b[31m bgps error(read config): open /fromenvvar/does/not/exist: %s\x1b[0m", notFoundMsg), []string{"BGPS_CONFIG=/fromenvvar/does/not/exist"}},
{"configs", []string{"--config=invalid_syntax.toml"}, "\x1b[31m bgps error(unmarshal config): toml: expected character =\x1b[0m", nil},
{"configs", []string{}, "\x1b[31m bgps error(unmarshal config): toml: expected character =\x1b[0m", []string{"BGPS_CONFIG=invalid_syntax.toml"}},

Expand Down
7 changes: 6 additions & 1 deletion integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
)

Expand All @@ -21,7 +22,11 @@ func TestMain(m *testing.M) {
}
defer os.RemoveAll(tmpDir)

builtBinaryPath = filepath.Join(tmpDir, "bgps")
bgps := "bgps"
if runtime.GOOS == "windows" {
bgps += ".exe"
}
builtBinaryPath = filepath.Join(tmpDir, bgps)

cmd := exec.Command("go", "build", "-o", builtBinaryPath, "..")
output, err := cmd.CombinedOutput()
Expand Down
16 changes: 8 additions & 8 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func LsFilesUnmerged() (string, error) {
if err != nil {
return string(stdCombined), err
}
return strings.TrimSuffix(string(stdCombined), "\n"), err
return strings.TrimRight(string(stdCombined), "\r\n"), err
}

func SparseCheckout() (bool, error) {
Expand All @@ -54,7 +54,7 @@ func SparseCheckout() (bool, error) {
if err != nil && len(stdCombined) != 0 {
return false, err
}
isSparseCheckout, _ := strconv.ParseBool(strings.TrimSuffix(string(stdCombined), "\n"))
isSparseCheckout, _ := strconv.ParseBool(strings.TrimRight(string(stdCombined), "\r\n"))
return isSparseCheckout, nil
}

Expand All @@ -68,7 +68,7 @@ func SymbolicRef(ref string) (string, error) {
if err != nil {
return string(stdCombined), err
}
return strings.TrimSuffix(string(stdCombined), "\n"), err
return strings.TrimRight(string(stdCombined), "\r\n"), err
}

func DescribeTag(ref string) (string, error) {
Expand All @@ -83,7 +83,7 @@ func DescribeTag(ref string) (string, error) {
if err != nil {
return string(stdCombined), err
}
return strings.TrimSuffix(string(stdCombined), "\n"), err
return strings.TrimRight(string(stdCombined), "\r\n"), err
}

func HasUntracked() (bool, error) {
Expand Down Expand Up @@ -144,7 +144,7 @@ func RevParseShort() (string, []byte, error) {

err = cmd.Wait()

return strings.TrimSuffix(string(stdout), "\n"), stderr, err
return strings.TrimRight(string(stdout), "\r\n"), stderr, err
}

func RevParse() (*GitRepo, []byte, error) {
Expand Down Expand Up @@ -187,7 +187,7 @@ func RevParse() (*GitRepo, []byte, error) {
err = cmd.Wait()

if len(stdout) > 0 {
result := strings.Split(strings.TrimSuffix(string(stdout), "\n"), "\n")
result := strings.Split(strings.TrimRight(string(stdout), "\r\n"), "\n")
resultLen := len(result)
if resultLen == 5 || resultLen == 6 {
g.GitDir = result[0]
Expand Down Expand Up @@ -260,7 +260,7 @@ func BranchRemote(branch string) (string, error) {
return "", err
}

return strings.TrimSuffix(string(stdCombined), "\n"), nil
return strings.TrimRight(string(stdCombined), "\r\n"), nil
}

func BranchMerge(branch string) (string, error) {
Expand All @@ -274,5 +274,5 @@ func BranchMerge(branch string) (string, error) {
return "", err
}

return strings.TrimSuffix(string(stdCombined), "\n"), nil
return strings.TrimRight(string(stdCombined), "\r\n"), nil
}
3 changes: 2 additions & 1 deletion pkg/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/mikesmithgh/bgps/pkg/color"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (g *GitRepo) IsGitDirSymlink(name string) bool {
}

func (g *GitRepo) GitDirPath(path string) string {
return fmt.Sprintf("%s/%s", g.GitDir, path)
return filepath.Join(g.GitDir, path)
}

func (g *GitRepo) ReadGitDirFile(name string) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func ReadFileTrimNewline(name string) (string, error) {
if err != nil {
return "", err
}
return strings.TrimSuffix(string(result), "\n"), err
return strings.TrimRight(string(result), "\r\n"), err
}

func ErrMsg(hint string, e error, exitCode int) {
Expand All @@ -40,7 +40,7 @@ func ErrMsg(hint string, e error, exitCode int) {
if e == nil {
error_msg = "no error message provided"
} else {
error_msg = strings.ReplaceAll(e.Error(), "\n", "")
error_msg = strings.ReplaceAll(strings.ReplaceAll(e.Error(), "\n", ""), "\r", "")
}
fmt.Printf("%s bgps error(%s): %s%s", errorColor, hint, error_msg, clearColor)
os.Exit(exitCode)
Expand Down
4 changes: 4 additions & 0 deletions testdata/bare/objects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
4 changes: 4 additions & 0 deletions testdata/bare/refs/heads/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
4 changes: 4 additions & 0 deletions testdata/git_dir/objects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
4 changes: 4 additions & 0 deletions testdata/git_dir/refs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
4 changes: 4 additions & 0 deletions testdata/no_upstream/dot_git/objects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
4 changes: 4 additions & 0 deletions testdata/no_upstream/dot_git/refs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
Binary file modified testdata/tag/dot_git/index
Binary file not shown.
1 change: 1 addition & 0 deletions testdata/tag/dot_git/refs/tags/v1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24afc9585ad36ab4a5bcfce5fe08131e72904a5e
1 change: 1 addition & 0 deletions testdata/tag/dot_git/refs/tags/v1.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ee15d853d41921ef418bab005f3f418905ca1291
1 change: 1 addition & 0 deletions testdata/tag/dot_git/refs/tags/v1.2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ac1388817966209ffb7a8a83a084f7388134c07d

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/pelletier/go-toml/v2/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions vendor/github.com/pelletier/go-toml/v2/.golangci.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ec5eb3e

Please sign in to comment.