-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from b4nst/feat/add-generic-git-package-support
feat: add generic git package manager
- Loading branch information
Showing
21 changed files
with
548 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package cache | ||
|
||
import ( | ||
"path" | ||
"strings" | ||
) | ||
|
||
func parseModURL(mod string) (remote, owner, repo string) { | ||
var flds []string | ||
if i := strings.Index(mod, ".git"); i > -1 { | ||
flds = strings.SplitN(mod[:i], "/", 3) | ||
} else { | ||
flds = strings.Split(mod, "/") | ||
} | ||
|
||
if len(flds) < 3 { | ||
return flds[0], "", flds[1] | ||
} | ||
|
||
return flds[0], flds[1], flds[2] | ||
} | ||
|
||
// MatchPrefixPatterns reports whether any path prefix of target matches one of | ||
// the glob patterns (as defined by path.Match) in the comma-separated globs | ||
// list. This implements the algorithm used when matching a module path to the | ||
// GOPRIVATE environment variable, as described by 'go help module-private'. | ||
// | ||
// It ignores any empty or malformed patterns in the list. | ||
func MatchPrefixPatterns(globs, target string) bool { | ||
for globs != "" { | ||
// Extract next non-empty glob in comma-separated list. | ||
var glob string | ||
if i := strings.Index(globs, ","); i >= 0 { | ||
glob, globs = globs[:i], globs[i+1:] | ||
} else { | ||
glob, globs = globs, "" | ||
} | ||
if glob == "" { | ||
continue | ||
} | ||
|
||
// A glob with N+1 path elements (N slashes) needs to be matched | ||
// against the first N+1 path elements of target, | ||
// which end just before the N+1'th slash. | ||
n := strings.Count(glob, "/") | ||
prefix := target | ||
// Walk target, counting slashes, truncating at the N+1'th slash. | ||
for i := 0; i < len(target); i++ { | ||
if target[i] == '/' { | ||
if n == 0 { | ||
prefix = target[:i] | ||
break | ||
} | ||
n-- | ||
} | ||
} | ||
if n > 0 { | ||
// Not enough prefix elements. | ||
continue | ||
} | ||
matched, _ := path.Match(glob, prefix) | ||
if matched { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cache | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
) | ||
|
||
func TestSplitMod(t *testing.T) { | ||
tests := map[string]struct { | ||
mod string | ||
expected string | ||
}{ | ||
"simple": {mod: "github.com/owner/repo", expected: "github.com/owner/repo"}, | ||
"submodule": {mod: "github.com/owner/repo/submodule", expected: "github.com/owner/repo"}, | ||
"complex": {mod: "gitlab.com/owner/repo.git/submodule", expected: "gitlab.com/owner/repo"}, | ||
"subgroup": {mod: "gitlab.com/owner/subgroup/repo.git", expected: "gitlab.com/owner/subgroup/repo"}, | ||
"subgroup+submodule": {mod: "gitlab.com/owner/subgroup/repo.git/submodule", expected: "gitlab.com/owner/subgroup/repo"}, | ||
"small": {mod: "cuelang.org/go", expected: "cuelang.org/go"}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
rm, o, rp := parseModURL(tc.mod) | ||
got := path.Join(rm, o, rp) | ||
if got != tc.expected { | ||
t.Fatalf("expected: %v, got: %s", tc.expected, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.