Add a module-override option to the checkout command

This can be used to override the revision for a module in the given
manifest.
This commit is contained in:
Bernd Ahlers
2017-04-29 16:03:54 +02:00
parent 473d7c9168
commit 9e6369006a
5 changed files with 133 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"fmt"
"github.com/pkg/errors"
"path/filepath"
"strings"
@@ -27,6 +28,21 @@ func ParseGitHubURL(url string) (GitHubURL, error) {
return gitHubURL, nil
}
func ReplaceGitHubURL(url string, repoName string) (string, error) {
name := strings.TrimSuffix(repoName, ".git")
switch {
case strings.HasPrefix(url, "github://"):
return fmt.Sprintf("github://%s.git", name), nil
case strings.HasPrefix(url, "git@github"):
return fmt.Sprintf("git@github.com:%s.git", name), nil
case strings.HasPrefix(url, "https://github"):
return fmt.Sprintf("https://github.com/%s.git", name), nil
default:
return "", errors.Errorf("unknown GitHub URL: %s", url)
}
}
type GitHubURL struct {
Repository string
}

View File

@@ -65,3 +65,38 @@ func TestParseGitHubURL(t *testing.T) {
t.Error("expected unknown URL to fail")
}
}
func TestReplaceGitHubURL(t *testing.T) {
url, _ := ReplaceGitHubURL("github://Graylog2/graylog2-server.git", "foo/graylog2-server")
expected := "github://foo/graylog2-server.git"
if url != expected {
t.Errorf("expected <%s> but got <%s>", expected, url)
}
url, _ = ReplaceGitHubURL("github://Graylog2/graylog2-server.git", "foo/graylog2-server.git")
expected = "github://foo/graylog2-server.git"
if url != expected {
t.Errorf("expected <%s> but got <%s>", expected, url)
}
url, _ = ReplaceGitHubURL("https://github.com/Graylog2/graylog2-server.git", "foo/graylog2-server")
expected = "https://github.com/foo/graylog2-server.git"
if url != expected {
t.Errorf("expected <%s> but got <%s>", expected, url)
}
url, _ = ReplaceGitHubURL("https://github.com/Graylog2/graylog2-server.git", "foo/graylog2-server.git")
expected = "https://github.com/foo/graylog2-server.git"
if url != expected {
t.Errorf("expected <%s> but got <%s>", expected, url)
}
url, _ = ReplaceGitHubURL("https://github.com/Graylog2/graylog2-server.git", "foo/graylog2-server")
expected = "https://github.com/foo/graylog2-server.git"
if url != expected {
t.Errorf("expected <%s> but got <%s>", expected, url)
}
url, _ = ReplaceGitHubURL("https://github.com/Graylog2/graylog2-server.git", "foo/graylog2-server.git")
expected = "https://github.com/foo/graylog2-server.git"
if url != expected {
t.Errorf("expected <%s> but got <%s>", expected, url)
}
}