mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-02 12:17:39 -06:00
config/module: Mercurial support
This commit is contained in:
parent
fc71d7091f
commit
7e94f7d4a9
@ -33,6 +33,7 @@ func init() {
|
||||
Getters = map[string]Getter{
|
||||
"file": new(FileGetter),
|
||||
"git": new(GitGetter),
|
||||
"hg": new(HgGetter),
|
||||
}
|
||||
}
|
||||
|
||||
|
51
config/module/get_hg.go
Normal file
51
config/module/get_hg.go
Normal file
@ -0,0 +1,51 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// HgGetter is a Getter implementation that will download a module from
|
||||
// a Mercurial repository.
|
||||
type HgGetter struct{}
|
||||
|
||||
func (g *HgGetter) Get(dst string, u *url.URL) error {
|
||||
if _, err := exec.LookPath("hg"); err != nil {
|
||||
return fmt.Errorf("hg must be available and on the PATH")
|
||||
}
|
||||
|
||||
_, err := os.Stat(dst)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
if err := g.clone(dst, u); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err:= g.pull(dst, u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return g.update(dst, u)
|
||||
}
|
||||
|
||||
func (g *HgGetter) clone(dst string, u *url.URL) error {
|
||||
cmd := exec.Command("hg", "clone", "-U", u.String(), dst)
|
||||
return getRunCommand(cmd)
|
||||
}
|
||||
|
||||
func (g *HgGetter) pull(dst string, u *url.URL) error {
|
||||
cmd := exec.Command("hg", "pull")
|
||||
cmd.Dir = dst
|
||||
return getRunCommand(cmd)
|
||||
}
|
||||
|
||||
func (g *HgGetter) update(dst string, u *url.URL) error {
|
||||
cmd := exec.Command("hg", "update")
|
||||
cmd.Dir = dst
|
||||
return getRunCommand(cmd)
|
||||
}
|
41
config/module/get_hg_test.go
Normal file
41
config/module/get_hg_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var testHasHg bool
|
||||
|
||||
func init() {
|
||||
if _, err := exec.LookPath("hg"); err == nil {
|
||||
testHasHg = true
|
||||
}
|
||||
}
|
||||
|
||||
func TestHgGetter_impl(t *testing.T) {
|
||||
var _ Getter = new(HgGetter)
|
||||
}
|
||||
|
||||
func TestHgGetter(t *testing.T) {
|
||||
if !testHasHg {
|
||||
t.Log("hg not found, skipping")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
g := new(HgGetter)
|
||||
dst := tempDir(t)
|
||||
|
||||
// With a dir that doesn't exist
|
||||
if err := g.Get(dst, testModuleURL("basic-hg")); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Verify the main file exists
|
||||
mainPath := filepath.Join(dst, "main.tf")
|
||||
if _, err := os.Stat(mainPath); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
BIN
config/module/test-fixtures/basic-hg/.hg/00changelog.i
Normal file
BIN
config/module/test-fixtures/basic-hg/.hg/00changelog.i
Normal file
Binary file not shown.
2
config/module/test-fixtures/basic-hg/.hg/cache/branch2-served
vendored
Normal file
2
config/module/test-fixtures/basic-hg/.hg/cache/branch2-served
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
dcaed7754d58264cb9a5916215a5442377307bd1 0
|
||||
dcaed7754d58264cb9a5916215a5442377307bd1 o default
|
BIN
config/module/test-fixtures/basic-hg/.hg/dirstate
Normal file
BIN
config/module/test-fixtures/basic-hg/.hg/dirstate
Normal file
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
Commit
|
||||
|
4
config/module/test-fixtures/basic-hg/.hg/requires
Normal file
4
config/module/test-fixtures/basic-hg/.hg/requires
Normal file
@ -0,0 +1,4 @@
|
||||
dotencode
|
||||
fncache
|
||||
revlogv1
|
||||
store
|
BIN
config/module/test-fixtures/basic-hg/.hg/store/00changelog.i
Normal file
BIN
config/module/test-fixtures/basic-hg/.hg/store/00changelog.i
Normal file
Binary file not shown.
BIN
config/module/test-fixtures/basic-hg/.hg/store/00manifest.i
Normal file
BIN
config/module/test-fixtures/basic-hg/.hg/store/00manifest.i
Normal file
Binary file not shown.
BIN
config/module/test-fixtures/basic-hg/.hg/store/data/main.tf.i
Normal file
BIN
config/module/test-fixtures/basic-hg/.hg/store/data/main.tf.i
Normal file
Binary file not shown.
1
config/module/test-fixtures/basic-hg/.hg/store/fncache
Normal file
1
config/module/test-fixtures/basic-hg/.hg/store/fncache
Normal file
@ -0,0 +1 @@
|
||||
data/main.tf.i
|
@ -0,0 +1 @@
|
||||
1 dcaed7754d58264cb9a5916215a5442377307bd1
|
BIN
config/module/test-fixtures/basic-hg/.hg/store/undo
Normal file
BIN
config/module/test-fixtures/basic-hg/.hg/store/undo
Normal file
Binary file not shown.
1
config/module/test-fixtures/basic-hg/.hg/undo.branch
Normal file
1
config/module/test-fixtures/basic-hg/.hg/undo.branch
Normal file
@ -0,0 +1 @@
|
||||
default
|
2
config/module/test-fixtures/basic-hg/.hg/undo.desc
Normal file
2
config/module/test-fixtures/basic-hg/.hg/undo.desc
Normal file
@ -0,0 +1,2 @@
|
||||
0
|
||||
commit
|
BIN
config/module/test-fixtures/basic-hg/.hg/undo.dirstate
Normal file
BIN
config/module/test-fixtures/basic-hg/.hg/undo.dirstate
Normal file
Binary file not shown.
5
config/module/test-fixtures/basic-hg/main.tf
Normal file
5
config/module/test-fixtures/basic-hg/main.tf
Normal file
@ -0,0 +1,5 @@
|
||||
# Hello
|
||||
|
||||
module "foo" {
|
||||
source = "./foo"
|
||||
}
|
Loading…
Reference in New Issue
Block a user