Exemple #1
0
func (c *GitPreCommitCmd) Run(args ...string) (err error) {
	var filenames []string
	var mod *model.Model
	if mod, err = model.New(c.WD, true, c.ChunkSize, c.PoolSize); err != nil {
		return
	}

	// In divert we need restrict check by target filenames
	divert := git.NewDivert(mod.Git)
	isInDivert, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if isInDivert {
		var spec git.DivertSpec
		if spec, err = divert.ReadSpec(); err != nil {
			return
		}
		filenames = spec.TargetFiles
	}

	isDirty, dirty, err := mod.Check(filenames...)
	if err != nil {
		return
	}
	if isDirty {
		err = fmt.Errorf("dirty files in working tree %s", dirty)
		return
	}

	feedR, err := mod.Git.Diff(filenames...)
	if err != nil {
		return
	}

	blobs, err := mod.Git.ManifestsFromDiff(feedR)
	if err != nil {
		return
	}

	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)
	err = trans.Upload(blobs)

	return
}
Exemple #2
0
func (c *GitInstallCmd) Run(args ...string) (err error) {
	var mod *model.Model
	if mod, err = model.New(c.WD, true, c.ChunkSize, c.PoolSize); err != nil {
		return
	}
	defer mod.Close()

	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)
	defer trans.Close()

	info, err := trans.ServerInfo()
	if err != nil {
		return
	}

	config := git.NewConfig(info, mod.Git)
	err = config.Install(c.Log)

	return
}
Exemple #3
0
func (c *DownCmd) Run(args ...string) (err error) {
	var mod *model.Model

	if mod, err = model.New(c.WD, c.UseGit, c.ChunkSize, c.PoolSize); err != nil {
		return
	}

	feed := lists.NewFileList(args...).ListDir(c.WD)

	isDirty, dirty, err := mod.Check(feed...)
	if err != nil {
		return
	}
	if isDirty {
		err = fmt.Errorf("dirty files in working tree %s", dirty)
		return
	}

	if c.UseGit {
		// filter by attrs
		feed, err = mod.Git.FilterByAttr("bar", feed...)
	}

	blobs, err := mod.FeedManifests(false, true, true, feed...)
	if err != nil {
		return
	}

	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)
	if err = trans.Download(blobs); err != nil {
		return
	}

	if c.UseGit {
		err = mod.Git.UpdateIndex(blobs.Names()...)
	}

	return
}
Exemple #4
0
func (c *SpecExportCmd) Run(args ...string) (err error) {
	var mod *model.Model
	if mod, err = model.New(c.WD, c.UseGit, c.ChunkSize, c.PoolSize); err != nil {
		return
	}

	feed := lists.NewFileList(args...).ListDir(c.WD)

	isDirty, dirty, err := mod.Check(feed...)
	if err != nil {
		return
	}
	if isDirty {
		err = fmt.Errorf("dirty files in working tree %s", dirty)
		return
	}

	if c.UseGit {
		// filter by attrs
		feed, err = mod.Git.FilterByAttr("bar", feed...)
	}

	blobs, err := mod.FeedManifests(true, true, true, feed...)
	if err != nil {
		return
	}

	// make specmap
	nameMap := map[string]proto.ID{}
	for name, m := range blobs {
		nameMap[name] = m.ID
	}

	spec, err := proto.NewSpec(time.Now().UnixNano(), nameMap, []string{})
	if err != nil {
		return
	}

	if c.DoCC {
		ccName := fmt.Sprintf("bar-spec-%d-%s.json",
			time.Now().UnixNano(), spec.ID)
		logx.Infof("storing carbon copy to %s", ccName)
		ccf, err := os.Create(lists.OSFromSlash(lists.OSJoin(c.WD, ccName)))
		if err != nil {
			return err
		}
		defer ccf.Close()

		if err = json.NewEncoder(ccf).Encode(&spec); err != nil {
			return err
		}
	}

	if !c.Upload {
		err = json.NewEncoder(c.Stdout).Encode(&spec)
		return
	}

	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)
	if err = trans.UploadSpec(spec); err != nil {
		return
	}
	fmt.Fprint(c.Stdout, spec.ID)
	return
}