зеркало из https://github.com/mislav/hub.git
Merge pull request jingweno/gh:154 from jingweno/browse_compat
Make gh browse compatible.
This commit is contained in:
Коммит
46a6ec41c7
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/jingweno/gh/github"
|
||||
"github.com/jingweno/gh/utils"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
@ -90,23 +91,28 @@ func browse(command *Command, args *Args) {
|
|||
if subpage == "commits" {
|
||||
subpage = fmt.Sprintf("commits/%s", branchInURL(branch))
|
||||
} else if subpage == "tree" || subpage == "" {
|
||||
if !reflect.DeepEqual(branch, master) {
|
||||
if !reflect.DeepEqual(branch, master) && branch.IsRemote() {
|
||||
subpage = fmt.Sprintf("tree/%s", branchInURL(branch))
|
||||
}
|
||||
}
|
||||
|
||||
url := project.WebURL("", "", subpage)
|
||||
pageUrl := project.WebURL("", "", subpage)
|
||||
launcher, err := utils.BrowserLauncher()
|
||||
utils.Check(err)
|
||||
|
||||
if flagBrowseURLOnly {
|
||||
args.Replace("echo", url)
|
||||
args.Replace("echo", pageUrl)
|
||||
} else {
|
||||
args.Replace(launcher[0], "", launcher[1:]...)
|
||||
args.AppendParams(url)
|
||||
args.AppendParams(pageUrl)
|
||||
}
|
||||
}
|
||||
|
||||
func branchInURL(branch *github.Branch) string {
|
||||
return strings.Replace(branch.ShortName(), ".", "/", -1)
|
||||
parts := strings.Split(strings.Replace(branch.ShortName(), ".", "/", -1), "/")
|
||||
newPath := make([]string, len(parts))
|
||||
for i, s := range parts {
|
||||
newPath[i] = url.QueryEscape(s)
|
||||
}
|
||||
return strings.Join(newPath, "/")
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче