Exemplo n.º 1
0
func TestUpdateCommand(t *testing.T) {
	if testing.Short() {
		t.Skip("skip a test for update command")
	}

	repo, err := git.NewRepository(config.RepositoryPath)
	if err != nil {
		t.Fatal("failed to initialize a reporitory")
	}

	hash, err := repo.Hash("origin/HEAD")
	if err != nil {
		t.Fatal("failed to get a hash of origin/HEAD")
	}

	app := makeTestEnv()
	app.Run([]string{"pgenv", "update"})

	updated, err := repo.Hash("origin/HEAD")
	if err != nil {
		t.Fatal("failed to get a hash of origin/HEAD")
	}

	if hash == updated {
		t.Error("local repository is not updated")
	}
}
Exemplo n.º 2
0
// DoUpdate is an implementation of update command
func DoUpdate(c *cli.Context) {
	log.Info("update a local git repository")
	repo, err := git.NewRepository(config.RepositoryPath)
	if err != nil {
		log.WithField("err", err).Fatal("failed to initialize a reporitory")
	}

	if out, err := repo.Fetch(); err != nil {
		log.WithFields(log.Fields{
			"err": err.Error(),
			"out": out,
		}).Fatal("failed to fetch")
	}
}
Exemplo n.º 3
0
// InstallCompletion provides cli completion of install command
func InstallCompletion(c *cli.Context) {
	if len(c.Args()) == 0 {
		repo, err := git.NewRepository(config.RepositoryPath)
		if err != nil {
			log.WithField("err", err).Fatal("failed to initialize local reporitory")
		}
		tags, err := repo.Tags()
		if err != nil {
			log.WithField("err", err).Fatal("failed to get tags")
		}
		for _, t := range tags {
			fmt.Println(t)
		}
	}
}
Exemplo n.º 4
0
// DoAvailable is an implementation of available command
func DoAvailable(c *cli.Context) {
	repo, err := git.NewRepository(config.RepositoryPath)
	if err != nil {
		log.WithField("err", err).Fatal("failed to initialize local reporitory")
	}

	tags, err := repo.Tags()
	if err != nil {
		log.WithField("err", err).Fatal("failed to get tags")
	}

	fmt.Println("Available versions:")
	for _, tag := range tags {
		fmt.Printf("\t%s\n", tag)
	}
}
Exemplo n.º 5
0
func doCheckout(gitRef string, workdir string) (string, error) {
	log.WithField("git ref", gitRef).Info("git checkout")

	repo, err := git.NewRepository(config.RepositoryPath)
	if err != nil {
		return "", fmt.Errorf("failed to get a repository: %s", err)
	}

	if out, err := repo.CheckoutWithWorkTree(gitRef, workdir); err != nil {
		return "", fmt.Errorf("failed to checkout: %s, %s", err, out)
	}
	defer repo.Checkout("master")

	hash, err := repo.HeadHash()
	if err != nil {
		return "", fmt.Errorf("failed to get a hash of HEAD: %s", err)
	}

	return hash, nil
}