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

Github relative #43

Merged
merged 4 commits into from
Mar 2, 2016
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
24 changes: 24 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"syscall"
Expand Down Expand Up @@ -134,6 +136,28 @@ func doGet(c *cli.Context) {
os.Exit(1)
}

// Find repository name trailing after github.com/USER/.
if !strings.Contains(argURL, "/") {
if wd, err := os.Getwd(); err == nil {
wd = filepath.ToSlash(wd)
if runtime.GOOS == "windows" {
wd = strings.ToLower(wd)
}
m := regexp.MustCompile(`/github.com/[^\/]+$`).FindStringIndex(wd)
if len(m) > 1 {
base, tail := wd[:m[0]], wd[m[0]+1:]
for _, root := range localRepositoryRoots() {
if runtime.GOOS == "windows" {
root = filepath.ToSlash(strings.ToLower(root))
}
if root == base {
argURL = "https://" + tail + "/" + argURL
break
}
}
}
}
}
url, err := NewURL(argURL)
utils.DieIf(err)

Expand Down
17 changes: 15 additions & 2 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

import (
"testing"
. "github.com/onsi/gomega"
"testing"
)

func flagSet(name string, flags []cli.Flag) *flag.FlagSet {
Expand Down Expand Up @@ -102,7 +102,7 @@ func withFakeGitBackend(t *testing.T, block func(string, *_cloneArgs, *_updateAr
Clone: func(remote *url.URL, local string, shallow bool) error {
cloneArgs = _cloneArgs{
remote: remote,
local: local,
local: filepath.FromSlash(local),
shallow: shallow,
}
return nil
Expand Down Expand Up @@ -171,6 +171,19 @@ func TestCommandGet(t *testing.T) {
Expect(cloneArgs.local).To(Equal(localDir))
Expect(cloneArgs.shallow).To(Equal(true))
})

withFakeGitBackend(t, func(tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
localDir := filepath.Join(tmpRoot, "github.com", "motemen")
os.MkdirAll(localDir, 0755)
wd, _ := os.Getwd()
defer os.Chdir(wd)
os.Chdir(localDir)

app.Run([]string{"", "get", "-u", "ghq-test-repo"})

Expect(cloneArgs.remote.String()).To(Equal("https://github.com/motemen/ghq-test-repo"))
Expect(cloneArgs.local).To(Equal(filepath.Join(localDir, "ghq-test-repo")))
})
}

func TestCommandList(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion git_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"testing"
. "github.com/onsi/gomega"
"testing"
)

func TestGitConfigAll(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion url_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
. "github.com/onsi/gomega"
"net/url"
"testing"
. "github.com/onsi/gomega"
)

func TestNewURL(t *testing.T) {
Expand Down