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:
Batuhan Apaydın
2021-09-15 19:12:45 +00:00
committed by GitHub
parent afad409c76
commit 4fb4ee67af
5 changed files with 25 additions and 4 deletions
+2 -2
View File
@@ -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)
}
+13
View File
@@ -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{
+1 -1
View File
@@ -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())
}
+1 -1
View File
@@ -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())
}
+8
View File
@@ -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()