From 51ee4ed91e9670063ebee69578a43dc672599a9d Mon Sep 17 00:00:00 2001 From: Sebastian <5648131+polyrainbow@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:55:57 +0100 Subject: [PATCH] getGitRepoContext gives the repository the clone pushes to, whatever -R selects getCurrentRepoContext answers with --repo/-R or TANG_REPO when either is set, so a command had no way to ask which Tangled repository the local remotes point to once another was selected. A pull request from a fork needs both: the repository it is opened in, and the one its head branch was pushed to. The git-remote half of getCurrentRepoContext is now getGitRepoContext, which getCurrentRepoContext falls through to when nothing overrides it. Seen red first: getGitRepoContext with TANG_REPO set. Co-Authored-By: Claude Opus 5.5 --- src/lib/context.ts | 12 ++++++++++++ tests/lib/context.test.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/lib/context.ts b/src/lib/context.ts index f83c8d6..04f290a 100644 --- a/src/lib/context.ts +++ b/src/lib/context.ts @@ -246,6 +246,18 @@ export async function getCurrentRepoContext( if (override) { return parseRepositoryInput(override, (explicitRepo ?? runtime.repo) ? 'flag' : 'environment'); } + return getGitRepoContext(cwd); +} + +/** + * The repository this clone's Git remotes point to, whatever --repo/-R or + * TANG_REPO select: where a branch is pushed, so where a pull request from a + * fork takes its head from. + */ +export async function getGitRepoContext( + cwd: string = process.cwd() +): Promise { + const runtime = getRuntimeOptions(); // Get all tangled remotes const remotes = await getTangledRemotes(cwd); diff --git a/tests/lib/context.test.ts b/tests/lib/context.test.ts index c98bfa3..a09640b 100644 --- a/tests/lib/context.test.ts +++ b/tests/lib/context.test.ts @@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import type { RepositoryContext } from '../../src/lib/context.js'; import { getCurrentRepoContext, + getGitRepoContext, getTangledRemotes, promptForRemote, } from '../../src/lib/context.js'; @@ -433,4 +434,32 @@ describe('Context Resolution', () => { consoleWarnSpy.mockRestore(); }); }); + + describe('getGitRepoContext', () => { + it('gives the repository the clone pushes to even when TANG_REPO selects another', async () => { + vi.mocked(simpleGit).mockReturnValue({ + checkIsRepo: vi.fn().mockResolvedValue(true), + getRemotes: vi + .fn() + .mockResolvedValue([ + { name: 'origin', refs: { fetch: 'git@tangled.org:fork.example/tangled-cli' } }, + ]), + } as never); + process.env.TANG_REPO = 'upstream.example/tangled-cli'; + try { + expect(await getCurrentRepoContext()).toMatchObject({ + owner: 'upstream.example', + selectionSource: 'environment', + }); + expect(await getGitRepoContext()).toMatchObject({ + owner: 'fork.example', + name: 'tangled-cli', + remoteName: 'origin', + selectionSource: 'git', + }); + } finally { + delete process.env.TANG_REPO; + } + }); + }); }); -- knotmirror 0.0.1