mirror of
https://github.com/x-motemen/ghq.git
synced 2026-09-10 07:26:27 -04:00
commit
3f586c1753
|
|
@ -16,7 +16,7 @@ You can also list local repositories (+ghq list+).
|
|||
== SYNOPSIS
|
||||
|
||||
[verse]
|
||||
ghq get [-u] [-p] [--shallow] [--vcs <vcs>] [--look] [--silent] [--branch] [--no-recursive] <repository URL>|<host>/<user>/<project>|<user>/<project>|<project>
|
||||
ghq get [-u] [-p] [--shallow] [--vcs <vcs>] [--look] [--silent] [--branch] [--no-recursive] [--bare] <repository URL>|<host>/<user>/<project>|<user>/<project>|<project>
|
||||
ghq list [-p] [-e] [<query>]
|
||||
ghq create [--vcs <vcs>] <repository URL>|<host>/<user>/<project>|<user>/<project>|<project>
|
||||
ghq root [--all]
|
||||
|
|
@ -41,6 +41,8 @@ get::
|
|||
Subversion and git-svn. +
|
||||
The 'ghq' gets the git repository recursively by default. +
|
||||
We can prevent it with '--no-recursive' option.
|
||||
With '--bare' option, a "bare clone" will be performed (for Git
|
||||
repositories only, 'git clone --bare ...' eg.).
|
||||
|
||||
list::
|
||||
List locally cloned repositories. If a query argument is given, only
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ func doGet(c *cli.Context) error {
|
|||
silent: c.Bool("silent"),
|
||||
branch: c.String("branch"),
|
||||
recursive: !c.Bool("no-recursive"),
|
||||
bare: c.Bool("bare"),
|
||||
}
|
||||
if parallel {
|
||||
// force silent in parallel import
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ func TestCommandGet(t *testing.T) {
|
|||
if !cloneArgs.recursive {
|
||||
t.Errorf("cloneArgs.recursive should be true")
|
||||
}
|
||||
if cloneArgs.bare {
|
||||
t.Errorf("cloneArgs.bare should be false")
|
||||
}
|
||||
},
|
||||
}, {
|
||||
name: "-p option",
|
||||
|
|
@ -182,6 +185,24 @@ func TestCommandGet(t *testing.T) {
|
|||
t.Errorf("got: %s, expect: %s", filepath.ToSlash(cloneArgs.local), filepath.ToSlash(localDir))
|
||||
}
|
||||
},
|
||||
}, {
|
||||
name: "bare",
|
||||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
app.Run([]string{"", "get", "--bare", "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
t.Errorf("got: %s, expect: %s", cloneArgs.remote, expect)
|
||||
}
|
||||
if filepath.ToSlash(cloneArgs.local) != filepath.ToSlash(localDir) {
|
||||
t.Errorf("got: %s, expect: %s", filepath.ToSlash(cloneArgs.local), filepath.ToSlash(localDir))
|
||||
}
|
||||
if !cloneArgs.bare {
|
||||
t.Errorf("cloneArgs.bare should be true")
|
||||
}
|
||||
},
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ var commandGet = &cli.Command{
|
|||
&cli.StringFlag{Name: "branch", Aliases: []string{"b"},
|
||||
Usage: "Specify `branch` name. This flag implies --single-branch on Git"},
|
||||
&cli.BoolFlag{Name: "parallel", Aliases: []string{"P"}, Usage: "Import parallely"},
|
||||
&cli.BoolFlag{Name: "bare", Usage: "Do a bare clone"},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ type commandDoc struct {
|
|||
}
|
||||
|
||||
var commandDocs = map[string]commandDoc{
|
||||
"get": {"", "[-u] [-p] [--shallow] [--vcs <vcs>] [--look] [--silent] [--branch <branch>] [--no-recursive] <repository URL>|<project>|<user>/<project>|<host>/<user>/<project>"},
|
||||
"get": {"", "[-u] [-p] [--shallow] [--vcs <vcs>] [--look] [--silent] [--branch <branch>] [--no-recursive] [--bare] <repository URL>|<project>|<user>/<project>|<host>/<user>/<project>"},
|
||||
"list": {"", "[-p] [-e] [<query>]"},
|
||||
"create": {"", "<project>|<user>/<project>|<host>/<user>/<project>"},
|
||||
"root": {"", "[-all]"},
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ type _cloneArgs struct {
|
|||
shallow bool
|
||||
branch string
|
||||
recursive bool
|
||||
bare bool
|
||||
}
|
||||
|
||||
type _updateArgs struct {
|
||||
|
|
@ -39,6 +40,7 @@ func withFakeGitBackend(t *testing.T, block func(*testing.T, string, *_cloneArgs
|
|||
shallow: vg.shallow,
|
||||
branch: vg.branch,
|
||||
recursive: vg.recursive,
|
||||
bare: vg.bare,
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ func getRepoLock(localRepoRoot string) bool {
|
|||
}
|
||||
|
||||
type getter struct {
|
||||
update, shallow, silent, ssh, recursive bool
|
||||
vcs, branch string
|
||||
update, shallow, silent, ssh, recursive, bare bool
|
||||
vcs, branch string
|
||||
}
|
||||
|
||||
func (g *getter) get(argURL string) error {
|
||||
|
|
@ -104,6 +104,7 @@ func (g *getter) getRemoteRepository(remote RemoteRepository) error {
|
|||
silent: g.silent,
|
||||
branch: g.branch,
|
||||
recursive: g.recursive,
|
||||
bare: g.bare,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ export GHQ_ROOT=$tmpdir
|
|||
ghq get --shallow --vcs=git-svn https://svn.apache.org/repos/asf/httpd/httpd
|
||||
ghq get https://svn.apache.org/repos/asf/subversion
|
||||
ghq get --shallow hub.darcs.net/byorgey/split
|
||||
ghq get --bare x-motemen/gore
|
||||
|
||||
test -d $tmpdir/github.com/x-motemen/ghq/.git
|
||||
test -d $tmpdir/www.mercurial-scm.org/repo/hello/.hg
|
||||
|
|
@ -30,6 +31,7 @@ export GHQ_ROOT=$tmpdir
|
|||
test -d $tmpdir/svn.apache.org/repos/asf/httpd/httpd/.git/svn
|
||||
test -d $tmpdir/svn.apache.org/repos/asf/subversion/.svn
|
||||
test -d $tmpdir/hub.darcs.net/byorgey/split/_darcs
|
||||
test -d $tmpdir/github.com/x-motemen/gore/refs
|
||||
|
||||
: testing 'ghq list'
|
||||
cat <<EOF | sort > $tmpdir/expect
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ function _ghq () {
|
|||
'--vcs[Specify vcs backend for cloning]' \
|
||||
'(-s --silent)'{-s,--silent}'[Clone or update silently]' \
|
||||
'--no-recursive[Prevent recursive fetching]' \
|
||||
'--bare[Do a bare clone]' \
|
||||
'(-b --branch)'{-b,--branch}'[Specify branch name]' \
|
||||
'(-P --parallel)'{-P,--parallel}'[Import parallely]' \
|
||||
'(-)*:: :->null_state' \
|
||||
|
|
|
|||
11
vcs.go
11
vcs.go
|
|
@ -41,10 +41,10 @@ type VCSBackend struct {
|
|||
}
|
||||
|
||||
type vcsGetOption struct {
|
||||
url *url.URL
|
||||
dir string
|
||||
recursive, shallow, silent bool
|
||||
branch string
|
||||
url *url.URL
|
||||
dir string
|
||||
recursive, shallow, silent, bare bool
|
||||
branch string
|
||||
}
|
||||
|
||||
// GitBackend is the VCSBackend of git
|
||||
|
|
@ -67,6 +67,9 @@ var GitBackend = &VCSBackend{
|
|||
if vg.recursive {
|
||||
args = append(args, "--recursive")
|
||||
}
|
||||
if vg.bare {
|
||||
args = append(args, "--bare")
|
||||
}
|
||||
args = append(args, vg.url.String(), vg.dir)
|
||||
|
||||
return run(vg.silent)("git", args...)
|
||||
|
|
|
|||
11
vcs_test.go
11
vcs_test.go
|
|
@ -126,6 +126,17 @@ func TestVCSBackend(t *testing.T) {
|
|||
},
|
||||
expect: []string{"git", "submodule", "update", "--init", "--recursive"},
|
||||
dir: localDir,
|
||||
}, {
|
||||
name: "[git] bare clone",
|
||||
f: func() error {
|
||||
return GitBackend.Clone(&vcsGetOption{
|
||||
url: remoteDummyURL,
|
||||
dir: localDir,
|
||||
bare: true,
|
||||
silent: true,
|
||||
})
|
||||
},
|
||||
expect: []string{"git", "clone", "--bare", remoteDummyURL.String(), localDir},
|
||||
}, {
|
||||
name: "[git] switch git-svn on update",
|
||||
f: func() error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue