Exemplo n.º 1
0
// Pushes to remote if local path exists and in a god context. If path is a
// directory, it recursively pushes to the remote if there are local changes.
// It doesn't check if there are local changes if isForce is set.
func (g *Commands) Push() (err error) {
	if g.context == nil {
		return ErrNoContext
	}

	absPath := g.context.AbsPathOf(g.opts.Path)
	r, err := g.rem.FindByPath(g.opts.Path)
	if err != nil && err != remote.ErrPathNotExists {
		return err
	}

	var l *types.File
	localinfo, _ := os.Stat(absPath)
	if localinfo != nil {
		l = types.NewLocalFile(absPath, localinfo)
	}

	fmt.Println("Resolving...")
	var cl []*types.Change
	if cl, err = g.resolveChangeListRecv(true, g.opts.Path, r, l); err != nil {
		return err
	}

	if ok := printChangeList(cl, g.opts.IsNoPrompt); ok {
		return g.playPushChangeList(cl)
	}
	return
}
Exemplo n.º 2
0
// Pull from remote if remote path exists and in a god context. If path is a
// directory, it recursively pulls from the remote if there are remote changes.
// It doesn't check if there are remote changes if isForce is set.
func (g *Commands) Pull() (err error) {
	if g.context == nil {
		return ErrNoContext
	}

	var r, l *types.File
	if r, err = g.rem.FindByPath(g.opts.Path); err != nil {
		return nil
	}
	absPath := g.context.AbsPathOf(g.opts.Path)
	localinfo, _ := os.Stat(absPath)
	if localinfo != nil {
		l = types.NewLocalFile(absPath, localinfo)
	}

	var cl []*types.Change
	fmt.Println("Resolving...")
	if cl, err = g.resolveChangeListRecv(false, g.opts.Path, r, l); err != nil {
		return
	}

	if ok := printChangeList(cl, g.opts.IsNoPrompt); ok {
		return g.playPullChangeList(cl)
	}
	return
}
Exemplo n.º 3
0
func list(context *config.Context, path string) (files []*types.File, err error) {
	absPath := context.AbsPathOf(path)
	var f []os.FileInfo
	if f, err = ioutil.ReadDir(absPath); err != nil {
		return
	}
	for _, file := range f {
		// ignore hidden files
		if !strings.HasPrefix(file.Name(), ".") {
			files = append(files, types.NewLocalFile(gopath.Join(absPath, file.Name()), file))
		}
	}
	return
}