Skip to content

Commit eb6d5ef

Browse files
authored
feat: better support for cloning forked repos (#139)
<!-- What / Why --> <!-- Describe the request in detail. What it does and why it's being changed. --> By default the gh cli operates against the upstream repo when you run commands like `gh pr checkout ...`. For the purposes of stafftools, we want to operate against the forked repo, so we run `gh repo set-default npm/{name}`. Tested with `node ./bin/gh.mjs template-oss-fix --install --filter 'name:json-parse-even-better-errors'` after removing `~/projects/npm/json-parse-even-better-errors`. Also tested with `node ./bin/gh.mjs repos clone --filter "name:agent"`, to ensure clone still works for non-forked repos. ## References <!-- Examples: Related to #0 Depends on #0 Blocked by #0 Fixes #0 Closes #0 --> Change to favor the upstream remote: npm/template-oss#363 npm/json-parse-even-better-errors#65 cli/cli#9261 (comment) cli/cli#6777
1 parent 4d1e886 commit eb6d5ef

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/gh/workers/_common.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ export const clone = ({ argv, item }) => [
88
mkdirp({ argv, item }),
99
[
1010
'gh',
11-
['repo', 'clone', `${item.owner}/${item.name}`],
11+
// template-oss will use upstream over origin, so we supply an alternate remote name for forked repos
12+
['repo', 'clone', `${item.owner}/${item.name}`, '-u', 'parent'],
1213
{
1314
cwd: item.ownerDir,
1415
status: ({ status, output }) =>
1516
status === 1 && output.includes('already exists') && 0,
1617
},
1718
],
19+
// choose the forked repo as the default, for operations like template-oss-fix
20+
// See https://github.com/cli/cli/issues/9261#issuecomment-2193936803
21+
['gh',
22+
['repo', 'set-default', `${item.owner}/${item.name}`],
23+
],
1824
]
1925

2026
export const checkout = ({ argv }) => [

0 commit comments

Comments
 (0)