Skip to content
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

Trying to fetch all tags fails #927

Merged
merged 3 commits into from Jan 24, 2015
Merged

Trying to fetch all tags fails #927

merged 3 commits into from Jan 24, 2015

Conversation

nulltoken
Copy link
Member

Related to this: http://stackoverflow.com/questions/28091482/how-to-pull-all-new-tags-using-libgit2sharp

Essentially I would like to use libgit2sharp to achieve 'git pull --tags'
I am using libgit2sharp 0.20.2

Here is a sample which fails for me:

static void Main(string[] args)
{
    const string haskellMode = "https://github.com/haskell/haskell-mode.git";

    var guid = Guid.NewGuid().ToString();
    var wdir = string.Format("%TEMP%/git-fetch-tags-{0}", guid);
    wdir = Environment.ExpandEnvironmentVariables(wdir);

    var sig = new Signature("hendrik", "hendrik@somemail.ee", new DateTimeOffset());

    var repoWithTags = Repository.Clone(haskellMode, wdir);
    Console.WriteLine(repoWithTags);

    using (var repo = new Repository(repoWithTags))
    {
        // this one works, but if there are any new tags in the remote it does not get them
        repo.Network.Pull(sig, new PullOptions());

        // this one throws
        repo.Network.Pull(sig, new PullOptions { FetchOptions = new FetchOptions { TagFetchMode = TagFetchMode.All } });

        // this one also throws but I think it manages to get the tags
        repo.Fetch("origin", new FetchOptions { TagFetchMode = TagFetchMode.All });

        Console.WriteLine("Done for {0}", haskellMode);
    }

    Console.ReadLine();
}

@nulltoken
Copy link
Member

@hendrikmaarand Thanks a lot for raising this! Just a quick request:

Could you please also add the complete exception stack traces regarding the failures?

@hendrikmaarand
Copy link
Author

Stack trace for the first one:

LibGit2Sharp.LibGit2SharpException: ref 'refs/remotes/origin/master' doesn't match the destination
  at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
  at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
  at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteSafeHandle remote, Signature signature, String logMessage)
  at LibGit2Sharp.Network.DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, Signature signature, String logMessage)
  at LibGit2Sharp.Network.Fetch(Remote remote, FetchOptions options, Signaturesignature, String logMessage)
  at LibGit2Sharp.Network.Pull(Signature merger, PullOptions options)   
  at ConsoleApplication4.Program.Main(String[] args) in c:\Users\hendrik\Documents\Visual Studio 2013\Projects\ConsoleApplication4\ConsoleApplication4\Program.cs:line 30

For the second one:

LibGit2Sharp.LibGit2SharpException: ref 'refs/remotes/origin/master' doesn't match the destination
  at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
  at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
  at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteSafeHandle remote, Signature signature, String logMessage)
  at LibGit2Sharp.Network.DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, Signature signature, String logMessage)
  at LibGit2Sharp.Network.Fetch(Remote remote, FetchOptions options, Signature signature, String logMessage)
  at LibGit2Sharp.RepositoryExtensions.Fetch(IRepository repository, String remoteName, FetchOptions options)
  at ConsoleApplication4.Program.Main(String[] args) in c:\Users\hendrik\Documents\Visual Studio 2013\Projects\ConsoleApplication4\ConsoleApplication4\Program.cs:line 34

@nulltoken
Copy link
Member

@hendrikmaarand Great! Could you please also include the exception messages?

@hendrikmaarand
Copy link
Author

@nulltoken Updated!

@nulltoken
Copy link
Member

Hmmm. I can't repro against the latest vNext. The following test pass

[Fact]
public void Issue_927()
{
    var scd = BuildSelfCleaningDirectory();

    string clonedRepoPath = Repository.Clone("https://github.com/haskell/haskell-mode.git", scd.DirectoryPath);

    using (var repo = new Repository(clonedRepoPath))
    {
        var sig = new Signature("hendrik", "hendrik@somemail.ee", new DateTimeOffset());
        repo.Network.Pull(sig, new PullOptions());
        repo.Network.Pull(sig,
            new PullOptions { FetchOptions = new FetchOptions { TagFetchMode = TagFetchMode.All } });
        repo.Fetch("origin", new FetchOptions { TagFetchMode = TagFetchMode.All });
    }
}

Can you confirm?

If you're not willing to build the source code by yourself, you could download a prerelase NuGet package from https://ci.appveyor.com/project/libgit2/libgit2sharp/build/0.20.2.127/job/b74exootjw18apt2/artifacts and check your code against this new version (this will require you to add a new local NuGet source).

Please, do not use this package in production 😉

@nulltoken
Copy link
Member

Confirmed repro in v0.20.2

@nulltoken nulltoken added the Bug label Jan 23, 2015
@nulltoken nulltoken added this to the v0.21 milestone Jan 23, 2015
@nulltoken
Copy link
Member

Thanks a lot for this report... and sorry for the inconvenience 😕

Will be fixed as part of v0.21 (which should be released shortly).

[InlineData(TagFetchMode.All, 4)]
[InlineData(TagFetchMode.None, 0)]
[InlineData(TagFetchMode.Auto, 3)]
//[InlineData(TagFetchMode.Auto, 3)] // TODO: Skipping due to github modification of --include-tag handling."
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlosmn git fetch against a newly initialized repository with the following config

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = https://github.com/libgit2/TestGitRepository
    fetch = +refs/heads/*:refs/remotes/origin/*

outputs

$ git fetch
remote: Counting objects: 68, done.
remote: Total 68 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (68/68), done.
From https://github.com/libgit2/TestGitRepository
 * [new branch]      first-merge -> origin/first-merge
 * [new branch]      master     -> origin/master
 * [new branch]      no-parent  -> origin/no-parent
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 1 (delta 0)
Unpacking objects: 100% (1/1), done.
 * [new tag]         annotated_tag -> annotated_tag
 * [new tag]         blob       -> blob
 * [new tag]         commit_tree -> commit_tree

Aren't we missing something in the way we handle the auto mode?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git is noticing that the server did not automatically send the tags and is performing a second fetch. This second fetch is completely different from the first one, so atm I don't think libgit2 should emulate that behaviour since we implement the underlying functionality, not the UI git wants to provide.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlosmn Thanks for this explanation. Do you think LibGit2Sharp should mimic git behavior?

/cc @ethomson @jamill @dahlbyk @Therzok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so - or at least a way to have it fetch with "expected" behavior. If someone wanted the "underlying functionality" behavior, maybe we could expose that as an advanced method.

As a writer of an application calling into lg2#'s fetch, I would expect for it to fetch tags (and not have to handle that in my application).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #936 to keep track of this.

@nulltoken
Copy link
Member

@hendrikmaarand I've transmuted this issue into a Pull Request with additional test coverage.

nulltoken added a commit that referenced this pull request Jan 24, 2015
Trying to fetch all tags fails
@nulltoken nulltoken merged commit 5de56d4 into vNext Jan 24, 2015
@nulltoken nulltoken deleted the ntk/issue_927 branch January 24, 2015 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants