config/module: fix some issues where tag re-pulling didnt' work

This commit is contained in:
Mitchell Hashimoto 2014-09-16 09:59:09 -07:00
parent dcb900470c
commit 13d892217c
2 changed files with 26 additions and 3 deletions

View File

@ -17,10 +17,17 @@ func (g *GitGetter) Get(dst string, u *url.URL) error {
} }
// Extract some query parameters we use // Extract some query parameters we use
var tag string
q := u.Query() q := u.Query()
tag := q.Get("tag") if len(q) > 0 {
q.Del("tag") tag = q.Get("tag")
u.RawQuery = q.Encode() q.Del("tag")
// Copy the URL
var newU url.URL = *u
u = &newU
u.RawQuery = q.Encode()
}
// First: clone or update the repository // First: clone or update the repository
_, err := os.Stat(dst) _, err := os.Stat(dst)
@ -56,6 +63,11 @@ func (g *GitGetter) clone(dst string, u *url.URL) error {
} }
func (g *GitGetter) update(dst string, u *url.URL) error { func (g *GitGetter) update(dst string, u *url.URL) error {
// We have to be on a branch to pull
if err := g.checkout(dst, "master"); err != nil {
return err
}
cmd := exec.Command("git", "pull", "--ff-only") cmd := exec.Command("git", "pull", "--ff-only")
cmd.Dir = dst cmd.Dir = dst
return getRunCommand(cmd) return getRunCommand(cmd)

View File

@ -83,4 +83,15 @@ func TestGitGetter_tag(t *testing.T) {
if _, err := os.Stat(mainPath); err != nil { if _, err := os.Stat(mainPath); err != nil {
t.Fatalf("err: %s", err) 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_tag1.tf")
if _, err := os.Stat(mainPath); err != nil {
t.Fatalf("err: %s", err)
}
} }