Beispiel #1
0
// Create the denv path and denvignore if they don't already exist
func (d *Denv) bootstrap() {
	if !pathutil.Exists(d.Path) {
		err := os.MkdirAll(d.Path, 0744)
		check(err)
		err = ioutil.WriteFile(d.ignoreFile(), []byte(_default_denvignore), 0644)
		check(err)
	}
}
Beispiel #2
0
func NewRepository(path string) (repo *Repository, err error) {
	if !pathutil.Exists(path) {
		err = fmt.Errorf("Cannot instantiate Repository because path doesn't exist at %q", path)
	} else {
		repo = &Repository{}
		repo.Path = path
	}
	return
}
Beispiel #3
0
// Get a Denv that has already been created
// Nil, err if it hasn't been created yet
func GetDenv(name string) (*Denv, error) {
	if len(name) < 1 {
		return nil, fmt.Errorf("Denv name can't be empty")
	}
	path := pathlib.Join(Settings.DenvHome, name)
	if !pathutil.Exists(path) {
		return nil, fmt.Errorf("Denv %s does not exist", name)
	}
	return NewDenv(name), nil
}
Beispiel #4
0
func init() {
	bootstrap()
	path := Settings.InfoFile
	Info.Path = path
	repo, err := git.NewRepository(Settings.DenvHome)
	check(err)
	Info.Repository = repo
	if !pathutil.Exists(path) {
		Info.Flush()
	}
	Info.Load()
}
Beispiel #5
0
// Loads the denvignore from disk
func (d *Denv) LoadIgnore() {
	d.Ignore = make(map[string]bool)
	if pathutil.Exists(d.ignoreFile()) == true {
		content, err := ioutil.ReadFile(d.ignoreFile())
		check(err)
		//TODO handle comments and stuff
		patterns := strings.Split(string(content), "\n")
		for _, pattern := range patterns {
			path := d.expandPath(pattern)
			d.Ignore[path] = true
		}
	} else {
		fmt.Printf("Warning: Denv %s has no .denvignore file at %s, all hidden files will be managed\n", d.Name(), d.ignoreFile())
	}
}
Beispiel #6
0
func bootstrap() error {
	//TODO: maybe this should live somewhere else
	// Create DENVHOME
	if !pathutil.Exists(Settings.DenvHome) {
		err := os.MkdirAll(Settings.DenvHome, 0744)
		if err != nil {
			return err
		}
	}
	if !git.IsRepository(Settings.DenvHome) {
		repo, err := git.NewRepository(Settings.DenvHome)
		check(err)
		repo.Init()
		repo.Exclude("/.*") // exclude hidden root files
	}
	return nil
}
Beispiel #7
0
func IsRepository(path string) bool {
	return pathutil.Exists(pathlib.Join(path, ".git"))
}