Skip to content

More nuanced handling of parent/fork in various commands#355

Merged
vilmibm merged 12 commits intocli:masterfrom
vilmibm:pr-parent-repo
Feb 12, 2020
Merged

More nuanced handling of parent/fork in various commands#355
vilmibm merged 12 commits intocli:masterfrom
vilmibm:pr-parent-repo

Conversation

@vilmibm
Copy link
Contributor

@vilmibm vilmibm commented Feb 12, 2020

This PR:

  • moves the code @mislav added for detecting parent/fork relationships in pr create to the context package
  • wraps that code in a helper in the command package
  • improves support for respecting --repo/-R
  • uses the wrapper in pr list, status, view
  • uses the wrapper in pr checkout i'm going to leave this alone for now since it has slightly different behavior
  • uses the wrapper in the issue commands
  • fixes tests

closes #251

performance note

I unscientifically benchmarked the before/after of doing this check. The time hit averaged about .2 sec on my machine/wifi. subjectively it was imperceptible and I don't think caching is urgent.

Originally based on #348

@vilmibm
Copy link
Contributor Author

vilmibm commented Feb 12, 2020

rubber ducking:

There is desire for a --self flag to say "even if the repo i'm working in is a fork, I really want you to query it for PRs and issues because it's a special fork with work that will never go upstream."

This seemed very reasonable but now that I'm working on it I'm remembering that the concept of "no, THIS repo" is really fraught on the CLI. All we have to go on is .git and there is no "this" repo beyond what we can deduce from the list of remotes. If all you have is one remote and it's a fork, we can then say that "this" repo (the "self") repo is the fork and there is a parent out in the aether of github.

But as soon as you have remotes like this:

origin    git@github.com:vilmibm/cli.git (fetch)
origin    git@github.com:vilmibm/cli.git (push)
upstream  git@github.com:cli/cli.git (fetch)
upstream  git@github.com:cli/cli.git (push)

words like "this" and "self" lose meaning. you could say that origin is the standard for "this" but origin could just as easily be a parent repo that you initially cloned then added a remote for. all along, git sees three repos (local, parent on github.com, fork on github.com) while it's common day to day as humans to only think in terms of two repos (parent on github.com, fork on github.com).

Personally, I prefer just having -R so you can be super explicit and not have to think of what "self" might mean at any given time.

Given all this thinking I'm going to kick the --self can down the road for a bit longer and remove support for it from this PR and note that I improved handling for --repo / -R to ensure that forks/parents can be explicitly chosen between when the automatic detection isn't sufficient.

I'm/we're open to other thoughts here but given that a big goal of gh is to be pretty carefully designed I'd rather wait for now on --self and rely on -R for now.

@vilmibm
Copy link
Contributor Author

vilmibm commented Feb 12, 2020

having to update the API fixtures to make the tests happy again and it's taking a while. will resume doing that in the morning.

@vilmibm vilmibm marked this pull request as ready for review February 12, 2020 15:00
@vilmibm vilmibm requested a review from outofambit February 12, 2020 15:04
Copy link
Contributor

@outofambit outofambit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good overall! i think pulling the remote resolution into context was a good choice. left a suggestion to simplify one new method.

after looking at the tests, i'm also appreciating the simplicity of the -R override flag

Comment on lines +112 to +114
// additionally, look up the resolved repository name in case this
// git remote points to this repository via a redirect
(r.Network.Repositories[i] != nil && ghrepo.IsSame(r.Network.Repositories[i], repo)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Comment on lines +38 to +40
hasBaseOverride := base != ""
baseOverride := ghrepo.FromFullName(base)
foundBaseOverride := false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not that familiar with golang types, do they have optionals or nullables? it feels like baseOverride could be "string or nah", and we could eliminate hasBaseOverride or maybe the logic flow could go

if (base !== '') attempt to add base override repo to repos list
else get resolved remotes

the main reason i'm suggesting this is it took me awhile to tease apart the different pieces of control logic in this function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is not an optional type D: this is just kind of how golang would have us do unfortunately.

@vilmibm vilmibm merged commit c27d780 into cli:master Feb 12, 2020
Stonre pushed a commit to Stonre/strands-fork that referenced this pull request Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After cloning a fork, pr status will query the wrong base repo

3 participants