Skip to content

Commit

Permalink
fix: consistent line endings in log messages (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleclay authored May 14, 2024
1 parent 0b03d5f commit 7df8477
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 21 deletions.
5 changes: 3 additions & 2 deletions .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ test_patterns = [

[[analyzers]]
name = "go"
enabled = true

[analyzers.meta]
import_root = "github.com/purpleclay/gitz"
import_root = "github.com/purpleclay/nsv"

[[analyzers]]
name = "secret"
name = "secrets"
enabled = true
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
43 changes: 25 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Ignore everything and selectively allow files
*

# Test binary, built with `go test -c`
*.test
# Allow project files
!.deepsource.toml
!.github/**/*
!.gitignore
!.golangci.yaml
!.goreleaser.yaml
!CODEOWNERS
!CODE_OF_CONDUCT.md
!htmltest.yml
!LICENSE
!mkdocs.yml
!README.md
!Taskfile.yaml

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Allow Nix files
!.envrc
!flake.nix
!flake.lock

# Dependency directories (remove the comment below to include it)
# vendor/
# Allow Go files
!*.go
!go.sum
!go.mod

# Mkdocs
.cache/
site/

# VSCode
.vscode/
# Recurse through sub-directories applying the same patterns
!*/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Purple Clay
Copyright (c) 2023 - 2024 Purple Clay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
File renamed without changes.
61 changes: 61 additions & 0 deletions flake.lock

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

27 changes: 27 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
description = "Write fluent interactions to Git. Programmatically crafting git commands becomes a breeze!";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
with pkgs;
{
devShells.default = mkShell {
buildInputs = [
git
go
gofumpt
golangci-lint
go-task
];
};
}
);
}
2 changes: 2 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ func parseLog(log string) []LogEntry {
for scanner.Scan() {
// Expected format of log from using the --online format is: <hash><space><message>
if hash, msg, found := strings.Cut(scanner.Text(), " "); found {
msg = cleanLineEndings(msg)

entries = append(entries, LogEntry{
Hash: hash,
AbbrevHash: hash[:7],
Expand Down
10 changes: 10 additions & 0 deletions log_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !windows
// +build !windows

package git

import "strings"

func cleanLineEndings(log string) string {
return strings.ReplaceAll(log, "\r\n", "\n")
}
9 changes: 9 additions & 0 deletions log_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build windows
// +build windows

package git

func cleanLineEndings(log string) string {
// Mixed line endings don't appear within Windows
return log
}

0 comments on commit 7df8477

Please sign in to comment.