# Merge pull request \#82 from entireio/fix/credential-host-port

`d67c10d`→[main](/content/gh/entireio/git-sync/commits/main/index.html)·

Soph·1mo ago·2 files·+20 added/-1 removed

Include the port in the git-credential host field

## Changes

2

- internal/auth

- Mauth.go+4/-1

- Mauth_test.go+16

```
176 unmodified lines

177
178
179
180
180
181
182
183
184
185
186

176 unmodified lines

return ""
	}
	var b strings.Builder
	fmt.Fprintf(&b, "protocol=%s\nhost=%s\n", ep.Scheme, ep.Hostname())
	// gitcredentials(7) defines host as "host[:port]" — use ep.Host, which
	// keeps any non-default port. ep.Hostname() drops it, which would store
	// and look up credentials under the default-port entry instead.
	fmt.Fprintf(&b, "protocol=%s\nhost=%s\n", ep.Scheme, ep.Host)
	if path := strings.TrimPrefix(ep.Path, "/"); path != "" {
		fmt.Fprintf(&b, "path=%s\n", path)
	}
```

Minternal/auth/auth.go+4/-1

```
161 unmodified lines

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

161 unmodified lines

}
}

// A non-default port must appear in the host field (gitcredentials(7) host is
// "host[:port]"); otherwise credentials are stored/looked up under the wrong
// (default-port) entry.
func TestCredentialInput_IncludesPort(t *testing.T) {
	ep := &url.URL{
		Scheme: "https",
		Host:   "example.com:8443",
		Path:   "/repo.git",
	}
	got := credentialInput(ep, "", "")
	want := "protocol=https\nhost=example.com:8443\npath=repo.git\n\n"
	if got != want {
		t.Errorf("credentialInput returned:\n%q\nwant:\n%q", got, want)
	}
}

func TestCredentialInput_ApproveRejectFormatIncludesUserAndPassword(t *testing.T) {
	ep := &url.URL{
		Scheme: "https",
