Example #1
0
// Synchronize remote specifications across all the repositories.
func SyncRemotes() {
	for reponame, repo := range AllRepos() {
		remotes := repo.Remotes()
		for _, remote := range Remotes {
			repopath := remote.Urlbase + "/" + reponame
			if url, found := remotes[remote.Name]; found {
				continue
			} else if found && url != repopath {
				log.Printf("Remote %s in repo %s not pointing at proper URL.\n", remote.Name, reponame)
				repo.ZapRemote(remote.Name)
			}
			if found, _ := git.ProbeURL(repopath); found {
				log.Printf("Adding new remote %s (%s) to %s\n", remote.Name, repopath, reponame)
				repo.AddRemote(remote.Name, repopath)
			} else {
				log.Printf("Repo %s is not at remote %s\n", reponame, remote.Name)
			}
		}
	}
}
Example #2
0
// Clone any missing barclamps we may need.
func CloneBarclamps() {
	barclampsToClone := make(BarclampMap)
	// Find all our missing barclamps
	for _, release := range Meta.Releases() {
		for _, barclamp := range release.Barclamps() {
			if barclamp.Repo != nil {
				continue
			}
			if _, ok := barclampsToClone[barclamp.Name]; ok {
				continue
			}
			log.Printf("Need to clone %s\n", barclamp.Name)
			barclampsToClone[barclamp.Name] = barclamp
		}
	}
	if len(barclampsToClone) == 0 {
		// Nothing to do, move along.
		log.Println("No barclamps need to be cloned.")
		return
	}
	type cloneRes struct {
		name string
		repo *git.Repo
		err  error
	}
	c := make(chan *cloneRes)
	defer close(c)
	cloner := func(name string, c chan *cloneRes) {
		res := &cloneRes{name: name}
		barclampPath := filepath.Join(Repo.Path(), "barclamps", name)
		if _, err := os.Stat(barclampPath); err == nil {
			res.err = fmt.Errorf("%s already exists, cowardly refusing to clone!", barclampPath)
			c <- res
			return
		}
		for _, remote := range SortedRemotes() {
			source := remote.Urlbase + "/barclamp-" + name + ".git"
			if found, _ := git.ProbeURL(source); !found {
				continue
			}
			res.repo, res.err = git.Clone(source, barclampPath, "--origin", remote.Name)
			c <- res
			return
		}
		res.err = fmt.Errorf("Could not find barclamp %s at any known remotes!", name)
		c <- res
	}
	for _, bc := range barclampsToClone {
		go cloner(bc.Name, c)
	}
	for _, _ = range barclampsToClone {
		res := <-c
		if res.repo != nil {
			barclampsToClone[res.name].Repo = res.repo
			Barclamps[res.name] = res.repo
			log.Printf("Cloned barclamp %s\n", res.name)
		} else {
			log.Println(res.err)
		}
	}
	SyncRemotes()
}