Skip to content

Commit

Permalink
feat: Allow to specify the git remote name (#2486)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
developer-guy committed Sep 15, 2021
1 parent afad409 commit 4fb4ee6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/git/config.go
Expand Up @@ -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)
}
Expand Down
13 changes: 13 additions & 0 deletions internal/git/config_test.go
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/pipe/milestone/milestone_test.go
Expand Up @@ -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())
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pipe/release/release_test.go
Expand Up @@ -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())
}

Expand Down
8 changes: 8 additions & 0 deletions internal/testlib/git.go
Expand Up @@ -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()
Expand Down

1 comment on commit 4fb4ee6

@vercel
Copy link

@vercel vercel bot commented on 4fb4ee6 Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.