diff --git a/LibGit2Sharp.Tests/FetchFixture.cs b/LibGit2Sharp.Tests/FetchFixture.cs index f6465f801..99ca5bd50 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 }); + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null); // 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 + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { CredentialsProvider = Constants.PrivateRepoCredentials - }); + }, null); } } @@ -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 { + Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All, OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler - }); + }, null); // 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 { + Commands.Fetch(repo, remoteName, new string[] { refSpec }, new FetchOptions { TagFetchMode = TagFetchMode.None, OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler - }); + }, 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. - repo.Network.Fetch(remote); + 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)) { - repo.Fetch("origin", new FetchOptions { TagFetchMode = TagFetchMode.All }); + 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")); - clonedRepo.Fetch("origin"); + 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); - clonedRepo.Fetch("origin"); + 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); - clonedRepo.Fetch("origin"); + 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 fe5a2b04f..9153ffeb0 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 = 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 = repo.Network.Pull(Constants.Signature, new PullOptions()); + 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 { - repo.Network.Pull(Constants.Signature, new PullOptions()); + Commands.Pull(repo, Constants.Signature, new PullOptions()); } catch(MergeFetchHeadNotFoundException ex) { @@ -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); - } + Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null); 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); + Commands.Fetch(repo, "pruner", new string[0], null, null); 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); + 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 - repo.Network.Fetch(remote, new FetchOptions { Prune = true} ); + 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 278590180..47fd359fa 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 }); + 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 - repo.Fetch(remote.Name, new FetchOptions { TagFetchMode = TagFetchMode.All }); + 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 f8bf3d90c..d55785baa 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 }); + Commands.Fetch(repo, remoteName, new string[0], + new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto }, + null); // 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, + 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); // Verify the expected expectedFetchState.CheckUpdatedReferences(repo); diff --git a/LibGit2Sharp/Commands/Fetch.cs b/LibGit2Sharp/Commands/Fetch.cs new file mode 100644 index 000000000..a42b4e47c --- /dev/null +++ b/LibGit2Sharp/Commands/Fetch.cs @@ -0,0 +1,80 @@ +using System.Collections.Generic; +using LibGit2Sharp; +using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp +{ + /// + /// Class to serve as namespacing for the command-emulating methods + /// + public static partial class Commands + { + private static RemoteHandle RemoteFromNameOrUrl(RepositoryHandle repoHandle, string remote) + { + RemoteHandle handle = null; + 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(repoHandle, remote); + } + + return handle; + } + + /// + /// Perform a fetch + /// + /// 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) + { + Ensure.ArgumentNotNull(remote, "remote"); + + options = options ?? new FetchOptions(); + using (var remoteHandle = RemoteFromNameOrUrl(repository.Handle, remote)) + { + + 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 new file mode 100644 index 000000000..d42c1951c --- /dev/null +++ b/LibGit2Sharp/Commands/Pull.cs @@ -0,0 +1,43 @@ +using System; +using LibGit2Sharp; +using LibGit2Sharp.Core; + +namespace LibGit2Sharp +{ + /// + /// Fetch changes from the configured upstream remote and branch into the branch pointed at by HEAD. + /// + public static partial class Commands + { + /// + /// 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 static MergeResult Pull(Repository repository, Signature merger, PullOptions options) + { + Ensure.ArgumentNotNull(repository, "repository"); + Ensure.ArgumentNotNull(merger, "merger"); + Ensure.ArgumentNotNull(options, "options"); + + + options = options ?? new PullOptions(); + Branch currentBranch = repository.Head; + + if (!currentBranch.IsTracking) + { + throw new LibGit2SharpException("There is no tracking information for the current branch."); + } + + if (currentBranch.RemoteName == null) + { + throw new LibGit2SharpException("No upstream remote for the current branch."); + } + + Commands.Fetch(repository, currentBranch.RemoteName, new string[0], options.FetchOptions, null); + return repository.MergeFetchedRefs(merger, options.MergeOptions); + } + } +} + diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 0851a5041..6606f5fa2 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -350,6 +350,8 @@ + + @@ -386,4 +388,7 @@ --> + + + \ No newline at end of file diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index be4bd27ba..1841184ec 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 LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote) { - Fetch(remote, (FetchOptions)null, null); + Commands.Fetch(repository, remote.Name, new string[0], null, null); } /// @@ -232,9 +156,10 @@ public virtual void Fetch(Remote remote) /// /// The remote to fetch /// controlling fetch behavior + [Obsolete("This method is deprecated. Please use LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, FetchOptions options) { - Fetch(remote, options, null); + Commands.Fetch(repository, remote.Name, new string[0], options, null); } /// @@ -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 use the LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, string logMessage) { - Fetch(remote, (FetchOptions)null, logMessage); + Commands.Fetch(repository, remote.Name, new string[0], null, logMessage); } /// @@ -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 use LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, FetchOptions options, string logMessage) { - Ensure.ArgumentNotNull(remote, "remote"); - - DoFetch(repository.Handle, remote, options, logMessage, new string[0]); + Commands.Fetch(repository, remote.Name, new string[0], options, logMessage); } /// @@ -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 use LibGit2Sharp.Commands.Fetch()")] public virtual void Fetch(Remote remote, IEnumerable refspecs) { - Fetch(remote, refspecs, null, null); + Commands.Fetch(repository, remote.Name, refspecs, null, null); } /// @@ -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 use LibGit2Sharp.Commands.Fetch")] public virtual void Fetch(Remote remote, IEnumerable refspecs, FetchOptions options) { - Fetch(remote, refspecs, options, null); + Commands.Fetch(repository, remote.Name, refspecs, options, null); } /// @@ -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 use LibGit2Sharp.Commands.Fetch")] public virtual void Fetch(Remote remote, IEnumerable refspecs, string logMessage) { - Fetch(remote, refspecs, null, logMessage); + Commands.Fetch(repository, remote.Name, refspecs, null, logMessage); } /// @@ -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 use LibGit2Sharp.Commands.Fetch()")] 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); + Commands.Fetch(repository, remote.Name, refspecs, options, logMessage); } /// @@ -355,7 +284,7 @@ public virtual void Fetch( Ensure.ArgumentNotNull(url, "url"); Ensure.ArgumentNotNull(refspecs, "refspecs"); - DoFetch(repository.Handle, url, options, logMessage, refspecs); + Commands.Fetch(repository, url, refspecs, options, logMessage); } /// @@ -549,29 +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 LibGit2Sharp.Commands.Pull()")] 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 Commands.Pull(repository, merger, options); } /// 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");