Skip to content

Commit

Permalink
Merge pull request #10 from juev/normalize
Browse files Browse the repository at this point in the history
fix: correctly taking the directory for the repository
  • Loading branch information
juev committed May 24, 2024
2 parents b5a1856 + b27b18f commit b5c5543
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
version = "0.3.0"
version = "0.3.1"
commit = "none"
date = "unknown"
)
Expand Down Expand Up @@ -68,7 +68,12 @@ func normalize(repo string) string {
if len(match) != 3 {
return ""
}
path := strings.Trim(match[2], "/.git~")
path := match[2]
path = strings.TrimPrefix(path, "/")
path = strings.TrimPrefix(path, "~")
path = strings.TrimPrefix(path, "/")
path = strings.TrimSuffix(path, "/")
path = strings.TrimSuffix(path, ".git")

return filepath.Join(match[1], path)
}
Expand Down
7 changes: 7 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ func Test_getProjectDir(t *testing.T) {
gitProjectDir: "src",
want: "src/host.xz/user/path/to/repo",
},
{
name: "src",
repository: "git@github.com:go-git/go-git.git",
homeVar: "/home/test",
gitProjectDir: "src",
want: "src/github.com/go-git/go-git",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit b5c5543

Please sign in to comment.