New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to clone/push to an empty repo #986
Comments
|
And also for a empty remote repo, if push something, it also occurs an error. |
I can't reproduce this issue. Could you give me an example code? |
AFAIK the clone part is intentional, and the @Darylddd please share a code snippet so that it is easier to reproduce the error trying to push to an empty repository. |
I've looked through about half of the projects for how they use Including the project you referenced, most of projects uses So I think hiding Another issue with returning error is when we pull or fetch from empty repo. This is git command line behavior.
This is go-git code snippet. package main
import (
"fmt"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport"
)
func main() {
// opening an empty repo
r, err := git.PlainOpen("./empty")
if err != nil {
panic(err)
}
err = r.Fetch(&git.FetchOptions{})
if err != nil {
if err == transport.ErrEmptyRemoteRepository {
fmt.Println("remote repository empty")
}
}
wt, err := r.Worktree()
if err != nil {
panic(err)
}
err = wt.Pull(&git.PullOptions{})
if err != nil {
if err == transport.ErrEmptyRemoteRepository {
fmt.Println("remote repository empty")
}
}
}
I think this kind of is inconsistency between go-git and git if you think we have to match behavior between those two. |
This behaviour is by design and is meant to be documented as per #909. As nicely pointed out by Hidde:
Not all applications that rely on In the future, we could look into making it easier to support the second use case with minimal amount of code needed. But that is beyond the scope of this issue and would be an enhancement request on its own right. |
You have the point. I didn't know there were discussion about this. Thanks for answering! Then we'll only need to check if push fails. |
If it is a new repo, there is only the HEAD file in .git, and the reference corresponding to HEAD cannot be found.
The text was updated successfully, but these errors were encountered: