mirror of
https://github.com/goreleaser/goreleaser.git
synced 2026-06-19 23:24:39 +02:00
feat: Allow to specify the git remote name (#2486)
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com> Co-authored-with: Erkan Zileli <erkan.zileli@trendyol.com> Co-authored-with: Furkan Türkal <furkan.turkal@trendyol.com>
This commit is contained in:
@@ -14,9 +14,9 @@ func ExtractRepoFromConfig() (result config.Repo, err error) {
|
||||
if !IsRepo() {
|
||||
return result, errors.New("current folder is not a git repository")
|
||||
}
|
||||
out, err := Run("config", "--get", "remote.origin.url")
|
||||
out, err := Run("ls-remote", "--get-url")
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("repository doesn't have an `origin` remote")
|
||||
return result, fmt.Errorf("no remote configured to list refs from")
|
||||
}
|
||||
return ExtractRepoFromURL(out)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,19 @@ func TestRepoName(t *testing.T) {
|
||||
require.Equal(t, "goreleaser/goreleaser", repo.String())
|
||||
}
|
||||
|
||||
func TestRepoNameWithDifferentRemote(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
testlib.GitRemoteAddWithName(t, "upstream", "https://github.com/goreleaser/goreleaser.git")
|
||||
_, err := git.Run("pull", "upstream", "master")
|
||||
require.NoError(t, err)
|
||||
_, err = git.Run("branch", "--set-upstream-to", "upstream/master")
|
||||
require.NoError(t, err)
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "goreleaser/goreleaser", repo.String())
|
||||
}
|
||||
|
||||
func TestExtractRepoFromURL(t *testing.T) {
|
||||
// valid urls
|
||||
for _, url := range []string{
|
||||
|
||||
@@ -79,7 +79,7 @@ func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
||||
}
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
testlib.GitInit(t)
|
||||
require.EqualError(t, Pipe{}.Default(ctx), "repository doesn't have an `origin` remote")
|
||||
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
|
||||
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -476,7 +476,7 @@ func TestDefaultGitRepoWithoutOrigin(t *testing.T) {
|
||||
}
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
testlib.GitInit(t)
|
||||
require.EqualError(t, Pipe{}.Default(ctx), "repository doesn't have an `origin` remote")
|
||||
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
|
||||
require.Empty(t, ctx.Config.Release.GitHub.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,14 @@ func GitRemoteAdd(tb testing.TB, url string) {
|
||||
require.Empty(tb, out)
|
||||
}
|
||||
|
||||
// GitRemoteAddWithName adds the given url as remote with given name.
|
||||
func GitRemoteAddWithName(tb testing.TB, remote, url string) {
|
||||
tb.Helper()
|
||||
out, err := fakeGit("remote", "add", remote, url)
|
||||
require.NoError(tb, err)
|
||||
require.Empty(tb, out)
|
||||
}
|
||||
|
||||
// GitCommit creates a git commits.
|
||||
func GitCommit(tb testing.TB, msg string) {
|
||||
tb.Helper()
|
||||
|
||||
Reference in New Issue
Block a user