On first run in a git repository, `BaseRepo()` will now prompt the user
which repository should be queried as base repository if there are
multiple git remotes or when we are in the context of a fork.
In non-interactive mode, the prompt is skipped and we default to the
first git remote instead.
After the base repo is resolved, the result is cached in the local
repository using `git config` so that RepositoryNetwork API lookups can
be avoided in the future.
This ensures that while having git remotes to point to either
`github.com` or authenticated GHE instances, adding another git remote
pointing to an unrelated host won't change the remote resolution in any
way, even if the unrelated remote is called `upstream` or `github` (and
thus normally took precedence).
Accept the "HOST/OWNER/REPO" syntax or passing a full URL for both the
`--repo` flag and the GH_REPO environment variable and allow setting
GH_HOST environment variable to override just the hostname for
operations that assume "github.com" by default.
Examples:
$ gh repo clone example.org/owner/repo
$ GH_HOST=example.org gh repo clone repo
$ GH_HOST=example.org gh api user
$ GH_HOST=example.org gh gist create myfile.txt
$ gh issue list -R example.org/owner/repo
$ gh issue list -R https://example.org/owner/repo.git
$ GH_REPO=example.org/owner/repo gh issue list
This commit hacks the existing repo clone tests into something usable by
the new isolated command. It went ok and was less effort than trying to
introduce the same kind of test format as repo view and gist create.
this adds recognition of the git_protocol setting when:
- creating a repo
- cloning a repo
- forking a repo
- forking/pushing during pr create
- checking out a PR
additionally, it:
- consolidates remote adding to use AddRemote; this introduces a fetch
where there previously hadn't been one
- changes repo clone to accept an ssh url
- changes repo fork to accept an ssh url
i just added basic unit tests; adding new test cases for all of the
above scenarios seemed like diminishing returns.
A branch is considered already pushed if its HEAD commit hash matches
the commit hash of one of the remote tracking branches:
`refs/remotes/<remote>/<branch>`
This mechanism allows the user to:
- Choose a remote as push target for their branch different than the one
that would automatically get chosen for them by `pr create`;
- Avoid a `git push` operation (and its associated git hooks) if a push
was not necessary in the first place.
A valid remote specificication read from `branch.<name>.remote` git
config can be a URL, a `.`, a filesystem path, and a remote name. When
detecting the remote name, be sure not to take filesystem paths instead.
The 2nd argument now unused since we've determined that, in practice, we
can safely fetch git objects from a freshly created fork on GitHub and
that we don't need the remote URL-swapping workaround.