libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.19k stars 888 forks source link

Fetch fails if the local repository is a Bare Repository #426

Closed jacobaloysious closed 10 years ago

jacobaloysious commented 11 years ago

I have a Cloned Bare repository.

When I do a fetch, it throws an exception. Reference on SO

public void Fetch()
{
    var remote = this.LibGit2SharpRepo.Network.Remotes.FirstOrDefault();
    if (remote != null)
    {
        this.LibGit2SharpRepo.Fetch(remoteName:"origin");
        //TODO : Soft reset to the latest commit
    }
 }

private IRepository _libGit2SharpRepo;
public IRepository LibGit2SharpRepo
{
    get { return _libGit2SharpRepo ?? (_libGit2SharpRepo = new Repository(this.RepositoryPath)); }
 }

Notes: Bare repository fetch works with git.exe. LigGit2Sharp fetch works well with a Normal Repository..

Here is how the config files looks like for bare and Normal repo respectively

git_config

jacobaloysious commented 11 years ago

While trying to debug. I noted that the below Clone test fails. Note : I ran only this test using xUnit gui.

LibGit2Sharp.Tests.CloneFixture.CanClone

But after updating the test to clone as a bare repo, the test passed.

using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath,bare:true))

Not sure if they are related..

nulltoken commented 11 years ago

@carlosmn Could you please take a look at this issue, please?

carlosmn commented 11 years ago

The configuration for the bare repository that you have provided would not cause that error to appear, as it contains no fetch refspec, and thus we wouldn't even try to create any remote-tracking branches.

Can you provide a copy of that RemoteGitRepo.git that's causing problems?

It's quite suspicious that the tests don't pass, but do when you modify it so it's bare. Do you have something in your global or system configuration that may be affecting this? (Running git config --list outside of a repo would show it)

carlosmn commented 11 years ago

Also, the local transport is somewhat hacky. Can you reproduce with git:// or http://?

jacobaloysious commented 11 years ago

Do you have something in your global or system configuration that may be affecting this?

$ git config --list core.symlinks=false core.autocrlf=true color.diff=auto color.status=auto color.branch=auto color.interactive=true pack.packsizelimit=2g help.format=html http.sslcainfo=/bin/curl-ca-bundle.crt sendemail.smtpserver=/bin/msmtp.exe diff.astextplain.textconv=astextplain rebase.autosquash=true user.name=Jacob Aloysious user.email=jacobaloysious@gmail.com

jacobaloysious commented 11 years ago

Can you provide a copy of that RemoteGitRepo.git that's causing problems

Attached the RemoteGitRepo.git. As a quick recipe, I renamed the extension to .jpg and uploaded ;-) Please download (rt click-> save image as) and rename it to .zip

remotegitrepo git zip

jacobaloysious commented 11 years ago

@carlosmn Please let me know if you need any more inputs..

nulltoken commented 11 years ago

While trying to debug. I noted that the below Clone test fails. Note : I ran only this test using xUnit gui.

LibGit2Sharp.Tests.CloneFixture.CanClone

But after updating the test to clone as a bare repo, the test passed.

using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath,bare:true))

Not sure if they are related..

@jacobaloysious This is really surprising. I've never seen this one fail. Does this still happen when performing a fresh clone of LibGit2Sharp and launching build.libgit2sharp.cmd?

jamill commented 11 years ago

@jacobaloysious one possibility is that your remote repository has a detached head. To verify, would you be able to paste the output of ls-git against the remote that fetch is failing? If you prefer not to share, could you check if the first line is a HEAD reference, and if the OID matches any of the branch references? for instance, running the following command against libgit2 repository here on GitHub:

prompt> git ls-remote origin f0ab73720a4e7a9b37c901a27519ea65eafeb8a6 HEAD 8e60c712acef798a6b3913359f8d9dffcddf7256 refs/heads/8bit-filename-status ... f0ab73720a4e7a9b37c901a27519ea65eafeb8a6 refs/heads/development

where HEAD is the same OID as refs/heads/development.

jacobaloysious commented 11 years ago

@jamill : I see that in my case the HEAD, master, tags/ver-5.0.0 are the same. Below is the output.

>git ls-remote origin d43bf06c1f858d4630e512d3188165e5f8dc9aaf HEAD d43bf06c1f858d4630e512d3188165e5f8dc9aaf refs/heads/master 7f826be369a30b1f4572a668c5a5cdb52ae91c45 refs/stash 8f22107f20ab9bce6ab8f9083eec2e056b4b37fa refs/tags/ver-1.0.0 d74c0c9f07790d6ee4621e1c4d1b144cca3f2b0e refs/tags/ver-1.0.0^{} b83eb0972f57f9145b278bd2591fcc72d99bdec4 refs/tags/ver-2.0.0 70135e3b71ac81dd4e2d8cd89c45e2a6d87b3473 refs/tags/ver-2.0.0^{} d98c00fbc7e79ee297b4a02d842e932bd466cc02 refs/tags/ver-3.0.0 4b4ec86f9e711808023ab5294b938e8f86951c13 refs/tags/ver-3.0.0^{} fa7028268402cdd6e638b901fa4e249907789c04 refs/tags/ver-4.0.0 d43bf06c1f858d4630e512d3188165e5f8dc9aaf refs/tags/ver-5.0.0

PS: I have attached my remote repository in my above comment.

jacobaloysious commented 11 years ago

@nulltoken : Below is how my CanClone unit test fails..

I also observe that on the disk, the repository has actually been cloned correctly. I am able to run git command on it.

But the working tree has not been checked out. Therefore at the last step of Clone, when new Repository instance is created. It tries to open the repo and it fails.

untitled

jacobaloysious commented 11 years ago

@nulltoken : Another observation, the failure is not very consistent.

When it fails, I see a LOCK on the HEAD file HEAD.lock

LibGit2Sharp.Tests.CloneFixture.CanClone(url: "https://github.com/libgit2/TestGitRepository") : System.UnauthorizedAccessException : Access to the path 'D:\Personal\Projects\LibGitSharp\libgit2sharp\LibGit2Sharp.Tests\bin\Debug\TestRepos\1fa6540f.git\HEAD' is denied.

aviatrix commented 10 years ago

I just recieved an error trying to fetch a local bare repository.

Any progress on fixing this ?

nulltoken commented 10 years ago

@aviatrix AFAIK we've never been able to reproduce this issue.

Can you please some repro steps that would help us troubleshooting this?

nulltoken commented 10 years ago

Closing this for now. Feel free to reopen it if you can reproduce the failure. We'll be happy to work on it.