fix(trail): skip local-origin enablement cache under --repo · Entire
fix(trail): skip local-origin enablement cache under --repo
e30a965·
toothbrush·3w ago·4 files·+22 added/-10 removed
The trails-enablement cache is keyed to the local clone's origin. With a --repo override the queried repo differs, so recording enablement (noteTrailCommandEnablement on every authenticated call, plus watch's explicit save) would mis-attribute it to the local repo — and the error path would make a spurious enablement call about the wrong repo. Thread the override into runAuthenticatedTrailAPI and skip the cache writes when it is set.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
3ff3830dba23View transcript
Changes
4
cmd/entire/cli
Mtrail_cmd.go+7/-5
Mtrail_context_cache.go+9/-2
Mtrail_review_cmd.go+1/-1
Mtrail_watch_cmd.go+5/-2
170 unmodified lines
171
172
173
174
174
175
176
177
208 unmodified lines
386
387
388
389
389
390
391
392
662 unmodified lines
1055
1056
1057
1058
1058
1059
1060
1061
204 unmodified lines
1266
1267
1268
1269
1269
1270
1271
1272
1273
1274
101 unmodified lines
1376
1377
1378
1377
1379
1380
1381
1382
170 unmodified lines
// runTrailShow shows one trail, defaulting to the current branch's trail.
func runTrailShow(ctx context.Context, w, errW io.Writer, insecureHTTP bool, selector, repoOverride, branchOverride string) error {
return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error {
return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, repoOverride, func(ctx context.Context, client *api.Client) error {
forge, owner, repo, err := resolveTrailRepoOrRemote(ctx, repoOverride)
if err != nil {
return err
}
return runTrailListAllWithClient(ctx, w, client, opts, statusFilters)
})
})
}
func runTrailUpdate(ctx context.Context, w, errW io.Writer, insecureHTTP bool, inputs trailUpdateInputs) error {
return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error {
return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, inputs.Repo, func(ctx context.Context, client *api.Client) error {
forge, owner, repoName, err := resolveTrailRepoOrRemote(ctx, inputs.Repo)
if err != nil {
return err
}
return nil
})
})
}
func runTrailCheckout(ctx context.Context, w, errW io.Writer, insecureHTTP bool, selector string, force bool) error {
return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error {
// checkout rejects --repo (it operates on the local clone), so the enablement
// cache always tracks the local origin here.
return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, "", func(ctx context.Context, client *api.Client) error {
forge, owner, repo, err := resolveTrailRemote(ctx)
if err != nil {
return err
}
return nil
})
})
}
func runAuthenticatedTrailAPI(ctx context.Context, errW io.Writer, insecureHTTP bool, fn func(context.Context, *api.Client) error) error {
// runAuthenticatedTrailAPI runs fn against the data API as the current user.
return runAuthenticatedDataAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error {
err := fn(ctx, client)
noteTrailCommandEnablement(ctx, client, err)
return err
})
}
Mcmd/entire/cli/trail_context_cache.go+9/-2
478 unmodified lines
479
480
481
482
482
483
484
485
478 unmodified lines
}
var target trailReviewTarget
var resolvedClient *api.Client
err := runAuthenticatedTrailAPI(cmd.Context(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd), func(ctx context.Context, client *api.Client) error {
err := runAuthenticatedTrailAPI(cmd.Context(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd), repoOverride, func(ctx context.Context, client *api.Client) error {
var err error
resolvedClient = client
target, err = resolveTrailReviewTarget(ctx, client, selector, repoOverride, branchOverride)
if err != nil {
return err
}
return nil
})
}
Mcmd/entire/cli/trail_review_cmd.go+1/-1
91 unmodified lines
92 93 94 95 95 96 97 98 99 100 100 101 102 103 104 105 106
91 unmodified lines
}
func runTrailWatch(cmd *cobra.Command, number int, repoOverride, branchOverride string, jsonOutput, showPings, once bool) error { return runAuthenticatedTrailAPI(cmd.Context(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd), func(ctx context.Context, client *api.Client) error { return runAuthenticatedTrailAPI(cmd.Context(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd), repoOverride, func(ctx context.Context, client *api.Client) error { trailID, description, err := resolveTrailWatchTarget(ctx, client, number, repoOverride, branchOverride) if err != nil { return err } saveTrailsEnabledForRepoBestEffort(ctx, true) // Skip the local-origin enablement cache when --repo targets another repo. if repoOverride == "" { saveTrailsEnabledForRepoBestEffort(ctx, true) } return nil }) }) }
Mcmd/entire/cli/trail_watch_cmd.go+5/-2