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

Support bazaar #87

Merged
merged 1 commit into from
Apr 30, 2019
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
9 changes: 8 additions & 1 deletion local_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ func (repo *LocalRepository) VCS() *VCSBackend {
if err == nil && fi.IsDir() {
return cvsDummyBackend
}

fi, err = os.Stat(filepath.Join(repo.FullPath, ".bzr"))
if err == nil && fi.IsDir() {
return BazaarBackend
}


return nil
}

var vcsDirs = []string{".git", ".svn", ".hg", "_darcs", ".fslckout", "_FOSSIL_", "CVS"}
var vcsDirs = []string{".git", ".svn", ".hg", "_darcs", ".fslckout", "_FOSSIL_", "CVS", ".bzr"}

func walkLocalRepositories(callback func(*LocalRepository)) error {
roots, err := localRepositoryRoots()
Expand Down
1 change: 1 addition & 0 deletions logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var logger = colorine.NewLogger(
"hg": colorine.Verbose,
"svn": colorine.Verbose,
"darcs": colorine.Verbose,
"bzr" : colorine.Verbose,
"skip": colorine.Verbose,
"cd": colorine.Verbose,
"resolved": colorine.Verbose,
Expand Down
4 changes: 4 additions & 0 deletions remote_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func (repo *OtherRepository) VCS() (*VCSBackend, *url.URL) {
if vcs == "fossil" {
return FossilBackend, repo.URL()
}

if vcs == "bazaar" {
return BazaarBackend, repo.URL()
}
}

// Detect VCS backend automatically
Expand Down
17 changes: 17 additions & 0 deletions vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ var FossilBackend = &VCSBackend{
},
}

var BazaarBackend = &VCSBackend{
// bazaar seems not supporting shallow clone currently.
Clone: func(remote *url.URL, local string, ignoredShallow, silent bool) error {
dir, _ := filepath.Split(local)
err := os.MkdirAll(dir, 0755)
if err != nil {
return err
}

return run(silent)("bzr", "branch", remote.String(), local)
},
Update: func(local string, silent bool) error {
return runInDir(silent)(local, "bzr", "pull")
},
}

var vcsRegistry = map[string]*VCSBackend{
"git": GitBackend,
"github": GitBackend,
Expand All @@ -172,4 +188,5 @@ var vcsRegistry = map[string]*VCSBackend{
"mercurial": MercurialBackend,
"darcs": DarcsBackend,
"fossil": FossilBackend,
"bazaar": BazaarBackend,
}
48 changes: 48 additions & 0 deletions vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,51 @@ func TestCvsDummyBackend(t *testing.T) {

Expect(err).To(HaveOccurred())
}

func TestBazaarBackend(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] }
cmdutil.CommandRunner = func(cmd *exec.Cmd) error {
commands = append(commands, cmd)
return nil
}

err = BazaarBackend.Clone(remoteURL, localDir, false, false)

Expect(err).NotTo(HaveOccurred())
Expect(commands).To(HaveLen(1))
Expect(lastCommand().Args).To(Equal([]string{
"bzr", "branch", remoteURL.String(), localDir,
}))

err = BazaarBackend.Clone(remoteURL, localDir, true, false)

Expect(err).NotTo(HaveOccurred())
Expect(commands).To(HaveLen(2))
Expect(lastCommand().Args).To(Equal([]string{
"bzr", "branch", remoteURL.String(), localDir,
}))

err = BazaarBackend.Update(localDir, false)

Expect(err).NotTo(HaveOccurred())
Expect(commands).To(HaveLen(3))
Expect(lastCommand().Args).To(Equal([]string{
"bzr", "pull",
}))
Expect(lastCommand().Dir).To(Equal(localDir))
}