config/module: hg supports branches/tags/etc.
This commit is contained in:
parent
feb9a36597
commit
9c74d6b5c0
|
@ -16,6 +16,19 @@ func (g *HgGetter) Get(dst string, u *url.URL) error {
|
|||
return fmt.Errorf("hg must be available and on the PATH")
|
||||
}
|
||||
|
||||
// Extract some query parameters we use
|
||||
var rev string
|
||||
q := u.Query()
|
||||
if len(q) > 0 {
|
||||
rev = q.Get("rev")
|
||||
q.Del("rev")
|
||||
|
||||
// Copy the URL
|
||||
var newU url.URL = *u
|
||||
u = &newU
|
||||
u.RawQuery = q.Encode()
|
||||
}
|
||||
|
||||
_, err := os.Stat(dst)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
|
@ -30,7 +43,7 @@ func (g *HgGetter) Get(dst string, u *url.URL) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return g.update(dst, u)
|
||||
return g.update(dst, u, rev)
|
||||
}
|
||||
|
||||
func (g *HgGetter) clone(dst string, u *url.URL) error {
|
||||
|
@ -44,8 +57,13 @@ func (g *HgGetter) pull(dst string, u *url.URL) error {
|
|||
return getRunCommand(cmd)
|
||||
}
|
||||
|
||||
func (g *HgGetter) update(dst string, u *url.URL) error {
|
||||
cmd := exec.Command("hg", "update")
|
||||
func (g *HgGetter) update(dst string, u *url.URL, rev string) error {
|
||||
args := []string{"update"}
|
||||
if rev != "" {
|
||||
args = append(args, rev)
|
||||
}
|
||||
|
||||
cmd := exec.Command("hg", args...)
|
||||
cmd.Dir = dst
|
||||
return getRunCommand(cmd)
|
||||
}
|
||||
|
|
|
@ -39,3 +39,39 @@ func TestHgGetter(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHgGetter_branch(t *testing.T) {
|
||||
if !testHasHg {
|
||||
t.Log("hg not found, skipping")
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
g := new(HgGetter)
|
||||
dst := tempDir(t)
|
||||
|
||||
url := testModuleURL("basic-hg")
|
||||
q := url.Query()
|
||||
q.Add("rev", "test-branch")
|
||||
url.RawQuery = q.Encode()
|
||||
|
||||
if err := g.Get(dst, url); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Verify the main file exists
|
||||
mainPath := filepath.Join(dst, "main_branch.tf")
|
||||
if _, err := os.Stat(mainPath); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Get again should work
|
||||
if err := g.Get(dst, url); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Verify the main file exists
|
||||
mainPath = filepath.Join(dst, "main_branch.tf")
|
||||
if _, err := os.Stat(mainPath); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -1,2 +1,3 @@
|
|||
dcaed7754d58264cb9a5916215a5442377307bd1 0
|
||||
c65e998d747ffbb1fe3b1c067a50664bb3fb5da4 1
|
||||
dcaed7754d58264cb9a5916215a5442377307bd1 o default
|
||||
c65e998d747ffbb1fe3b1c067a50664bb3fb5da4 o test-branch
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
1 c65e998d747ffbb1fe3b1c067a50664bb3fb5da4
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
Commit
|
||||
Branch
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1,2 @@
|
|||
data/main.tf.i
|
||||
data/main_branch.tf.i
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
1 dcaed7754d58264cb9a5916215a5442377307bd1
|
|
@ -1 +1 @@
|
|||
default
|
||||
test-branch
|
|
@ -1,2 +1,2 @@
|
|||
0
|
||||
1
|
||||
commit
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue