Skip to content

Commit 1a5de68

Browse files
authored
Merge pull request #1624 from entireio/fix-stale-entire-repo-comments
checkpoint/remote: remove dead entiredb-original-url read path
2 parents 6a41271 + de68c54 commit 1a5de68

2 files changed

Lines changed: 14 additions & 66 deletions

File tree

cmd/entire/cli/checkpoint/remote/util.go

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func FetchURL(ctx context.Context, opts ...FetchURLOptions) (string, error) {
115115
// Origin's protocol can't be mapped to a git transport (e.g. entire://,
116116
// file://). Honor the configured checkpoint_remote by targeting the
117117
// provider's canonical host over HTTPS rather than falling back to origin.
118-
if providerURL, ok := resolveProviderCheckpointURL(config, originRemote, opt.WorktreeRoot); ok {
118+
if providerURL, ok := resolveProviderCheckpointURL(config, opt.WorktreeRoot); ok {
119119
return providerURL, nil
120120
}
121121
logFallback(ctx, "fetch", originURL, "derive checkpoint remote URL", err)
@@ -223,7 +223,7 @@ func PushURL(ctx context.Context, pushRemoteName string) (string, bool, error) {
223223
// (e.g. entire://, file://). Honor the configured checkpoint_remote by
224224
// targeting the provider's canonical host over HTTPS rather than
225225
// misrouting checkpoints to the origin remote.
226-
if providerURL, ok := resolveProviderCheckpointURL(config, pushRemoteName, ""); ok {
226+
if providerURL, ok := resolveProviderCheckpointURL(config, ""); ok {
227227
return providerURL, true, nil
228228
}
229229
fallbackURL, fallbackErr := resolvePushFallbackURL(ctx, pushRemoteName, originURL)
@@ -309,12 +309,6 @@ func deriveCheckpointURLFromInfo(info *Info, config *settings.CheckpointRemoteCo
309309
}
310310
}
311311

312-
// originalURLConfigKey is the git config option, under remote.<name>., where
313-
// entiredb's `entire-repo mirror use` records the URL a remote had before it was
314-
// switched to entire://. It is the most faithful record of the endpoint and auth
315-
// method the user had for that remote.
316-
const originalURLConfigKey = "entiredb-original-url"
317-
318312
// resolveProviderCheckpointURL builds the checkpoint URL for the configured
319313
// provider, choosing the transport from what's already configured for that
320314
// endpoint. It is the fallback used when the push/origin remote's protocol can't
@@ -323,24 +317,21 @@ const originalURLConfigKey = "entiredb-original-url"
323317
// than being misrouted to the origin remote.
324318
//
325319
// Transport precedence:
326-
// 1. The remote's pre-mirror URL (remote.<name>.entiredb-original-url) — the
327-
// endpoint and scheme the remote used before `entire-repo mirror use`
328-
// switched it to entire://. Reused verbatim (host + scheme + port).
329-
// 2. ENTIRE_CHECKPOINT_TOKEN set -> HTTPS on the provider host (the token is
320+
// 1. ENTIRE_CHECKPOINT_TOKEN set -> HTTPS on the provider host (the token is
330321
// the credential).
331-
// 3. An existing remote already targets the provider host -> reuse its scheme,
322+
// 2. An existing remote already targets the provider host -> reuse its scheme,
332323
// so checkpoints use the same auth the user already has for that endpoint.
333-
// 4. Otherwise SSH on the provider host.
324+
// 3. Otherwise SSH on the provider host.
334325
//
335326
// Returns ok=false when no transport can be determined (unknown provider with no
336327
// usable signal), in which case the caller falls back to the origin remote.
337-
func resolveProviderCheckpointURL(config *settings.CheckpointRemoteConfig, remoteName, dir string) (string, bool) {
328+
func resolveProviderCheckpointURL(config *settings.CheckpointRemoteConfig, dir string) (string, bool) {
338329
repo, err := openRepoAt(dir)
339330
if err != nil {
340331
repo = nil // Fall back to env/provider-only signals.
341332
}
342333

343-
info, ok := pickProviderTransport(repo, config, remoteName)
334+
info, ok := pickProviderTransport(repo, config)
344335
if !ok {
345336
return "", false
346337
}
@@ -354,31 +345,22 @@ func resolveProviderCheckpointURL(config *settings.CheckpointRemoteConfig, remot
354345
// pickProviderTransport returns the protocol/host/port to use when deriving a
355346
// checkpoint URL, following the precedence documented on
356347
// resolveProviderCheckpointURL.
357-
func pickProviderTransport(repo *git.Repository, config *settings.CheckpointRemoteConfig, remoteName string) (*Info, bool) {
358-
// 1. The remote's saved pre-mirror URL: the endpoint and auth the user had.
359-
if repo != nil {
360-
if original := originalRemoteURL(repo, remoteName); original != "" {
361-
if info, err := gitremote.ParseURL(original); err == nil && isDerivableProtocol(info.Protocol) {
362-
return info, true
363-
}
364-
}
365-
}
366-
348+
func pickProviderTransport(repo *git.Repository, config *settings.CheckpointRemoteConfig) (*Info, bool) {
367349
host, hostOK := providerHost(config.Provider)
368350

369-
// 2. Explicit token -> HTTPS on the provider host.
351+
// 1. Explicit token -> HTTPS on the provider host.
370352
if hostOK && strings.TrimSpace(os.Getenv(CheckpointTokenEnvVar)) != "" {
371353
return &Info{Protocol: ProtocolHTTPS, Host: host}, true
372354
}
373355

374-
// 3. An existing remote already targeting the provider host -> reuse scheme.
356+
// 2. An existing remote already targeting the provider host -> reuse scheme.
375357
if hostOK && repo != nil {
376358
if info, ok := findRemoteInfoForHost(repo, host); ok {
377359
return &Info{Protocol: info.Protocol, Host: info.Host, Port: info.Port}, true
378360
}
379361
}
380362

381-
// 4. Default to SSH on the provider host.
363+
// 3. Default to SSH on the provider host.
382364
if hostOK {
383365
return &Info{Protocol: ProtocolSSH, Host: host}, true
384366
}
@@ -399,16 +381,6 @@ func openRepoAt(dir string) (*git.Repository, error) {
399381
return repo, nil
400382
}
401383

402-
// originalRemoteURL returns the pre-mirror URL saved by `entire-repo mirror use`
403-
// in remote.<name>.entiredb-original-url, or "" when absent.
404-
func originalRemoteURL(repo *git.Repository, remoteName string) string {
405-
cfg, err := repo.Config()
406-
if err != nil {
407-
return ""
408-
}
409-
return cfg.Raw.Section("remote").Subsection(remoteName).Option(originalURLConfigKey)
410-
}
411-
412384
// findRemoteInfoForHost returns the parsed Info of the first configured git
413385
// remote (in deterministic name order) whose host matches host and whose
414386
// protocol is a usable git transport (ssh/https). entire:// and other

cmd/entire/cli/checkpoint/remote/util_test.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -401,38 +401,17 @@ func TestPushURL(t *testing.T) {
401401
// setup: origin migrated to an entire:// URL (forge-prefixed /gh/owner/repo)
402402
// with a github checkpoint_remote. The checkpoint URL must route to github
403403
// rather than fall back to the entire:// origin, reusing the auth/scheme the
404-
// repo had for that endpoint — first from the pre-mirror URL that
405-
// `entire-repo mirror use` saves (remote.origin.entiredb-original-url), then an
406-
// existing remote on the provider host, then defaulting to SSH.
404+
// repo had for that endpoint — a token forces HTTPS, then an existing remote
405+
// on the provider host, then defaulting to SSH.
407406
func TestPushURL_EntireOriginReusesProviderRemoteScheme(t *testing.T) {
408407
const entireOrigin = "entire://aws-eu-central-1.entire.io/gh/entireio/cli"
409408
tests := []struct {
410409
name string
411410
githubURL string
412-
savedURL string
413411
token string
414412
wantURL string
415413
wantEnabled bool
416414
}{
417-
{
418-
name: "pre-mirror ssh url yields ssh checkpoint url",
419-
savedURL: "git@github.com:entireio/cli.git",
420-
wantURL: "git@github.com:entireio/cli-checkpoints.git",
421-
wantEnabled: true,
422-
},
423-
{
424-
name: "pre-mirror https url yields https checkpoint url",
425-
savedURL: "https://github.com/entireio/cli.git",
426-
wantURL: "https://github.com/entireio/cli-checkpoints.git",
427-
wantEnabled: true,
428-
},
429-
{
430-
name: "pre-mirror url wins over token",
431-
savedURL: "git@github.com:entireio/cli.git",
432-
token: "ci-token",
433-
wantURL: "git@github.com:entireio/cli-checkpoints.git",
434-
wantEnabled: true,
435-
},
436415
{
437416
name: "ssh github remote yields ssh checkpoint url",
438417
githubURL: "git@github.com:entireio/cli.git",
@@ -451,7 +430,7 @@ func TestPushURL_EntireOriginReusesProviderRemoteScheme(t *testing.T) {
451430
wantEnabled: true,
452431
},
453432
{
454-
name: "token forces https when no pre-mirror url",
433+
name: "token forces https over existing ssh remote",
455434
githubURL: "git@github.com:entireio/cli.git",
456435
token: "ci-token",
457436
wantURL: "https://github.com/entireio/cli-checkpoints.git",
@@ -467,9 +446,6 @@ func TestPushURL_EntireOriginReusesProviderRemoteScheme(t *testing.T) {
467446
if tt.githubURL != "" {
468447
runGit(t, repoDir, "remote", "add", "github", tt.githubURL)
469448
}
470-
if tt.savedURL != "" {
471-
runGit(t, repoDir, "config", "remote.origin.entiredb-original-url", tt.savedURL)
472-
}
473449
writeSettings(t, repoDir, `{"enabled":true,"strategy_options":{"checkpoint_remote":{"provider":"github","repo":"entireio/cli-checkpoints"}}}`)
474450
t.Chdir(repoDir)
475451
if tt.token != "" {

0 commit comments

Comments
 (0)