Skip to content
Open
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
5 changes: 5 additions & 0 deletions bzr.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ type BzrRepo struct {
base
}

// SetRecursive is not used for bzr repositories.
func (BzrRepo) SetRecursive(bool) {
// Do Nothing
}

// Vcs retrieves the underlying VCS being implemented.
func (s BzrRepo) Vcs() Type {
return Bzr
Expand Down
34 changes: 24 additions & 10 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vcs
import (
"bytes"
"encoding/xml"
"fmt"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -31,6 +32,7 @@ func NewGitRepo(remote, local string) (*GitRepo, error) {
r.setLocalPath(local)
r.RemoteLocation = "origin"
r.Logger = Logger
r.recursive = true

// Make sure the local Git repo is configured the same as the remote when
// A remote value was passed in.
Expand Down Expand Up @@ -62,6 +64,12 @@ func NewGitRepo(remote, local string) (*GitRepo, error) {
type GitRepo struct {
base
RemoteLocation string
recursive bool
}

// SetRecursive sets if submodule updates should be recursive or not.
func (s *GitRepo) SetRecursive(enable bool) {
s.recursive = enable
}

// Vcs retrieves the underlying VCS being implemented.
Expand Down Expand Up @@ -169,21 +177,27 @@ func (s *GitRepo) UpdateVersion(version string) error {
// defendAgainstSubmodules tries to keep repo state sane in the event of
// submodules. Or nested submodules. What a great idea, submodules.
func (s *GitRepo) defendAgainstSubmodules() error {
cmd := []string{"submodule", "update", "--init"}
if s.recursive {
cmd = append(cmd, "--recursive")
}
// First, update them to whatever they should be, if there should happen to be any.
out, err := s.RunFromDir("git", "submodule", "update", "--init", "--recursive")
out, err := s.RunFromDir("git", cmd...)
if err != nil {
return NewLocalError("Unexpected error while defensively updating submodules", err, string(out))
return NewLocalError(fmt.Sprintf("Unexpected error while defensively updating submodules (recursive:%v)", s.recursive), err, string(out))
}
// Now, do a special extra-aggressive clean in case changing versions caused
// one or more submodules to go away.
out, err = s.RunFromDir("git", "clean", "-x", "-d", "-f", "-f")
if err != nil {
return NewLocalError("Unexpected error while defensively cleaning up after possible derelict submodule directories", err, string(out))
}
// Then, repeat just in case there are any nested submodules that went away.
out, err = s.RunFromDir("git", "submodule", "foreach", "--recursive", "git", "clean", "-x", "-d", "-f", "-f")
if err != nil {
return NewLocalError("Unexpected error while defensively cleaning up after possible derelict nested submodule directories", err, string(out))
if s.recursive {
// Then, repeat just in case there are any nested submodules that went away.
out, err = s.RunFromDir("git", "submodule", "foreach", "--recursive", "git", "clean", "-x", "-d", "-f", "-f")
if err != nil {
return NewLocalError("Unexpected error while defensively cleaning up after possible derelict nested submodule directories", err, string(out))
}
}

return nil
Expand Down Expand Up @@ -366,7 +380,7 @@ func (s *GitRepo) Ping() bool {

// EscapePathSeparator escapes the path separator by replacing it with several.
// Note: this is harmless on Unix, and needed on Windows.
func EscapePathSeparator(path string) (string) {
func EscapePathSeparator(path string) string {
switch runtime.GOOS {
case `windows`:
// On Windows, triple all path separators.
Expand All @@ -379,7 +393,7 @@ func EscapePathSeparator(path string) (string) {
// used with --prefix, like this: --prefix=C:\foo\bar\ -> --prefix=C:\\\foo\\\bar\\\
return strings.Replace(path,
string(os.PathSeparator),
string(os.PathSeparator) + string(os.PathSeparator) + string(os.PathSeparator),
string(os.PathSeparator)+string(os.PathSeparator)+string(os.PathSeparator),
-1)
default:
return path
Expand All @@ -404,15 +418,15 @@ func (s *GitRepo) ExportDir(dir string) error {
return NewLocalError("Unable to create directory", err, "")
}

path = EscapePathSeparator( dir )
path = EscapePathSeparator(dir)
out, err := s.RunFromDir("git", "checkout-index", "-f", "-a", "--prefix="+path)
s.log(out)
if err != nil {
return NewLocalError("Unable to export source", err, string(out))
}

// and now, the horror of submodules
path = EscapePathSeparator( dir + "$path" + string(os.PathSeparator) )
path = EscapePathSeparator(dir + "$path" + string(os.PathSeparator))
out, err = s.RunFromDir("git", "submodule", "foreach", "--recursive", "git checkout-index -f -a --prefix="+path)
s.log(out)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions hg.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type HgRepo struct {
base
}

// SetRecursive is not used for hg repositories.
func (HgRepo) SetRecursive(bool) {
// Do Nothing
}

// Vcs retrieves the underlying VCS being implemented.
func (s HgRepo) Vcs() Type {
return Hg
Expand Down
4 changes: 4 additions & 0 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ type Repo interface {

// ExportDir exports the current revision to the passed in directory.
ExportDir(string) error

// SetRecursive allows setting if the recursive option should be used
// with Git submodule calls. This only applies to Git.
SetRecursive(bool)
}

// NewRepo returns a Repo based on trying to detect the source control from the
Expand Down
5 changes: 5 additions & 0 deletions svn.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ type SvnRepo struct {
base
}

// SetRecursive is not used for svn repositories.
func (SvnRepo) SetRecursive(bool) {
// Do Nothing
}

// Vcs retrieves the underlying VCS being implemented.
func (s SvnRepo) Vcs() Type {
return Svn
Expand Down