Fix GHE host prompts for `hub remote` commands

Now `hub remote` will only prompt to select from your configured hosts
if it can't infer the GitHub hostname from existing remotes.

In case you're prompted, and you choose a GHE host, now that choice will
be properly reflected in the generated URL, unlike before when it would
always revert to "github.com" regardless of choice.

Fixes #1141
This commit is contained in:
Mislav Marohnić 2016-08-11 23:34:17 +02:00
Родитель af72087bc7
Коммит 7633e5b182
2 изменённых файлов: 17 добавлений и 10 удалений

Просмотреть файл

@ -62,32 +62,38 @@ func transformRemoteArgs(args *Args) {
localRepo, err := github.LocalRepo()
utils.Check(err)
var repoName, host string
var host string
mainProject, err := localRepo.MainProject()
if err == nil {
host = mainProject.Host
}
if name == "" {
project, err := localRepo.MainProject()
if err == nil {
repoName = project.Name
host = project.Host
if mainProject != nil {
name = mainProject.Name
} else {
dirName, err := git.WorkdirName()
utils.Check(err)
repoName = github.SanitizeProjectName(dirName)
name = github.SanitizeProjectName(dirName)
}
name = repoName
}
hostConfig, err := github.CurrentConfig().DefaultHost()
var hostConfig *github.Host
if host == "" {
hostConfig, err = github.CurrentConfig().DefaultHost()
} else {
hostConfig, err = github.CurrentConfig().PromptForHost(host)
}
if err != nil {
utils.Check(github.FormatError("adding remote", err))
}
host = hostConfig.Host
words := args.Words()
isPrivate := parseRemotePrivateFlag(args)
if len(words) == 2 && words[1] == "origin" {
// Origin special case triggers default user/repo
owner = hostConfig.User
name = repoName
} else if len(words) == 2 {
// gh remote add jingweno foo/bar
if idx := args.IndexOfParam(words[1]); idx != -1 {

Просмотреть файл

@ -44,6 +44,7 @@ Feature: hub remote add
Scenario: Add new remote for Enterprise repo
Given "git.my.org" is a whitelisted Enterprise host
And I am "ProLoser" on git.my.org with OAuth token "FITOKEN"
And the "origin" remote has url "git@git.my.org:mislav/topsekrit.git"
When I successfully run `hub remote add another`
Then the url for "another" should be "git@git.my.org:another/topsekrit.git"