提交 aa4611dd 编写于 作者: M Mislav Marohnić

Merge branch 'root-dir'

......@@ -88,11 +88,18 @@ func compare(command *Command, args *Args) {
usageHelp()
} else {
r = parseCompareRange(args.RemoveParam(args.ParamsSize() - 1))
project, err = localRepo.CurrentProject()
if args.IsParamsEmpty() {
project, err = localRepo.CurrentProject()
utils.Check(err)
} else {
project = github.NewProject(args.RemoveParam(args.ParamsSize()-1), "", "")
projectName := ""
if err == nil {
projectName = project.Name
}
project = github.NewProject(args.RemoveParam(args.ParamsSize()-1), projectName, "")
if project.Name == "" {
utils.Check(fmt.Errorf("error: missing project name (owner: %q)\n", project.Owner))
}
}
}
}
......
......@@ -69,8 +69,9 @@ func create(command *Command, args *Args) {
var newRepoName string
if args.IsParamsEmpty() {
newRepoName, err = utils.DirName()
dirName, err := git.WorkdirName()
utils.Check(err)
newRepoName = github.SanitizeProjectName(dirName)
} else {
reg := regexp.MustCompile("^[^-]")
if !reg.MatchString(args.FirstParam()) {
......
......@@ -44,13 +44,16 @@ func tranformFetchArgs(args *Args) error {
localRepo, err := github.LocalRepo()
utils.Check(err)
currentProject, err := localRepo.CurrentProject()
utils.Check(err)
projects := make(map[*github.Project]bool)
ownerRegexp := regexp.MustCompile(OwnerRe)
for _, name := range names {
if ownerRegexp.MatchString(name) && !isCloneable(name) {
_, err := localRepo.RemoteByName(name)
if err != nil {
project := github.NewProject(name, "", "")
project := github.NewProject(name, currentProject.Name, "")
gh := github.NewClient(project.Host)
repo, err := gh.Repository(project)
if err != nil {
......
......@@ -5,6 +5,7 @@ import (
"regexp"
"strings"
"github.com/github/hub/git"
"github.com/github/hub/github"
"github.com/github/hub/utils"
)
......@@ -68,8 +69,9 @@ func transformRemoteArgs(args *Args) {
repoName = project.Name
host = project.Host
} else {
repoName, err = utils.DirName()
dirName, err := git.WorkdirName()
utils.Check(err)
repoName = github.SanitizeProjectName(dirName)
}
name = repoName
......
......@@ -9,6 +9,14 @@ Feature: hub remote add
Then the url for "origin" should be "git@github.com:EvilChelu/dotfiles.git"
And there should be no output
Scenario: Add origin remote for my own repo using -C
Given there are no remotes
And I cd to ".."
When I successfully run `hub -C dotfiles remote add origin`
And I cd to "dotfiles"
Then the url for "origin" should be "git@github.com:EvilChelu/dotfiles.git"
And there should be no output
Scenario: Unchanged public remote add
When I successfully run `hub remote add origin http://github.com/defunkt/resque.git`
Then the url for "origin" should be "http://github.com/defunkt/resque.git"
......
......@@ -64,6 +64,15 @@ func Dir() (string, error) {
return gitDir, nil
}
func WorkdirName() (string, error) {
output, err := gitOutput("rev-parse", "--show-toplevel")
if err == nil {
return output[0], nil
} else {
return "", err
}
}
func HasFile(segments ...string) bool {
// The blessed way to resolve paths within git dir since Git 2.5.0
output, err := gitOutput("rev-parse", "-q", "--git-path", filepath.Join(segments...))
......
......@@ -4,6 +4,7 @@ import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
"github.com/github/hub/git"
......@@ -166,10 +167,6 @@ func newProject(owner, name, host, protocol string) *Project {
}
}
if name == "" {
name, _ = utils.DirName()
}
return &Project{
Name: name,
Owner: owner,
......@@ -177,3 +174,8 @@ func newProject(owner, name, host, protocol string) *Project {
Protocol: protocol,
}
}
func SanitizeProjectName(name string) string {
name = filepath.Base(name)
return strings.Replace(name, " ", "-", -1)
}
......@@ -74,17 +74,6 @@ func CommandPath(cmd string) (string, error) {
return filepath.EvalSymlinks(path)
}
func DirName() (string, error) {
dir, err := os.Getwd()
if err != nil {
return "", err
}
name := filepath.Base(dir)
name = strings.Replace(name, " ", "-", -1)
return name, nil
}
func IsOption(confirm, short, long string) bool {
return strings.EqualFold(confirm, short) || strings.EqualFold(confirm, long)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册