Skip to content
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: 1 addition & 1 deletion cmd/entire/cli/dispatch/mode_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func runServer(ctx context.Context, opts Options) (*Dispatch, error) {
// repo on the other forge cannot answer for this checkout.
repoSlug, err := resolveOriginRepoSlug(ctx, repo)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w (or pass --repos %s to name the repo)", err, RepoSlugShapes)
}
repos = []string{repoSlug}
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/entire/cli/dispatch/mode_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,20 +475,23 @@ func runGitOutput(ctx context.Context, repoRoot string, args ...string) (string,
// forge-qualified slug (gh/<owner>/<repo> or et/<project>/<repo>), read from
// the origin remote. The forge is whatever the remote points at, never
// assumed, so an Entire-native checkout is addressed as the native repo.
//
// Errors name no flag: local mode refuses --repos, so the hint to pass it
// belongs to the cloud caller alone.
func resolveOriginRepoSlug(ctx context.Context, repo *git.Repository) (string, error) {
remote, err := repo.Remote("origin")
if err != nil {
logging.Warn(ctx, "dispatch repo resolution failed", "step", "origin_remote", "error", err)
return "", fmt.Errorf("dispatch needs an origin remote on GitHub or Entire (or pass --repos %s): %w", RepoSlugShapes, err)
return "", fmt.Errorf("dispatch needs an origin remote on GitHub or Entire: %w", err)
}
if len(remote.Config().URLs) == 0 {
return "", fmt.Errorf("dispatch needs an origin remote URL on GitHub or Entire (or pass --repos %s)", RepoSlugShapes)
return "", errors.New("dispatch needs an origin remote URL on GitHub or Entire")
}

slug, err := OriginRepoSlug(remote.Config().URLs[0])
if err != nil {
logging.Warn(ctx, "dispatch repo resolution failed", "step", "parse_origin_remote", "error", err)
return "", fmt.Errorf("dispatch cannot address this checkout's origin (pass --repos to name the repo): %w", err)
return "", fmt.Errorf("dispatch cannot address this checkout's origin: %w", err)
}
return slug, nil
}
Expand Down
26 changes: 26 additions & 0 deletions cmd/entire/cli/dispatch/mode_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1363,3 +1363,29 @@ func addOriginRemoteURL(t *testing.T, repoDir, remoteURL string) {
t.Fatal(err)
}
}

// TestLocalMode_UnknownOriginHostDoesNotSuggestRepos: local mode refuses
// --repos, so an origin it cannot address must not point the user at it.
func TestLocalMode_UnknownOriginHostDoesNotSuggestRepos(t *testing.T) {
dir := t.TempDir()
testutil.InitRepo(t, dir)
testutil.WriteFile(t, dir, "a.txt", "x")
testutil.GitAdd(t, dir, "a.txt")
testutil.GitCommit(t, dir, "initial")
addOriginRemoteURL(t, dir, "https://gitlab.com/acme/thing.git")

t.Chdir(dir)

_, err := Run(context.Background(), Options{
Mode: ModeLocal,
Since: "7d",
Branches: []string{"main"},
TextGenerator: stubGeneratedLocalDispatch(),
})
if err == nil || !strings.Contains(err.Error(), "gitlab.com") {
t.Fatalf("expected an error naming the host, got %v", err)
}
if strings.Contains(err.Error(), "--repos") {
t.Fatalf("local mode refuses --repos, so its error must not suggest it, got %v", err)
}
}
Loading