示例#1
0
文件: denv.go 项目: buckhx/denv
// 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)
	}
}
示例#2
0
文件: git.go 项目: buckhx/gitlib
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
}
示例#3
0
文件: denv.go 项目: buckhx/denv
// 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
}
示例#4
0
文件: info.go 项目: buckhx/denv
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()
}
示例#5
0
文件: denv.go 项目: buckhx/denv
// 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())
	}
}
示例#6
0
文件: info.go 项目: buckhx/denv
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
}
示例#7
0
文件: git.go 项目: buckhx/gitlib
func IsRepository(path string) bool {
	return pathutil.Exists(pathlib.Join(path, ".git"))
}