Skip to content

Commit

Permalink
feat: better support for cloning forked repos (#139)
Browse files Browse the repository at this point in the history
<!-- 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
  • Loading branch information
hashtagchris authored Jul 23, 2024
1 parent 4d1e886 commit eb6d5ef
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/gh/workers/_common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ export const clone = ({ argv, item }) => [
mkdirp({ argv, item }),
[
'gh',
['repo', 'clone', `${item.owner}/${item.name}`],
// template-oss will use upstream over origin, so we supply an alternate remote name for forked repos
['repo', 'clone', `${item.owner}/${item.name}`, '-u', 'parent'],
{
cwd: item.ownerDir,
status: ({ status, output }) =>
status === 1 && output.includes('already exists') && 0,
},
],
// choose the forked repo as the default, for operations like template-oss-fix
// See https://github.com/cli/cli/issues/9261#issuecomment-2193936803
['gh',
['repo', 'set-default', `${item.owner}/${item.name}`],
],
]

export const checkout = ({ argv }) => [
Expand Down

0 comments on commit eb6d5ef

Please sign in to comment.