You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
// Initialize non bare repo
r, err := git.PlainInit(path, false)
if err != git.ErrRepositoryAlreadyExists && err != nil {
log.Fatal(err)
}
// Open repo, if initialized
r, err = git.PlainOpen(path)
if err != nil {
log.Println(err)
}
// Add a upstream remote
_, err = r.CreateRemote(&config.RemoteConfig{
Name: "upstream",
URLs: []string{"https://github.com/src-d/go-git.git"},
})
if err != nil {
switch err {
case git.ErrRemoteNotFound:
log.Fatal("remote not found")
default:
log.Println(err)
}
}
// Get the working directory for the repository
w, err := r.Worktree()
if err != nil {
log.Fatal(err)
}
// Pull using default options
log.Println("Pulling https://github.com/src-d/go-git.git")
err = w.Pull(&git.PullOptions{
RemoteName: "upstream",
ReferenceName: plumbing.ReferenceName("refs/remotes/fix/checkout-empty-repo"),
})
if err != nil {
switch err {
case transport.ErrEmptyRemoteRepository:
log.Fatal("upstream repository is empty")
default:
log.Println(err)
}
}
The text was updated successfully, but these errors were encountered:
orirawlings
changed the title
repo.Reference(plumbing.ReferenceName("refs/remotes/origin/branch", true)) results in "reference not found" error
repo.Reference(plumbing.ReferenceName("refs/remotes/origin/branch"), true) results in "reference not found" error
Dec 5, 2017
When specifying your PullOptions.ReferenceName you need to use the name of the reference as it is stored in the remote (ex. something under refs/heads/*). So to fix this code you would do:
Steps to reproduce:
• Create new repository (git.Init)
• Add new remote (repo.CreateRemote)
• Fetch https://github.com/src-d/go-git.git/fix/checkout-empty-repo -> works
• Pull https://github.com/src-d/go-git.git/fix/checkout-empty-repo -> results in "reference not found error", but can print reference hash, type, etc.
Example code:
The text was updated successfully, but these errors were encountered: