func checkout()

in cmd/git_clone.go [66:92]


func checkout(cmd *cobra.Command, path string) error {
	repo, err := git.PlainOpen(path)
	if err != nil {
		return err
	}

	if len(Rev) > 0 {
		worktree, err := repo.Worktree()
		if err != nil {
			return err
		}
		var checkoutOptions git.CheckoutOptions

		if isHash(Rev) {
			fmt.Println("checking out hash:", Rev)
			checkoutOptions = git.CheckoutOptions{Hash: plumbing.NewHash(Rev)}
		} else {
			fmt.Println("checking out branch:", Rev)
			checkoutOptions = git.CheckoutOptions{Branch: plumbing.ReferenceName("refs/remotes/origin/" + Rev)}
		}
		err = worktree.Checkout(&checkoutOptions)
		if err != nil {
			return err
		}
	}
	return nil
}