Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh: Fork compatibility fix #535

Merged
merged 15 commits into from
Apr 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion commands/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func browse(command *Command, args *Args) {
subpage = args.RemoveParam(0)
}

localRepo := github.LocalRepo()
localRepo, _ := github.LocalRepo()
if dest != "" {
project = github.NewProject("", dest, "")
branch = localRepo.MasterBranch()
Expand Down
4 changes: 3 additions & 1 deletion commands/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func transformCheckoutArgs(args *Args) error {
newBranchName = fmt.Sprintf("%s-%s", user, branch)
}

repo := github.LocalRepo()
repo, err := github.LocalRepo()
utils.Check(err)

_, err = repo.RemoteByName(user)
if err == nil {
args.Before("git", "remote", "set-branches", "--add", user, branch)
Expand Down
8 changes: 6 additions & 2 deletions commands/cherry_pick.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package commands

import (
"regexp"

"github.com/github/hub/github"
"github.com/github/hub/utils"
"regexp"
)

var cmdCherryPick = &Command{
Expand Down Expand Up @@ -72,7 +73,10 @@ func parseCherryPickProjectAndSha(ref string) (project *github.Project, sha stri
if ownerWithShaRegexp.MatchString(ref) {
matches := ownerWithShaRegexp.FindStringSubmatch(ref)
sha = matches[2]
project, err := github.LocalRepo().CurrentProject()
localRepo, err := github.LocalRepo()
utils.Check(err)

project, err := localRepo.CurrentProject()
utils.Check(err)
project.Owner = matches[1]
}
Expand Down
7 changes: 5 additions & 2 deletions commands/ci_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package commands

import (
"fmt"
"os"

"github.com/github/hub/git"
"github.com/github/hub/github"
"github.com/github/hub/utils"
"os"
)

var cmdCiStatus = &Command{
Expand Down Expand Up @@ -51,7 +52,9 @@ func ciStatus(cmd *Command, args *Args) {
ref = args.RemoveParam(0)
}

localRepo := github.LocalRepo()
localRepo, err := github.LocalRepo()
utils.Check(err)

project, err := localRepo.MainProject()
utils.Check(err)

Expand Down
5 changes: 3 additions & 2 deletions commands/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ func init() {
> open https://github.com/other-user/REPO/compare/patch
*/
func compare(command *Command, args *Args) {
localRepo := github.LocalRepo()
localRepo, err := github.LocalRepo()
utils.Check(err)

var (
branch *github.Branch
project *github.Project
r string
err error
)

branch, project, err = localRepo.RemoteBranchAndProject("")
Expand Down
9 changes: 6 additions & 3 deletions commands/fetch.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package commands

import (
"github.com/github/hub/github"
"github.com/github/hub/utils"
"regexp"
"strings"

"github.com/github/hub/github"
"github.com/github/hub/utils"
)

var cmdFetch = &Command{
Expand Down Expand Up @@ -45,7 +46,9 @@ func fetch(command *Command, args *Args) {

func tranformFetchArgs(args *Args) error {
names := parseRemoteNames(args)
localRepo := github.LocalRepo()

localRepo, err := github.LocalRepo()
utils.Check(err)

projects := make(map[*github.Project]bool)
ownerRegexp := regexp.MustCompile(OwnerRe)
Expand Down
20 changes: 12 additions & 8 deletions commands/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package commands

import (
"fmt"
"os"
"reflect"

"github.com/github/hub/github"
"github.com/github/hub/utils"
"os"
"reflect"
)

var cmdFork = &Command{
Expand Down Expand Up @@ -35,10 +34,13 @@ func init() {
[ repo forked on GitHub ]
*/
func fork(cmd *Command, args *Args) {
localRepo := github.LocalRepo()
localRepo, err := github.LocalRepo()
utils.Check(err)

project, err := localRepo.MainProject()
utils.Check(err)
if err != nil {
utils.Check(fmt.Errorf("Error: repository under 'origin' remote is not a GitHub project"))
}

configs := github.CurrentConfigs()
host, err := configs.PromptForHost(project.Host)
Expand All @@ -47,7 +49,6 @@ func fork(cmd *Command, args *Args) {
}

forkProject := github.NewProject(host.User, project.Name, project.Host)

client := github.NewClient(project.Host)
existingRepo, err := client.Repository(forkProject)
if err == nil {
Expand All @@ -70,8 +71,11 @@ func fork(cmd *Command, args *Args) {
if flagForkNoRemote {
os.Exit(0)
} else {
u := forkProject.GitURL("", "", true)
args.Replace("git", "remote", "add", "-f", forkProject.Owner, u)
originRemote, _ := localRepo.OriginRemote()
originURL := originRemote.URL.String()
url := forkProject.GitURL("", "", true)
args.Replace("git", "remote", "add", "-f", forkProject.Owner, originURL)
args.After("git", "remote", "set-url", forkProject.Owner, url)
args.After("echo", fmt.Sprintf("new remote: %s", forkProject.Owner))
}
}
3 changes: 2 additions & 1 deletion commands/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func init() {
[ create pull request with title & body from FILE ]
*/
func pullRequest(cmd *Command, args *Args) {
localRepo := github.LocalRepo()
localRepo, err := github.LocalRepo()
utils.Check(err)

currentBranch, err := localRepo.CurrentBranch()
utils.Check(err)
Expand Down
8 changes: 6 additions & 2 deletions commands/push.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package commands

import (
"strings"

"github.com/github/hub/github"
"github.com/github/hub/utils"
"strings"
)

var cmdPush = &Command{
Expand Down Expand Up @@ -44,9 +45,12 @@ func transformPushArgs(args *Args) {
args.ReplaceParam(0, remotes[0])

if len(refs) == 0 {
localRepo := github.LocalRepo()
localRepo, err := github.LocalRepo()
utils.Check(err)

head, err := localRepo.CurrentBranch()
utils.Check(err)

refs = []string{head.ShortName()}
args.AppendParams(refs...)
}
Expand Down
Loading