From 8c2538d6772c8b2ea725d4498666bf5cfb4d6729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 22 Mar 2016 12:12:55 +0100 Subject: [PATCH 1/3] Convert Pull into a command This makes it clearer that what we have there is a command and not a method fundamental to the Git system. --- LibGit2Sharp.Tests/NetworkFixture.cs | 6 +-- LibGit2Sharp/Commands/Pull.cs | 59 ++++++++++++++++++++++++++++ LibGit2Sharp/LibGit2Sharp.csproj | 4 ++ LibGit2Sharp/Network.cs | 23 +---------- 4 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 LibGit2Sharp/Commands/Pull.cs diff --git a/LibGit2Sharp.Tests/NetworkFixture.cs b/LibGit2Sharp.Tests/NetworkFixture.cs index fe5a2b04f..1f3a89f70 100644 --- a/LibGit2Sharp.Tests/NetworkFixture.cs +++ b/LibGit2Sharp.Tests/NetworkFixture.cs @@ -164,7 +164,7 @@ public void CanPull(FastForwardStrategy fastForwardStrategy) } }; - MergeResult mergeResult = repo.Network.Pull(Constants.Signature, pullOptions); + MergeResult mergeResult = new Commands.Pull(repo, Constants.Signature, pullOptions).Run(); if(fastForwardStrategy == FastForwardStrategy.Default || fastForwardStrategy == FastForwardStrategy.FastForwardOnly) { @@ -197,7 +197,7 @@ public void CanPullIntoEmptyRepo() b => b.UpstreamBranch = "refs/heads/master"); // Pull! - MergeResult mergeResult = repo.Network.Pull(Constants.Signature, new PullOptions()); + MergeResult mergeResult = new Commands.Pull(repo, Constants.Signature, new PullOptions()).Run(); Assert.Equal(mergeResult.Status, MergeStatus.FastForward); Assert.Equal(mergeResult.Commit, repo.Branches["refs/remotes/origin/master"].Tip); @@ -224,7 +224,7 @@ public void PullWithoutMergeBranchThrows() try { - repo.Network.Pull(Constants.Signature, new PullOptions()); + new Commands.Pull(repo, Constants.Signature, new PullOptions()).Run(); } catch(MergeFetchHeadNotFoundException ex) { diff --git a/LibGit2Sharp/Commands/Pull.cs b/LibGit2Sharp/Commands/Pull.cs new file mode 100644 index 000000000..a73a23351 --- /dev/null +++ b/LibGit2Sharp/Commands/Pull.cs @@ -0,0 +1,59 @@ +using System; +using LibGit2Sharp; +using LibGit2Sharp.Core; + +namespace LibGit2Sharp.Commands +{ + /// + /// Fetch changes from the configured upstream remote and branch into the branch pointed at by HEAD. + /// + public class Pull + { + private readonly Repository repository; + private readonly Signature merger; + private readonly PullOptions options; + + /// + /// Initializes a new instance of the class. + /// + /// The repository. + /// The signature to use for the merge. + /// The options for fetch and merging. + public Pull(Repository repository, Signature merger, PullOptions options) + { + Ensure.ArgumentNotNull(repository, "repository"); + Ensure.ArgumentNotNull(merger, "merger"); + Ensure.ArgumentNotNull(options, "options"); + + this.repository = repository; + this.merger = merger; + this.options = options; + } + + /// + /// Run this command + /// + public MergeResult Run() + { + + Branch currentBranch = repository.Head; + + if (!currentBranch.IsTracking) + { + throw new LibGit2SharpException("There is no tracking information for the current branch."); + } + + using (var remote = repository.Network.Remotes.RemoteForName(currentBranch.RemoteName)) + { + if (remote == null) + { + throw new LibGit2SharpException("No upstream remote for the current branch."); + } + + repository.Network.Fetch(remote, options.FetchOptions); + return repository.MergeFetchedRefs(merger, options.MergeOptions); + } + } + } +} + diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 0851a5041..653626cfd 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -350,6 +350,7 @@ + @@ -386,4 +387,7 @@ --> + + + \ No newline at end of file diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index be4bd27ba..a4c157009 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -549,29 +549,10 @@ public virtual void Push(Remote remote, IEnumerable pushRefSpecs, PushOp /// /// If the merge is a non-fast forward merge that generates a merge commit, the of who made the merge. /// Specifies optional parameters controlling merge behavior of pull; if null, the defaults are used. + [Obsolete("This method is deprecated. Please use the LibGit2Sharp.Commands.Pull class")] public virtual MergeResult Pull(Signature merger, PullOptions options) { - Ensure.ArgumentNotNull(merger, "merger"); - Ensure.ArgumentNotNull(options, "options"); - - Branch currentBranch = repository.Head; - - if (!currentBranch.IsTracking) - { - throw new LibGit2SharpException("There is no tracking information for the current branch."); - } - - string remoteName = currentBranch.RemoteName; - if (remoteName == null) - { - throw new LibGit2SharpException("No upstream remote for the current branch."); - } - - using (var remote = repository.Network.Remotes.RemoteForName(remoteName)) - { - Fetch(remote, options.FetchOptions); - return repository.MergeFetchedRefs(merger, options.MergeOptions); - } + return new Commands.Pull(repository, merger, options).Run(); } /// From 53dc1c27a15225c24bed09bd4f104698b0d94da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 22 Mar 2016 13:13:18 +0100 Subject: [PATCH 2/3] Convert Fetch into a command --- LibGit2Sharp.Tests/FetchFixture.cs | 32 +++--- LibGit2Sharp.Tests/NetworkFixture.cs | 12 +- LibGit2Sharp.Tests/RepositoryFixture.cs | 6 +- .../SmartSubtransportFixture.cs | 13 ++- LibGit2Sharp/Commands/Fetch.cs | 97 ++++++++++++++++ LibGit2Sharp/Commands/Pull.cs | 13 +-- LibGit2Sharp/LibGit2Sharp.csproj | 1 + LibGit2Sharp/Network.cs | 105 +++--------------- LibGit2Sharp/RepositoryExtensions.cs | 2 + 9 files changed, 153 insertions(+), 128 deletions(-) create mode 100644 LibGit2Sharp/Commands/Fetch.cs diff --git a/LibGit2Sharp.Tests/FetchFixture.cs b/LibGit2Sharp.Tests/FetchFixture.cs index f6465f801..bd74b8ea6 100644 --- a/LibGit2Sharp.Tests/FetchFixture.cs +++ b/LibGit2Sharp.Tests/FetchFixture.cs @@ -22,7 +22,7 @@ public void CanFetchIntoAnEmptyRepository(string url) using (var repo = new Repository(path)) { - Remote remote = repo.Network.Remotes.Add(remoteName, url); + repo.Network.Remotes.Add(remoteName, url); // Set up structures for the expected results // and verifying the RemoteUpdateTips callback. @@ -44,7 +44,7 @@ public void CanFetchIntoAnEmptyRepository(string url) } // Perform the actual fetch - repo.Network.Fetch(remote, new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }); + new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null).Run(); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); @@ -61,13 +61,13 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials() using (var repo = new Repository(path)) { - Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl); + repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl); // Perform the actual fetch - repo.Network.Fetch(remote, new FetchOptions + new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { CredentialsProvider = Constants.PrivateRepoCredentials - }); + }, null).Run(); } } @@ -81,7 +81,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url) using (var repo = new Repository(path)) { - Remote remote = repo.Network.Remotes.Add(remoteName, url); + repo.Network.Remotes.Add(remoteName, url); // Set up structures for the expected results // and verifying the RemoteUpdateTips callback. @@ -101,10 +101,10 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url) } // Perform the actual fetch - repo.Network.Fetch(remote, new FetchOptions { + new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All, OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler - }); + }, null).Run(); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); @@ -124,7 +124,7 @@ public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string local using (var repo = new Repository(path)) { - Remote remote = repo.Network.Remotes.Add(remoteName, url); + repo.Network.Remotes.Add(remoteName, url); string refSpec = string.Format("refs/heads/{2}:refs/remotes/{0}/{1}", remoteName, localBranchName, remoteBranchName); @@ -147,10 +147,10 @@ public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string local } // Perform the actual fetch - repo.Network.Fetch(remote, new string[] { refSpec }, new FetchOptions { + new Commands.Fetch(repo, remoteName, new string[] { refSpec }, new FetchOptions { TagFetchMode = TagFetchMode.None, OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler - }); + }, null).Run(); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); @@ -181,7 +181,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int r => r.TagFetchMode = tagFetchMode); // Perform the actual fetch. - repo.Network.Fetch(remote); + new Commands.Fetch(repo, remoteName, new string[0], null, null).Run(); // Verify the number of fetched tags. Assert.Equal(expectedTagCount, repo.Tags.Count()); @@ -199,7 +199,7 @@ public void CanFetchAllTagsAfterAnInitialClone() using (var repo = new Repository(clonedRepoPath)) { - repo.Fetch("origin", new FetchOptions { TagFetchMode = TagFetchMode.All }); + new Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null).Run(); } } @@ -225,17 +225,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry() // No pruning when the configuration entry isn't defined Assert.Null(clonedRepo.Config.Get("fetch.prune")); - clonedRepo.Fetch("origin"); + new Commands.Fetch(clonedRepo, "origin", new string[0], null, null).Run(); Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote)); // No pruning when the configuration entry is set to false clonedRepo.Config.Set("fetch.prune", false); - clonedRepo.Fetch("origin"); + new Commands.Fetch(clonedRepo, "origin", new string[0], null, null).Run(); Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote)); // Auto pruning when the configuration entry is set to true clonedRepo.Config.Set("fetch.prune", true); - clonedRepo.Fetch("origin"); + new Commands.Fetch(clonedRepo, "origin", new string[0], null, null).Run(); Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote)); } } diff --git a/LibGit2Sharp.Tests/NetworkFixture.cs b/LibGit2Sharp.Tests/NetworkFixture.cs index 1f3a89f70..2ca6bb4dd 100644 --- a/LibGit2Sharp.Tests/NetworkFixture.cs +++ b/LibGit2Sharp.Tests/NetworkFixture.cs @@ -252,10 +252,7 @@ public void CanMergeFetchedRefs() Assert.False(repo.RetrieveStatus().Any()); Assert.Equal(repo.Lookup("refs/remotes/origin/master~1"), repo.Head.Tip); - using (var remote = repo.Network.Remotes[repo.Head.RemoteName]) - { - repo.Network.Fetch(remote); - } + new Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null).Run(); MergeOptions mergeOptions = new MergeOptions() { @@ -282,8 +279,7 @@ public void CanPruneRefs() using (var repo = new Repository(clonedRepoPath)) { repo.Network.Remotes.Add("pruner", clonedRepoPath2); - var remote = repo.Network.Remotes["pruner"]; - repo.Network.Fetch(remote); + new Commands.Fetch(repo, "pruner", new string[0], null, null).Run(); Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]); // Remove the branch from the source repository @@ -293,11 +289,11 @@ public void CanPruneRefs() } // and by default we don't prune it - repo.Network.Fetch(remote); + new Commands.Fetch(repo, "pruner", new string[0], null, null).Run(); Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]); // but we do when asked by the user - repo.Network.Fetch(remote, new FetchOptions { Prune = true} ); + new Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true}, null).Run(); Assert.Null(repo.Refs["refs/remotes/pruner/master"]); } } diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs index 278590180..c331d8047 100644 --- a/LibGit2Sharp.Tests/RepositoryFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryFixture.cs @@ -181,7 +181,7 @@ public void CanFetchFromRemoteByName() using (var repo = new Repository(repoPath)) { - Remote remote = repo.Network.Remotes.Add(remoteName, url); + repo.Network.Remotes.Add(remoteName, url); // We will first fetch without specifying any Tag options. // After we verify this fetch, we will perform a second fetch @@ -208,13 +208,13 @@ public void CanFetchFromRemoteByName() } // Perform the actual fetch - repo.Fetch(remote.Name, new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }); + new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null).Run(); // Verify the expected state expectedFetchState.CheckUpdatedReferences(repo); // Now fetch the rest of the tags - repo.Fetch(remote.Name, new FetchOptions { TagFetchMode = TagFetchMode.All }); + new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null).Run(); // Verify that the "nearly-dangling" tag is now in the repo. Tag nearlyDanglingTag = repo.Tags["nearly-dangling"]; diff --git a/LibGit2Sharp.Tests/SmartSubtransportFixture.cs b/LibGit2Sharp.Tests/SmartSubtransportFixture.cs index f8bf3d90c..b15938b45 100644 --- a/LibGit2Sharp.Tests/SmartSubtransportFixture.cs +++ b/LibGit2Sharp.Tests/SmartSubtransportFixture.cs @@ -41,7 +41,7 @@ public void CustomSmartSubtransportTest(string scheme, string url) using (var repo = new Repository(repoPath)) { - Remote remote = repo.Network.Remotes.Add(remoteName, url); + repo.Network.Remotes.Add(remoteName, url); // Set up structures for the expected results // and verifying the RemoteUpdateTips callback. @@ -63,7 +63,9 @@ public void CustomSmartSubtransportTest(string scheme, string url) } // Perform the actual fetch - repo.Network.Fetch(remote, new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto }); + new Commands.Fetch(repo, remoteName, new string[0], + new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto }, + null).Run(); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); @@ -99,7 +101,7 @@ public void CanUseCredentials(string scheme, string url, string user, string pas using (var repo = new Repository(scd.DirectoryPath)) { - Remote remote = repo.Network.Remotes.Add(remoteName, url); + repo.Network.Remotes.Add(remoteName, url); // Set up structures for the expected results // and verifying the RemoteUpdateTips callback. @@ -113,9 +115,10 @@ public void CanUseCredentials(string scheme, string url, string user, string pas } // Perform the actual fetch - repo.Network.Fetch(remote, new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto, + new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { + OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto, CredentialsProvider = (_user, _valid, _hostname) => new UsernamePasswordCredentials() { Username = "libgit3", Password = "libgit3" }, - }); + }, null).Run(); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); diff --git a/LibGit2Sharp/Commands/Fetch.cs b/LibGit2Sharp/Commands/Fetch.cs new file mode 100644 index 000000000..4d131da56 --- /dev/null +++ b/LibGit2Sharp/Commands/Fetch.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic; +using LibGit2Sharp; +using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp.Commands +{ + /// + /// Fetch from a particular remote or the default + /// + public class Fetch + { + private readonly Repository repository; + private readonly string remote; + private readonly FetchOptions options; + private readonly string logMessage; + private readonly IEnumerable refspecs; + + /// + /// Initializes a new instance of the class. + /// + /// The repository in which to fetch. + /// The remote to fetch from + /// Fetch options. + /// Log message for any ref updates. + /// List of refspecs to apply as active. + public Fetch(Repository repository, string remote, IEnumerable refspecs, FetchOptions options, string logMessage) + { + Ensure.ArgumentNotNull(remote, "remote"); + + this.repository = repository; + this.remote = remote; + this.options = options ?? new FetchOptions(); + this.logMessage = logMessage; + this.refspecs = refspecs; + } + + private RemoteHandle RemoteFromNameOrUrl() + { + RemoteHandle handle = null; + handle = Proxy.git_remote_lookup(repository.Handle, remote, false); + + // If that wasn't the name of a remote, let's use it as a url + if (handle == null) + { + handle = Proxy.git_remote_create_anonymous(repository.Handle, remote); + } + + return handle; + } + + /// + /// Run this command + /// + public void Run() + { + using (var remoteHandle = RemoteFromNameOrUrl()) + { + + var callbacks = new RemoteCallbacks(options); + GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); + + // It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of + // the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation + // to store a reference to the git_remote_callbacks structure this would introduce a subtle bug + // where the managed layer could move the git_remote_callbacks to a different location in memory, + // but libgit2 would still reference the old address. + // + // Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against + // GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords. + var fetchOptions = new GitFetchOptions + { + RemoteCallbacks = gitCallbacks, + download_tags = Proxy.git_remote_autotag(remoteHandle), + }; + + if (options.TagFetchMode.HasValue) + { + fetchOptions.download_tags = options.TagFetchMode.Value; + } + + if (options.Prune.HasValue) + { + fetchOptions.Prune = options.Prune.Value ? FetchPruneStrategy.Prune : FetchPruneStrategy.NoPrune; + } + else + { + fetchOptions.Prune = FetchPruneStrategy.FromConfigurationOrDefault; + } + + Proxy.git_remote_fetch(remoteHandle, refspecs, fetchOptions, logMessage); + } + + } + } +} + diff --git a/LibGit2Sharp/Commands/Pull.cs b/LibGit2Sharp/Commands/Pull.cs index a73a23351..712746d26 100644 --- a/LibGit2Sharp/Commands/Pull.cs +++ b/LibGit2Sharp/Commands/Pull.cs @@ -43,16 +43,13 @@ public MergeResult Run() throw new LibGit2SharpException("There is no tracking information for the current branch."); } - using (var remote = repository.Network.Remotes.RemoteForName(currentBranch.RemoteName)) + if (currentBranch.RemoteName == null) { - if (remote == null) - { - throw new LibGit2SharpException("No upstream remote for the current branch."); - } - - repository.Network.Fetch(remote, options.FetchOptions); - return repository.MergeFetchedRefs(merger, options.MergeOptions); + throw new LibGit2SharpException("No upstream remote for the current branch."); } + + new Commands.Fetch(repository, currentBranch.RemoteName, new string[0], options.FetchOptions, null).Run(); + return repository.MergeFetchedRefs(merger, options.MergeOptions); } } } diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 653626cfd..6606f5fa2 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -351,6 +351,7 @@ + diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index a4c157009..839a8e0e7 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -130,17 +130,6 @@ private IEnumerable ListReferencesInternal(string url, CredentialsHan } } - static RemoteHandle BuildRemoteHandle(RepositoryHandle repoHandle, Remote remote) - { - Debug.Assert(repoHandle != null && !repoHandle.IsNull); - Debug.Assert(remote != null && remote.Name != null); - - RemoteHandle remoteHandle = Proxy.git_remote_lookup(repoHandle, remote.Name, true); - Debug.Assert(remoteHandle != null && !(remoteHandle.IsNull)); - - return remoteHandle; - } - static RemoteHandle BuildRemoteHandle(RepositoryHandle repoHandle, string url) { Debug.Assert(repoHandle != null && !repoHandle.IsNull); @@ -152,79 +141,14 @@ static RemoteHandle BuildRemoteHandle(RepositoryHandle repoHandle, string url) return remoteHandle; } - static void DoFetch( - RepositoryHandle repoHandle, - Remote remote, - FetchOptions options, - string logMessage, - IEnumerable refspecs) - { - using (RemoteHandle remoteHandle = BuildRemoteHandle(repoHandle, remote)) - { - DoFetch(options, remoteHandle, logMessage, refspecs); - } - } - - static void DoFetch( - RepositoryHandle repoHandle, - string url, - FetchOptions options, - string logMessage, - IEnumerable refspecs) - { - using (RemoteHandle remoteHandle = BuildRemoteHandle(repoHandle, url)) - { - DoFetch(options, remoteHandle, logMessage, refspecs); - } - } - - private static void DoFetch(FetchOptions options, RemoteHandle remoteHandle, string logMessage, IEnumerable refspecs) - { - Debug.Assert(remoteHandle != null && !remoteHandle.IsNull); - - options = options ?? new FetchOptions(); - - var callbacks = new RemoteCallbacks(options); - GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); - - // It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of - // the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation - // to store a reference to the git_remote_callbacks structure this would introduce a subtle bug - // where the managed layer could move the git_remote_callbacks to a different location in memory, - // but libgit2 would still reference the old address. - // - // Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against - // GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords. - var fetchOptions = new GitFetchOptions - { - RemoteCallbacks = gitCallbacks, - download_tags = Proxy.git_remote_autotag(remoteHandle), - }; - - if (options.TagFetchMode.HasValue) - { - fetchOptions.download_tags = options.TagFetchMode.Value; - } - - if (options.Prune.HasValue) - { - fetchOptions.Prune = options.Prune.Value ? FetchPruneStrategy.Prune : FetchPruneStrategy.NoPrune; - } - else - { - fetchOptions.Prune = FetchPruneStrategy.FromConfigurationOrDefault; - } - - Proxy.git_remote_fetch(remoteHandle, refspecs, fetchOptions, logMessage); - } - /// /// Fetch from the . /// /// The remote to fetch + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] public virtual void Fetch(Remote remote) { - Fetch(remote, (FetchOptions)null, null); + new Commands.Fetch(repository, remote.Name, new string[0], null, null).Run(); } /// @@ -232,9 +156,10 @@ public virtual void Fetch(Remote remote) /// /// The remote to fetch /// controlling fetch behavior + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] public virtual void Fetch(Remote remote, FetchOptions options) { - Fetch(remote, options, null); + new Commands.Fetch(repository, remote.Name, new string[0], options, null).Run(); } /// @@ -242,9 +167,10 @@ public virtual void Fetch(Remote remote, FetchOptions options) /// /// The remote to fetch /// Message to use when updating the reflog. + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] public virtual void Fetch(Remote remote, string logMessage) { - Fetch(remote, (FetchOptions)null, logMessage); + new Commands.Fetch(repository, remote.Name, new string[0], null, logMessage).Run(); } /// @@ -253,11 +179,10 @@ public virtual void Fetch(Remote remote, string logMessage) /// The remote to fetch /// controlling fetch behavior /// Message to use when updating the reflog. + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] public virtual void Fetch(Remote remote, FetchOptions options, string logMessage) { - Ensure.ArgumentNotNull(remote, "remote"); - - DoFetch(repository.Handle, remote, options, logMessage, new string[0]); + new Commands.Fetch(repository, remote.Name, new string[0], options, logMessage).Run(); } /// @@ -265,9 +190,10 @@ public virtual void Fetch(Remote remote, FetchOptions options, string logMessage /// /// The remote to fetch /// Refspecs to use, replacing the remote's fetch refspecs + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] public virtual void Fetch(Remote remote, IEnumerable refspecs) { - Fetch(remote, refspecs, null, null); + new Commands.Fetch(repository, remote.Name, refspecs, null, null).Run(); } /// @@ -276,9 +202,10 @@ public virtual void Fetch(Remote remote, IEnumerable refspecs) /// The remote to fetch /// Refspecs to use, replacing the remote's fetch refspecs /// controlling fetch behavior + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] public virtual void Fetch(Remote remote, IEnumerable refspecs, FetchOptions options) { - Fetch(remote, refspecs, options, null); + new Commands.Fetch(repository, remote.Name, refspecs, options, null).Run(); } /// @@ -287,9 +214,10 @@ public virtual void Fetch(Remote remote, IEnumerable refspecs, FetchOpti /// The remote to fetch /// Refspecs to use, replacing the remote's fetch refspecs /// Message to use when updating the reflog. + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] public virtual void Fetch(Remote remote, IEnumerable refspecs, string logMessage) { - Fetch(remote, refspecs, null, logMessage); + new Commands.Fetch(repository, remote.Name, refspecs, null, logMessage).Run(); } /// @@ -299,12 +227,13 @@ public virtual void Fetch(Remote remote, IEnumerable refspecs, string lo /// Refspecs to use, replacing the remote's fetch refspecs /// controlling fetch behavior /// Message to use when updating the reflog. + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] public virtual void Fetch(Remote remote, IEnumerable refspecs, FetchOptions options, string logMessage) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(refspecs, "refspecs"); - DoFetch(repository.Handle, remote, options, logMessage, refspecs); + new Commands.Fetch(repository, remote.Name, refspecs, options, logMessage).Run(); } /// @@ -355,7 +284,7 @@ public virtual void Fetch( Ensure.ArgumentNotNull(url, "url"); Ensure.ArgumentNotNull(refspecs, "refspecs"); - DoFetch(repository.Handle, url, options, logMessage, refspecs); + new Commands.Fetch(repository, url, refspecs, options, logMessage).Run(); } /// diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs index 5f162325b..643dfb94a 100644 --- a/LibGit2Sharp/RepositoryExtensions.cs +++ b/LibGit2Sharp/RepositoryExtensions.cs @@ -205,6 +205,7 @@ public static Commit Commit(this IRepository repository, string message, Signatu /// /// The being worked with. /// The name of the to fetch from. + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Fetch class")] public static void Fetch(this IRepository repository, string remoteName) { repository.Fetch(remoteName, null); @@ -216,6 +217,7 @@ public static void Fetch(this IRepository repository, string remoteName) /// The being worked with. /// The name of the to fetch from. /// controlling fetch behavior + [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Fetch class")] public static void Fetch(this IRepository repository, string remoteName, FetchOptions options) { Ensure.ArgumentNotNull(repository, "repository"); From 6f0230d85380d05011571b994dfbdbb75a0794c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 23 Mar 2016 12:17:11 +0100 Subject: [PATCH 3/3] Move Fetch and Pull to be static methods Since we make no use of these commands being classes. Make them static methods of a static class to give them some namespacing. --- LibGit2Sharp.Tests/FetchFixture.cs | 24 ++++----- LibGit2Sharp.Tests/NetworkFixture.cs | 14 ++--- LibGit2Sharp.Tests/RepositoryFixture.cs | 4 +- .../SmartSubtransportFixture.cs | 8 +-- LibGit2Sharp/Commands/Fetch.cs | 51 +++++++------------ LibGit2Sharp/Commands/Pull.cs | 25 +++------ LibGit2Sharp/Network.cs | 38 +++++++------- 7 files changed, 67 insertions(+), 97 deletions(-) diff --git a/LibGit2Sharp.Tests/FetchFixture.cs b/LibGit2Sharp.Tests/FetchFixture.cs index bd74b8ea6..99ca5bd50 100644 --- a/LibGit2Sharp.Tests/FetchFixture.cs +++ b/LibGit2Sharp.Tests/FetchFixture.cs @@ -44,7 +44,7 @@ public void CanFetchIntoAnEmptyRepository(string url) } // Perform the actual fetch - new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null).Run(); + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); @@ -64,10 +64,10 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials() repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl); // Perform the actual fetch - new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { CredentialsProvider = Constants.PrivateRepoCredentials - }, null).Run(); + }, null); } } @@ -101,10 +101,10 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url) } // Perform the actual fetch - new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All, OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler - }, null).Run(); + }, null); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); @@ -147,10 +147,10 @@ public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string local } // Perform the actual fetch - new Commands.Fetch(repo, remoteName, new string[] { refSpec }, new FetchOptions { + Commands.Fetch(repo, remoteName, new string[] { refSpec }, new FetchOptions { TagFetchMode = TagFetchMode.None, OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler - }, null).Run(); + }, null); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); @@ -181,7 +181,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int r => r.TagFetchMode = tagFetchMode); // Perform the actual fetch. - new Commands.Fetch(repo, remoteName, new string[0], null, null).Run(); + Commands.Fetch(repo, remoteName, new string[0], null, null); // Verify the number of fetched tags. Assert.Equal(expectedTagCount, repo.Tags.Count()); @@ -199,7 +199,7 @@ public void CanFetchAllTagsAfterAnInitialClone() using (var repo = new Repository(clonedRepoPath)) { - new Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null).Run(); + Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null); } } @@ -225,17 +225,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry() // No pruning when the configuration entry isn't defined Assert.Null(clonedRepo.Config.Get("fetch.prune")); - new Commands.Fetch(clonedRepo, "origin", new string[0], null, null).Run(); + Commands.Fetch(clonedRepo, "origin", new string[0], null, null); Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote)); // No pruning when the configuration entry is set to false clonedRepo.Config.Set("fetch.prune", false); - new Commands.Fetch(clonedRepo, "origin", new string[0], null, null).Run(); + Commands.Fetch(clonedRepo, "origin", new string[0], null, null); Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote)); // Auto pruning when the configuration entry is set to true clonedRepo.Config.Set("fetch.prune", true); - new Commands.Fetch(clonedRepo, "origin", new string[0], null, null).Run(); + Commands.Fetch(clonedRepo, "origin", new string[0], null, null); Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote)); } } diff --git a/LibGit2Sharp.Tests/NetworkFixture.cs b/LibGit2Sharp.Tests/NetworkFixture.cs index 2ca6bb4dd..9153ffeb0 100644 --- a/LibGit2Sharp.Tests/NetworkFixture.cs +++ b/LibGit2Sharp.Tests/NetworkFixture.cs @@ -164,7 +164,7 @@ public void CanPull(FastForwardStrategy fastForwardStrategy) } }; - MergeResult mergeResult = new Commands.Pull(repo, Constants.Signature, pullOptions).Run(); + MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, pullOptions); if(fastForwardStrategy == FastForwardStrategy.Default || fastForwardStrategy == FastForwardStrategy.FastForwardOnly) { @@ -197,7 +197,7 @@ public void CanPullIntoEmptyRepo() b => b.UpstreamBranch = "refs/heads/master"); // Pull! - MergeResult mergeResult = new Commands.Pull(repo, Constants.Signature, new PullOptions()).Run(); + MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, new PullOptions()); Assert.Equal(mergeResult.Status, MergeStatus.FastForward); Assert.Equal(mergeResult.Commit, repo.Branches["refs/remotes/origin/master"].Tip); @@ -224,7 +224,7 @@ public void PullWithoutMergeBranchThrows() try { - new Commands.Pull(repo, Constants.Signature, new PullOptions()).Run(); + Commands.Pull(repo, Constants.Signature, new PullOptions()); } catch(MergeFetchHeadNotFoundException ex) { @@ -252,7 +252,7 @@ public void CanMergeFetchedRefs() Assert.False(repo.RetrieveStatus().Any()); Assert.Equal(repo.Lookup("refs/remotes/origin/master~1"), repo.Head.Tip); - new Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null).Run(); + Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null); MergeOptions mergeOptions = new MergeOptions() { @@ -279,7 +279,7 @@ public void CanPruneRefs() using (var repo = new Repository(clonedRepoPath)) { repo.Network.Remotes.Add("pruner", clonedRepoPath2); - new Commands.Fetch(repo, "pruner", new string[0], null, null).Run(); + Commands.Fetch(repo, "pruner", new string[0], null, null); Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]); // Remove the branch from the source repository @@ -289,11 +289,11 @@ public void CanPruneRefs() } // and by default we don't prune it - new Commands.Fetch(repo, "pruner", new string[0], null, null).Run(); + Commands.Fetch(repo, "pruner", new string[0], null, null); Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]); // but we do when asked by the user - new Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true}, null).Run(); + Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true}, null); Assert.Null(repo.Refs["refs/remotes/pruner/master"]); } } diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs index c331d8047..47fd359fa 100644 --- a/LibGit2Sharp.Tests/RepositoryFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryFixture.cs @@ -208,13 +208,13 @@ public void CanFetchFromRemoteByName() } // Perform the actual fetch - new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null).Run(); + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null); // Verify the expected state expectedFetchState.CheckUpdatedReferences(repo); // Now fetch the rest of the tags - new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null).Run(); + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null); // Verify that the "nearly-dangling" tag is now in the repo. Tag nearlyDanglingTag = repo.Tags["nearly-dangling"]; diff --git a/LibGit2Sharp.Tests/SmartSubtransportFixture.cs b/LibGit2Sharp.Tests/SmartSubtransportFixture.cs index b15938b45..d55785baa 100644 --- a/LibGit2Sharp.Tests/SmartSubtransportFixture.cs +++ b/LibGit2Sharp.Tests/SmartSubtransportFixture.cs @@ -63,9 +63,9 @@ public void CustomSmartSubtransportTest(string scheme, string url) } // Perform the actual fetch - new Commands.Fetch(repo, remoteName, new string[0], + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto }, - null).Run(); + null); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); @@ -115,10 +115,10 @@ public void CanUseCredentials(string scheme, string url, string user, string pas } // Perform the actual fetch - new Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto, CredentialsProvider = (_user, _valid, _hostname) => new UsernamePasswordCredentials() { Username = "libgit3", Password = "libgit3" }, - }, null).Run(); + }, null); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); diff --git a/LibGit2Sharp/Commands/Fetch.cs b/LibGit2Sharp/Commands/Fetch.cs index 4d131da56..a42b4e47c 100644 --- a/LibGit2Sharp/Commands/Fetch.cs +++ b/LibGit2Sharp/Commands/Fetch.cs @@ -3,58 +3,41 @@ using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; -namespace LibGit2Sharp.Commands +namespace LibGit2Sharp { /// - /// Fetch from a particular remote or the default + /// Class to serve as namespacing for the command-emulating methods /// - public class Fetch + public static partial class Commands { - private readonly Repository repository; - private readonly string remote; - private readonly FetchOptions options; - private readonly string logMessage; - private readonly IEnumerable refspecs; - - /// - /// Initializes a new instance of the class. - /// - /// The repository in which to fetch. - /// The remote to fetch from - /// Fetch options. - /// Log message for any ref updates. - /// List of refspecs to apply as active. - public Fetch(Repository repository, string remote, IEnumerable refspecs, FetchOptions options, string logMessage) - { - Ensure.ArgumentNotNull(remote, "remote"); - - this.repository = repository; - this.remote = remote; - this.options = options ?? new FetchOptions(); - this.logMessage = logMessage; - this.refspecs = refspecs; - } - - private RemoteHandle RemoteFromNameOrUrl() + private static RemoteHandle RemoteFromNameOrUrl(RepositoryHandle repoHandle, string remote) { RemoteHandle handle = null; - handle = Proxy.git_remote_lookup(repository.Handle, remote, false); + handle = Proxy.git_remote_lookup(repoHandle, remote, false); // If that wasn't the name of a remote, let's use it as a url if (handle == null) { - handle = Proxy.git_remote_create_anonymous(repository.Handle, remote); + handle = Proxy.git_remote_create_anonymous(repoHandle, remote); } return handle; } /// - /// Run this command + /// Perform a fetch /// - public void Run() + /// The repository in which to fetch. + /// The remote to fetch from. Either as a remote name or a URL + /// Fetch options. + /// Log message for any ref updates. + /// List of refspecs to apply as active. + public static void Fetch(Repository repository, string remote, IEnumerable refspecs, FetchOptions options, string logMessage) { - using (var remoteHandle = RemoteFromNameOrUrl()) + Ensure.ArgumentNotNull(remote, "remote"); + + options = options ?? new FetchOptions(); + using (var remoteHandle = RemoteFromNameOrUrl(repository.Handle, remote)) { var callbacks = new RemoteCallbacks(options); diff --git a/LibGit2Sharp/Commands/Pull.cs b/LibGit2Sharp/Commands/Pull.cs index 712746d26..d42c1951c 100644 --- a/LibGit2Sharp/Commands/Pull.cs +++ b/LibGit2Sharp/Commands/Pull.cs @@ -2,40 +2,27 @@ using LibGit2Sharp; using LibGit2Sharp.Core; -namespace LibGit2Sharp.Commands +namespace LibGit2Sharp { /// /// Fetch changes from the configured upstream remote and branch into the branch pointed at by HEAD. /// - public class Pull + public static partial class Commands { - private readonly Repository repository; - private readonly Signature merger; - private readonly PullOptions options; - /// - /// Initializes a new instance of the class. + /// Fetch changes from the configured upstream remote and branch into the branch pointed at by HEAD. /// /// The repository. /// The signature to use for the merge. /// The options for fetch and merging. - public Pull(Repository repository, Signature merger, PullOptions options) + public static MergeResult Pull(Repository repository, Signature merger, PullOptions options) { Ensure.ArgumentNotNull(repository, "repository"); Ensure.ArgumentNotNull(merger, "merger"); Ensure.ArgumentNotNull(options, "options"); - this.repository = repository; - this.merger = merger; - this.options = options; - } - - /// - /// Run this command - /// - public MergeResult Run() - { + options = options ?? new PullOptions(); Branch currentBranch = repository.Head; if (!currentBranch.IsTracking) @@ -48,7 +35,7 @@ public MergeResult Run() throw new LibGit2SharpException("No upstream remote for the current branch."); } - new Commands.Fetch(repository, currentBranch.RemoteName, new string[0], options.FetchOptions, null).Run(); + Commands.Fetch(repository, currentBranch.RemoteName, new string[0], options.FetchOptions, null); return repository.MergeFetchedRefs(merger, options.MergeOptions); } } diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index 839a8e0e7..1841184ec 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -145,10 +145,10 @@ static RemoteHandle BuildRemoteHandle(RepositoryHandle repoHandle, string url) /// Fetch from the . /// /// The remote to fetch - [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please us LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote) { - new Commands.Fetch(repository, remote.Name, new string[0], null, null).Run(); + Commands.Fetch(repository, remote.Name, new string[0], null, null); } /// @@ -156,10 +156,10 @@ public virtual void Fetch(Remote remote) /// /// The remote to fetch /// controlling fetch behavior - [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please use LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, FetchOptions options) { - new Commands.Fetch(repository, remote.Name, new string[0], options, null).Run(); + Commands.Fetch(repository, remote.Name, new string[0], options, null); } /// @@ -167,10 +167,10 @@ public virtual void Fetch(Remote remote, FetchOptions options) /// /// The remote to fetch /// Message to use when updating the reflog. - [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please use the LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, string logMessage) { - new Commands.Fetch(repository, remote.Name, new string[0], null, logMessage).Run(); + Commands.Fetch(repository, remote.Name, new string[0], null, logMessage); } /// @@ -179,10 +179,10 @@ public virtual void Fetch(Remote remote, string logMessage) /// The remote to fetch /// controlling fetch behavior /// Message to use when updating the reflog. - [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please use LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, FetchOptions options, string logMessage) { - new Commands.Fetch(repository, remote.Name, new string[0], options, logMessage).Run(); + Commands.Fetch(repository, remote.Name, new string[0], options, logMessage); } /// @@ -190,10 +190,10 @@ public virtual void Fetch(Remote remote, FetchOptions options, string logMessage /// /// The remote to fetch /// Refspecs to use, replacing the remote's fetch refspecs - [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please use LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, IEnumerable refspecs) { - new Commands.Fetch(repository, remote.Name, refspecs, null, null).Run(); + Commands.Fetch(repository, remote.Name, refspecs, null, null); } /// @@ -202,10 +202,10 @@ public virtual void Fetch(Remote remote, IEnumerable refspecs) /// The remote to fetch /// Refspecs to use, replacing the remote's fetch refspecs /// controlling fetch behavior - [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please use LibGit2Sharp.Commands.Fetch")] public virtual void Fetch(Remote remote, IEnumerable refspecs, FetchOptions options) { - new Commands.Fetch(repository, remote.Name, refspecs, options, null).Run(); + Commands.Fetch(repository, remote.Name, refspecs, options, null); } /// @@ -214,10 +214,10 @@ public virtual void Fetch(Remote remote, IEnumerable refspecs, FetchOpti /// The remote to fetch /// Refspecs to use, replacing the remote's fetch refspecs /// Message to use when updating the reflog. - [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please use LibGit2Sharp.Commands.Fetch")] public virtual void Fetch(Remote remote, IEnumerable refspecs, string logMessage) { - new Commands.Fetch(repository, remote.Name, refspecs, null, logMessage).Run(); + Commands.Fetch(repository, remote.Name, refspecs, null, logMessage); } /// @@ -227,13 +227,13 @@ public virtual void Fetch(Remote remote, IEnumerable refspecs, string lo /// Refspecs to use, replacing the remote's fetch refspecs /// controlling fetch behavior /// Message to use when updating the reflog. - [Obsolete("This method is deprecated. Please us the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please use LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, IEnumerable refspecs, FetchOptions options, string logMessage) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(refspecs, "refspecs"); - new Commands.Fetch(repository, remote.Name, refspecs, options, logMessage).Run(); + Commands.Fetch(repository, remote.Name, refspecs, options, logMessage); } /// @@ -284,7 +284,7 @@ public virtual void Fetch( Ensure.ArgumentNotNull(url, "url"); Ensure.ArgumentNotNull(refspecs, "refspecs"); - new Commands.Fetch(repository, url, refspecs, options, logMessage).Run(); + Commands.Fetch(repository, url, refspecs, options, logMessage); } /// @@ -478,10 +478,10 @@ public virtual void Push(Remote remote, IEnumerable pushRefSpecs, PushOp /// /// If the merge is a non-fast forward merge that generates a merge commit, the of who made the merge. /// Specifies optional parameters controlling merge behavior of pull; if null, the defaults are used. - [Obsolete("This method is deprecated. Please use the LibGit2Sharp.Commands.Pull class")] + [Obsolete("This method is deprecated. Please use LibGit2Sharp.Commands.Pull()")] public virtual MergeResult Pull(Signature merger, PullOptions options) { - return new Commands.Pull(repository, merger, options).Run(); + return Commands.Pull(repository, merger, options); } ///