Skip to content

Commit

Permalink
Merge pull request #372 from yoichi/pijul
Browse files Browse the repository at this point in the history
Support pijul
  • Loading branch information
Songmu authored Feb 2, 2024
2 parents 7163e61 + 026adc2 commit 8f42cc3
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func TestDoCreate(t *testing.T) {
input: []string{"create", "--vcs=darcs", "motemen/ghq-darcs"},
want: []string{"darcs", "init"},
wantDir: filepath.Join(tmpd, "github.com/motemen/ghq-darcs"),
}, {
name: "Pijul",
input: []string{"create", "--vcs=pijul", "motemen/ghq-pijul"},
want: []string{"pijul", "init"},
wantDir: filepath.Join(tmpd, "github.com/motemen/ghq-pijul"),
}, {
name: "Bazzar",
input: []string{"create", "--vcs=bzr", "motemen/ghq-bzr"},
Expand Down
2 changes: 2 additions & 0 deletions local_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ var vcsContentsMap = map[string]*VCSBackend{
".hg": MercurialBackend,
".svn": SubversionBackend,
"_darcs": DarcsBackend,
".pijul": PijulBackend,
".bzr": BazaarBackend,
".fslckout": FossilBackend, // file
"_FOSSIL_": FossilBackend, // file
Expand All @@ -219,6 +220,7 @@ var vcsContents = [...]string{
".hg",
".svn",
"_darcs",
".pijul",
".bzr",
".fslckout",
"._FOSSIL_",
Expand Down
1 change: 1 addition & 0 deletions logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var logger = colorine.NewLogger(
"hg": colorine.Verbose,
"svn": colorine.Verbose,
"darcs": colorine.Verbose,
"pijul": colorine.Verbose,
"bzr": colorine.Verbose,
"fossil": colorine.Verbose,
"skip": colorine.Verbose,
Expand Down
22 changes: 22 additions & 0 deletions remote_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ func (repo *DarksHubRepository) VCS() (*VCSBackend, *url.URL, error) {
return DarcsBackend, repo.URL(), nil
}

// NestPijulRepository represents the Nest repository
type NestPijulRepository struct {
url *url.URL
}

// URL returns URL of the Nest repository
func (repo *NestPijulRepository) URL() *url.URL {
return repo.url
}

// IsValid determine if the Nest repository is valid or not
func (repo *NestPijulRepository) IsValid() bool {
return strings.Count(repo.url.Path, "/") == 2
}

// VCS returns VCSBackend of the Nest repository
func (repo *NestPijulRepository) VCS() (*VCSBackend, *url.URL, error) {
return PijulBackend, repo.URL(), nil
}

// A CodeCommitRepository represents a CodeCommit repository. Implements RemoteRepository.
type CodeCommitRepository struct {
url *url.URL
Expand Down Expand Up @@ -197,6 +217,8 @@ func NewRemoteRepository(u *url.URL) (RemoteRepository, error) {
return &GitHubGistRepository{u}
case "hub.darcs.net":
return &DarksHubRepository{u}
case "nest.pijul.com":
return &NestPijulRepository{u}
default:
return &OtherRepository{u}
}
Expand Down
4 changes: 4 additions & 0 deletions remote_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func TestNewRemoteRepository(t *testing.T) {
url: "http://hub.darcs.net/foo/bar",
valid: true,
vcsBackend: DarcsBackend,
}, {
url: "http://nest.pijul.com/foo/bar",
valid: true,
vcsBackend: PijulBackend,
}, {
url: "svn+ssh://example.com/proj/repo",
valid: true,
Expand Down
27 changes: 27 additions & 0 deletions vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,32 @@ var DarcsBackend = &VCSBackend{
Contents: []string{"_darcs"},
}

// PijulBackend is the VCSBackend for pijul
var PijulBackend = &VCSBackend{
Clone: func(vg *vcsGetOption) error {
dir, _ := filepath.Split(vg.dir)
err := os.MkdirAll(dir, 0755)
if err != nil {
return err
}

args := []string{"clone"}
if vg.branch != "" {
args = append(args, "--channel", vg.branch)
}
args = append(args, vg.url.String(), vg.dir)

return run(vg.silent)("pijul", args...)
},
Update: func(vg *vcsGetOption) error {
return runInDir(vg.silent)(vg.dir, "pijul", "pull")
},
Init: func(dir string) error {
return cmdutil.RunInDir(dir, "pijul", "init")
},
Contents: []string{".pijul"},
}

var cvsDummyBackend = &VCSBackend{
Clone: func(vg *vcsGetOption) error {
return errors.New("CVS clone is not supported")
Expand Down Expand Up @@ -370,6 +396,7 @@ var vcsRegistry = map[string]*VCSBackend{
"hg": MercurialBackend,
"mercurial": MercurialBackend,
"darcs": DarcsBackend,
"pijul": PijulBackend,
"fossil": FossilBackend,
"bzr": BazaarBackend,
"bazaar": BazaarBackend,
Expand Down
18 changes: 18 additions & 0 deletions vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,24 @@ func TestVCSBackend(t *testing.T) {
},
expect: []string{"darcs", "pull"},
dir: localDir,
}, {
name: "[pijul] clone",
f: func() error {
return PijulBackend.Clone(&vcsGetOption{
url: remoteDummyURL,
dir: localDir,
})
},
expect: []string{"pijul", "clone", remoteDummyURL.String(), localDir},
}, {
name: "[pijul] update",
f: func() error {
return PijulBackend.Update(&vcsGetOption{
dir: localDir,
})
},
expect: []string{"pijul", "pull"},
dir: localDir,
}, {
name: "[bzr] clone",
f: func() error {
Expand Down

0 comments on commit 8f42cc3

Please sign in to comment.