Skip to content

Consume push URLs when they are provided #1191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const (
extensionsSection = "extensions"
fetchKey = "fetch"
urlKey = "url"
pushurlKey = "pushurl"
bareKey = "bare"
worktreeKey = "worktree"
commentCharKey = "commentChar"
Expand Down Expand Up @@ -633,6 +634,7 @@ func (c *RemoteConfig) unmarshal(s *format.Subsection) error {

c.Name = c.raw.Name
c.URLs = append([]string(nil), c.raw.Options.GetAll(urlKey)...)
c.URLs = append(c.URLs, c.raw.Options.GetAll(pushurlKey)...)
c.Fetch = fetch
c.Mirror = c.raw.Options.Get(mirrorKey) == "true"

Expand Down
24 changes: 24 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,27 @@ func (s *ConfigSuite) TestRemoveUrlOptions(c *C) {
}
c.Assert(err, IsNil)
}

func (s *ConfigSuite) TestUnmarshalRemotes(c *C) {
input := []byte(`[core]
bare = true
worktree = foo
custom = ignored
[user]
name = John Doe
email = john@example.com
[remote "origin"]
url = https://git.sr.ht/~mcepl/go-git
pushurl = git@git.sr.ht:~mcepl/go-git.git
fetch = +refs/heads/*:refs/remotes/origin/*
mirror = true
`)

cfg := NewConfig()
err := cfg.Unmarshal(input)
c.Assert(err, IsNil)

c.Assert(cfg.Remotes["origin"].URLs[0], Equals, "https://git.sr.ht/~mcepl/go-git")
c.Assert(cfg.Remotes["origin"].URLs[1], Equals, "git@git.sr.ht:~mcepl/go-git.git")
}

6 changes: 3 additions & 3 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (r *Remote) String() string {
var fetch, push string
if len(r.c.URLs) > 0 {
fetch = r.c.URLs[0]
push = r.c.URLs[0]
push = r.c.URLs[len(r.c.URLs)-1]
}

return fmt.Sprintf("%s\t%s (fetch)\n%[1]s\t%[3]s (push)", r.c.Name, fetch, push)
Expand All @@ -110,8 +110,8 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
return fmt.Errorf("remote names don't match: %s != %s", o.RemoteName, r.c.Name)
}

if o.RemoteURL == "" {
o.RemoteURL = r.c.URLs[0]
if o.RemoteURL == "" && len(r.c.URLs) > 0 {
o.RemoteURL = r.c.URLs[len(r.c.URLs)-1]
}

s, err := newSendPackSession(o.RemoteURL, o.Auth, o.InsecureSkipTLS, o.CABundle, o.ProxyOptions)
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy