Skip to content

Commit

Permalink
accept replacements with branches of github forks (#51)
Browse files Browse the repository at this point in the history
* accept replacements with branches of github forks

Closes #50

* remove `!filepath.IsAbs(repl)` when checking path of replacement

If the replacement path starts with a `.`, then the path is definitely not absolute.
  • Loading branch information
mohammed90 committed Feb 26, 2021
1 parent 8365548 commit 83bc5a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/xcaddy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func runBuild(ctx context.Context, args []string) error {
})
if repl != "" {
// adjust relative replacements in current working directory since our temporary module is in a different directory
if !filepath.IsAbs(repl) {
if strings.HasPrefix(repl, ".") {
repl, err = filepath.Abs(repl)
if err != nil {
log.Fatalf("[FATAL] %v", err)
Expand Down Expand Up @@ -288,9 +288,13 @@ func trapSignals(ctx context.Context, cancel context.CancelFunc) {
func splitWith(arg string) (module, version, replace string, err error) {
const versionSplit, replaceSplit = "@", "="

parts := strings.SplitN(arg, versionSplit, 2)
module = parts[0]
modules := strings.SplitN(arg, replaceSplit, 2)
if len(modules) > 1 {
replace = modules[1]
}

parts := strings.SplitN(modules[0], versionSplit, 2)
module = parts[0]
if len(parts) == 1 {
parts := strings.SplitN(module, replaceSplit, 2)
if len(parts) > 1 {
Expand Down
11 changes: 11 additions & 0 deletions cmd/xcaddy/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ func TestSplitWith(t *testing.T) {
expectModule: "module",
expectReplace: "replace",
},
{
input: "module=replace@version",
expectModule: "module",
expectReplace: "replace@version",
},
{
input: "module@version=replace@version",
expectModule: "module",
expectVersion: "version",
expectReplace: "replace@version",
},
{
input: "=replace",
expectErr: true,
Expand Down

0 comments on commit 83bc5a7

Please sign in to comment.