Skip to content

Commit

Permalink
Merge pull request hound-search#36 from etsy/empty_repos
Browse files Browse the repository at this point in the history
Fixes hound-search#33, continue when a repo is empty and just report it
  • Loading branch information
kellegous committed Jan 31, 2015
2 parents 8481037 + 020504d commit 6ef3168
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
27 changes: 18 additions & 9 deletions src/hound/cmds/houndd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"net/http"
"os"
"errors"
"os/exec"
"path"
"path/filepath"
Expand Down Expand Up @@ -175,29 +176,37 @@ func makeSearchers(
}
}

validRepos := map[string]*config.Repo{}
// Now build and initialize a searcher for each repo.
// TODO(knorton): These could be done in parallel.
m := map[string]*searcher.Searcher{}
var err error
for name, repo := range cfg.Repos {
path := filepath.Join(cfg.DbPath, name)

var s *searcher.Searcher
var err error


if useStaleIndex {
s, err = searcher.NewFromExisting(path, repo)
} else {
s, err = searcher.New(path, repo)
}

if err != nil {
return nil, err
if err == nil {
m[strings.ToLower(name)] = s
validRepos[name] = repo
}
m[strings.ToLower(name)] = s

}

return m, nil
if err != nil {
err = errors.New("One or more repos failed to index")
}

// Update the config to only include repos we have successfully indexed
cfg.Repos = validRepos
return m, err
}

func makeTemplateData(cfg *config.Config) (interface{}, error) {
Expand Down Expand Up @@ -301,16 +310,16 @@ func main() {

idx, err := makeSearchers(&cfg, *flagStale)
if err != nil {
panic(err)
info_log.Println("Some repos failed to index, see output above")
} else {
info_log.Println("All indexes built!")
}


formattedAddress := *flagAddr
if (0 == strings.Index(*flagAddr, ":")) {
formattedAddress = "localhost" + *flagAddr
}

info_log.Printf("All indexes built, running server at http://%s...\n", formattedAddress)
info_log.Printf("running server at http://%s...\n", formattedAddress)

if err := runHttp(*flagAddr, *flagRoot, *flagProd, &cfg, idx); err != nil {
panic(err)
Expand Down
10 changes: 6 additions & 4 deletions src/hound/vcs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package vcs
import (
"bytes"
"io"
"io/ioutil"
"log"
"os/exec"
"path/filepath"
"strings"
Expand Down Expand Up @@ -43,8 +43,9 @@ func (g *GitDriver) HeadHash(dir string) (string, error) {
func (g *GitDriver) Pull(dir string) (string, error) {
cmd := exec.Command("git", "pull")
cmd.Dir = dir
err := cmd.Run()
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Failed to git pull %s, see output below\n%sContinuing...", dir, out)
return "", err
}

Expand All @@ -59,8 +60,9 @@ func (g *GitDriver) Clone(dir, url string) (string, error) {
url,
rep)
cmd.Dir = par
cmd.Stdout = ioutil.Discard
if err := cmd.Run(); err != nil {
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Failed to clone %s, see output below\n%sContinuing...", url, out)
return "", err
}

Expand Down

0 comments on commit 6ef3168

Please sign in to comment.