diff --git a/config-example.json b/config-example.json index 12e3b7bb..2d1ebdab 100644 --- a/config-example.json +++ b/config-example.json @@ -58,6 +58,10 @@ "url" : "https://www.github.com/YourOrganization/RepoOne.git", "enable-push-updates" : true }, + "RepoWithCustomRefs" : { + "url" : "https://www.github.com/YourOrganization/RepoOne.git", + "ref" : "develop" + }, "RepoIsGitHubWiki" : { "url" : "https://github.com/YourOrganization/RepoWithWiki.wiki.git", "url-pattern" : { diff --git a/config/config.go b/config/config.go index 1dce70ab..2cf01a86 100644 --- a/config/config.go +++ b/config/config.go @@ -29,6 +29,7 @@ type Repo struct { Vcs string `json:"vcs"` VcsConfigMessage *SecretMessage `json:"vcs-config"` UrlPattern *UrlPattern `json:"url-pattern"` + Ref string `json:"ref"` ExcludeDotFiles bool `json:"exclude-dot-files"` EnablePollUpdates *bool `json:"enable-poll-updates"` EnablePushUpdates *bool `json:"enable-push-updates"` diff --git a/searcher/searcher.go b/searcher/searcher.go index 4cb706ad..3d121591 100644 --- a/searcher/searcher.go +++ b/searcher/searcher.go @@ -348,7 +348,7 @@ func updateAndReindex( defer lim.Release() repo := s.Repo - newRev, err := wd.PullOrClone(vcsDir, repo.Url) + newRev, err := wd.PullOrClone(vcsDir, repo.Url, repo.Ref) if err != nil { log.Printf("vcs pull error (%s - %s): %s", name, repo.Url, err) @@ -405,7 +405,7 @@ func newSearcher( SpecialFiles: wd.SpecialFiles(), } - rev, err := wd.PullOrClone(vcsDir, repo.Url) + rev, err := wd.PullOrClone(vcsDir, repo.Url, repo.Ref) if err != nil { return nil, err } diff --git a/vcs/bzr.go b/vcs/bzr.go index f8acd8dd..99e289d9 100644 --- a/vcs/bzr.go +++ b/vcs/bzr.go @@ -43,7 +43,7 @@ func (g *BzrDriver) HeadRev(dir string) (string, error) { return strings.TrimSpace(buf.String()), cmd.Wait() } -func (g *BzrDriver) Pull(dir string) (string, error) { +func (g *BzrDriver) Pull(dir string, _ string) (string, error) { cmd := exec.Command("bzr", "pull") cmd.Dir = dir out, err := cmd.CombinedOutput() diff --git a/vcs/git.go b/vcs/git.go index f8c66825..38b39b63 100644 --- a/vcs/git.go +++ b/vcs/git.go @@ -61,7 +61,11 @@ func run(desc, dir, cmd string, args ...string) error { return nil } -func (g *GitDriver) Pull(dir string) (string, error) { +func (g *GitDriver) Pull(dir string, configRef string) (string, error) { + ref := configRef + if ref == "" { + ref = defaultRef + } if err := run("git fetch", dir, "git", "fetch", @@ -69,7 +73,7 @@ func (g *GitDriver) Pull(dir string) (string, error) { "--no-tags", "--depth", "1", "origin", - fmt.Sprintf("+%s:remotes/origin/%s", defaultRef, defaultRef)); err != nil { + fmt.Sprintf("+%s:remotes/origin/%s", ref, ref)); err != nil { return "", err } diff --git a/vcs/hg.go b/vcs/hg.go index 8e13bb1b..4029c692 100644 --- a/vcs/hg.go +++ b/vcs/hg.go @@ -47,7 +47,7 @@ func (g *MercurialDriver) HeadRev(dir string) (string, error) { return strings.TrimSpace(buf.String()), cmd.Wait() } -func (g *MercurialDriver) Pull(dir string) (string, error) { +func (g *MercurialDriver) Pull(dir string, _ string) (string, error) { cmd := exec.Command("hg", "pull", "-u") cmd.Dir = dir err := cmd.Run() diff --git a/vcs/svn.go b/vcs/svn.go index 087aa0f3..29c68e8a 100644 --- a/vcs/svn.go +++ b/vcs/svn.go @@ -54,7 +54,7 @@ func (g *SVNDriver) HeadRev(dir string) (string, error) { return strings.TrimSpace(buf.String()), cmd.Wait() } -func (g *SVNDriver) Pull(dir string) (string, error) { +func (g *SVNDriver) Pull(dir string, _ string) (string, error) { cmd := exec.Command( "svn", "update", diff --git a/vcs/vcs.go b/vcs/vcs.go index 6f2588d6..56926ab6 100644 --- a/vcs/vcs.go +++ b/vcs/vcs.go @@ -19,7 +19,7 @@ type Driver interface { Clone(dir, url string) (string, error) // Pull new changes from the server and update the working directory. - Pull(dir string) (string, error) + Pull(dir string, ref string) (string, error) // Return the revision at the head of the vcs directory. HeadRev(dir string) (string, error) @@ -69,9 +69,9 @@ func exists(path string) bool { // A utility method that carries out the common operation of cloning // if the working directory is absent and pulling otherwise. -func (w *WorkDir) PullOrClone(dir, url string) (string, error) { +func (w *WorkDir) PullOrClone(dir, url, ref string) (string, error) { if exists(dir) { - return w.Pull(dir) + return w.Pull(dir, ref) } return w.Clone(dir, url) }