func()

in tools/eksDistroBuildToolingOpsTools/pkg/git/gogitClient.go [199:235]


func (g *GogitClient) Pull(ctx context.Context, branch string) error {
	logger.V(4).Info("Pulling from remote", "repo", g.RepoDirectory, "remote", gogit.DefaultRemoteName)
	r, err := g.Client.OpenRepo()
	if err != nil {
		return fmt.Errorf("pulling from remote: %v", err)
	}

	w, err := g.Client.OpenWorktree(r)
	if err != nil {
		return fmt.Errorf("pulling from remote: %v", err)
	}

	branchRef := plumbing.NewBranchReferenceName(branch)

	err = g.Client.PullWithContext(ctx, w, g.Auth, branchRef)

	if errors.Is(err, gogit.NoErrAlreadyUpToDate) {
		logger.V(4).Info("Local repo already up-to-date", "repo", g.RepoDirectory, "remote", gogit.DefaultRemoteName)
		return &RepositoryUpToDateError{}
	}

	if err != nil {
		return fmt.Errorf("pulling from remote: %v", err)
	}

	ref, err := g.Client.Head(r)
	if err != nil {
		return fmt.Errorf("pulling from remote: %v", err)
	}

	commit, err := g.Client.CommitObject(r, ref.Hash())
	if err != nil {
		return fmt.Errorf("accessing latest commit after pulling from remote: %v", err)
	}
	logger.V(4).Info("Successfully pulled from remote", "repo", g.RepoDirectory, "remote", gogit.DefaultRemoteName, "latest commit", commit.Hash)
	return nil
}