Skip to content

Commit

Permalink
Prioritize windows when formatting filepath
Browse files Browse the repository at this point in the history
  • Loading branch information
gandarez committed May 13, 2024
1 parent 42030f4 commit 7b405b1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ jobs:
name: Build binary
env:
VERSION: ${{ env.TEST_VERSION }}
run: make build-darwin-amd64
run: make build-darwin-arm64
-
name: Integration tests
run: make test-integration
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/wakatime/wakatime-cli

go 1.22.2
go 1.22.3

require (
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358
Expand Down
2 changes: 1 addition & 1 deletion pkg/heartbeat/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func WithFormatting() HandleOption {
}
}

// Format accepts a heartbeat formats it's filepath and returns the formatted version.
// Format accepts a heartbeat to format its filepath and returns the formatted version.
func Format(h Heartbeat) Heartbeat {
if !h.IsUnsavedEntity && (runtime.GOOS != "windows" || !windows.IsWindowsNetworkMount(h.Entity)) {
formatLinuxFilePath(&h)
Expand Down
20 changes: 20 additions & 0 deletions pkg/heartbeat/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ func TestWithFormatting(t *testing.T) {
}, result)
}

func TestFormat_WindowsUnixProjectPathOverride(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("Skipping because OS is not windows.")
}

h := heartbeat.Heartbeat{
Entity: `C:\Users\project\main.go`,
EntityType: heartbeat.FileType,
ProjectPathOverride: "/Users/project/\x00",
}

r := heartbeat.Format(h)

assert.Equal(t, heartbeat.Heartbeat{
Entity: `C:/Users/project/main.go`,
EntityType: heartbeat.FileType,
ProjectPathOverride: "/Users/project",
}, r)
}

func TestFormat_NetworkMount(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("Skipping because OS is not windows.")
Expand Down
2 changes: 1 addition & 1 deletion pkg/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
// FormatFilePath formats a windows filepath by converting backslash to
// frontslash and ensuring that drive letter is upper case.
func FormatFilePath(fp string) string {
isWindowsNetworkMount := windowsNetworkMountRegex.MatchString(fp)
isWindowsNetworkMount := IsWindowsNetworkMount(fp)

fp = backslashReplaceRegex.ReplaceAllString(fp, "/")

Expand Down

0 comments on commit 7b405b1

Please sign in to comment.