Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Unable to pull from branch #1271

Open
Raffo opened this issue Jan 3, 2020 · 0 comments
Open

Unable to pull from branch #1271

Raffo opened this issue Jan 3, 2020 · 0 comments

Comments

@Raffo
Copy link

Raffo commented Jan 3, 2020

I'm trying to open a local repo and pull it. I want to checkout a specific branch identified by the var branch. I'm doing the following:

dir, err := os.Getwd()
	if err != nil {
		logrus.Errorf("error getting current directory: %v", err)
	}

	currentUser, err := user.Current()
	if err != nil {
		logrus.Errorf("error getting current user: %v", err)
	}

	sshAuth, err := ssh.NewPublicKeysFromFile("git", currentUser.HomeDir+"/.ssh/id_rsa", "")
	if err != nil {
		logrus.Errorf("error getting public key: %v", err)
	}

	r, err := git.PlainOpenWithOptions(dir, &git.PlainOpenOptions{DetectDotGit: true})
	if err != nil {
		logrus.Errorf("error opening repo: %v", err)
	}
	w, err := r.Worktree()
	if err != nil {
		logrus.Errorf("error getting worktree: %v", err)
	}
	err = w.Checkout(&git.CheckoutOptions{
		Branch: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", branch)),
	})
	if err != nil {
		logrus.Errorf("error checking out repo: %v", err)
	}

	err = w.Pull(&git.PullOptions{ReferenceName: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", branch)), Auth: sshAuth})
	if err != nil {
		logrus.Errorf("error pulling repo: %v", err)
	}

I keep getting errornon-fast-forward update when trying to pull. From a debug session, I saw that in https://github.com/src-d/go-git/blob/master/worktree.go#L89 master is actually returned and this causes issues when determining if we are in a fast forward situation.

Can someone help debug this issue and/or suggest how to proceed?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant