mirror of
https://github.com/x-motemen/ghq.git
synced 2026-09-10 07:26:27 -04:00
Add darcs backend
This commit is contained in:
parent
bdfcba594a
commit
c57d95cad9
|
|
@ -127,10 +127,15 @@ func (repo *LocalRepository) VCS() *VCSBackend {
|
|||
return MercurialBackend
|
||||
}
|
||||
|
||||
fi, err = os.Stat(filepath.Join(repo.FullPath, "_darcs"))
|
||||
if err == nil && fi.IsDir() {
|
||||
return DarcsBackend
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var vcsDirs = []string{".git", ".svn", ".hg"}
|
||||
var vcsDirs = []string{".git", ".svn", ".hg", "_darcs"}
|
||||
|
||||
func walkLocalRepositories(callback func(*LocalRepository)) {
|
||||
for _, root := range localRepositoryRoots() {
|
||||
|
|
|
|||
|
|
@ -125,6 +125,10 @@ func (repo *OtherRepository) VCS() *VCSBackend {
|
|||
if vcs == "hg" || vcs == "mercurial" {
|
||||
return MercurialBackend
|
||||
}
|
||||
|
||||
if vcs == "darcs" {
|
||||
return DarcsBackend
|
||||
}
|
||||
} else {
|
||||
utils.Log("warning", "This version of Git does not support `config --get-urlmatch`; per-URL settings are not available")
|
||||
}
|
||||
|
|
|
|||
11
utils/log.go
11
utils/log.go
|
|
@ -8,11 +8,12 @@ import (
|
|||
|
||||
var logger = &colorine.Logger{
|
||||
colorine.Prefixes{
|
||||
"git": colorine.Verbose,
|
||||
"hg": colorine.Verbose,
|
||||
"svn": colorine.Verbose,
|
||||
"skip": colorine.Verbose,
|
||||
"cd": colorine.Verbose,
|
||||
"git": colorine.Verbose,
|
||||
"hg": colorine.Verbose,
|
||||
"svn": colorine.Verbose,
|
||||
"darcs": colorine.Verbose,
|
||||
"skip": colorine.Verbose,
|
||||
"cd": colorine.Verbose,
|
||||
|
||||
"open": colorine.Warn,
|
||||
"exists": colorine.Warn,
|
||||
|
|
|
|||
21
vcs.go
21
vcs.go
|
|
@ -89,3 +89,24 @@ var MercurialBackend = &VCSBackend{
|
|||
return utils.RunInDir(local, "hg", "pull", "--update")
|
||||
},
|
||||
}
|
||||
|
||||
var DarcsBackend = &VCSBackend{
|
||||
Clone: func(remote *url.URL, local string, shallow bool) error {
|
||||
dir, _ := filepath.Split(local)
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
args := []string{"get"}
|
||||
if shallow {
|
||||
args = append(args, "--lazy")
|
||||
}
|
||||
args = append(args, remote.String(), local)
|
||||
|
||||
return utils.Run("darcs", args...)
|
||||
},
|
||||
Update: func(local string) error {
|
||||
return utils.RunInDir(local, "darcs", "pull")
|
||||
},
|
||||
}
|
||||
|
|
|
|||
47
vcs_test.go
47
vcs_test.go
|
|
@ -200,3 +200,50 @@ func TestMercurialBackend(t *testing.T) {
|
|||
}))
|
||||
Expect(lastCommand().Dir).To(Equal(localDir))
|
||||
}
|
||||
|
||||
func TestDarcsBackend(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "ghq-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
localDir := filepath.Join(tempDir, "repo")
|
||||
|
||||
remoteURL, err := url.Parse("https://example.com/git/repo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
commands := []*exec.Cmd{}
|
||||
lastCommand := func() *exec.Cmd { return commands[len(commands)-1] }
|
||||
utils.CommandRunner = func(cmd *exec.Cmd) error {
|
||||
commands = append(commands, cmd)
|
||||
return nil
|
||||
}
|
||||
|
||||
err = DarcsBackend.Clone(remoteURL, localDir, false)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(commands).To(HaveLen(1))
|
||||
Expect(lastCommand().Args).To(Equal([]string{
|
||||
"darcs", "get", remoteURL.String(), localDir,
|
||||
}))
|
||||
|
||||
err = DarcsBackend.Clone(remoteURL, localDir, true)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(commands).To(HaveLen(2))
|
||||
Expect(lastCommand().Args).To(Equal([]string{
|
||||
"darcs", "get", "--lazy", remoteURL.String(), localDir,
|
||||
}))
|
||||
|
||||
err = DarcsBackend.Update(localDir)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(commands).To(HaveLen(3))
|
||||
Expect(lastCommand().Args).To(Equal([]string{
|
||||
"darcs", "pull",
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue