From 3c32e9665be1f5b88663c243de58afc85b4a3f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 22 Mar 2016 18:26:13 +0100 Subject: [PATCH] Fix Branch.Remote deprecations --- LibGit2Sharp.Tests/BranchFixture.cs | 25 ++++++++++++------------- LibGit2Sharp.Tests/NetworkFixture.cs | 5 ++++- LibGit2Sharp.Tests/RepositoryFixture.cs | 2 +- LibGit2Sharp/Branch.cs | 5 ++++- LibGit2Sharp/Network.cs | 19 +++++++++++++------ 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index be82049ea..99eea1b29 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -394,7 +394,7 @@ public void CanResolveRemote() using (var repo = new Repository(path)) { Branch master = repo.Branches["master"]; - Assert.Equal(repo.Network.Remotes["origin"], master.Remote); + Assert.Equal("origin", master.RemoteName); } } @@ -405,7 +405,7 @@ public void RemoteAndUpstreamBranchCanonicalNameForNonTrackingBranchIsNull() using (var repo = new Repository(path)) { Branch test = repo.Branches["i-do-numbers"]; - Assert.Null(test.Remote); + Assert.Null(test.RemoteName); Assert.Null(test.UpstreamBranchCanonicalName); } } @@ -418,7 +418,7 @@ public void QueryRemoteForLocalTrackingBranch() using (var repo = new Repository(path)) { Branch trackLocal = repo.Branches["track-local"]; - Assert.Null(trackLocal.Remote); + Assert.Null(trackLocal.RemoteName); } } @@ -440,7 +440,7 @@ public void QueryRemoteForRemoteBranch() using (var repo = new Repository(path)) { var master = repo.Branches["origin/master"]; - Assert.Equal(repo.Network.Remotes["origin"], master.Remote); + Assert.Equal("origin", master.RemoteName); } } @@ -464,7 +464,7 @@ public void QueryUnresolvableRemoteForRemoteBranch() Assert.NotNull(branch); Assert.True(branch.IsRemote); - Assert.Null(branch.Remote); + Assert.Null(branch.RemoteName); } } @@ -486,7 +486,7 @@ public void QueryAmbigousRemoteForRemoteBranch() Assert.NotNull(branch); Assert.True(branch.IsRemote); - Assert.Null(branch.Remote); + Assert.Null(branch.RemoteName); } } @@ -732,7 +732,7 @@ public void CanSetTrackedBranch() Assert.True(branch.IsTracking); Assert.Equal(trackedBranch, branch.TrackedBranch); - Assert.Equal(upstreamRemote, branch.Remote); + Assert.Equal("origin", branch.RemoteName); } } @@ -793,7 +793,7 @@ public void CanSetUpstreamBranch() Assert.True(updatedBranch.IsTracking); Assert.Equal(trackedBranch, updatedBranch.TrackedBranch); Assert.Equal(upstreamBranchName, updatedBranch.UpstreamBranchCanonicalName); - Assert.Equal(upstreamRemote, updatedBranch.Remote); + Assert.Equal(remoteName, updatedBranch.RemoteName); } } @@ -820,7 +820,7 @@ public void CanSetLocalTrackedBranch() // Branches that track the local remote do not have the "Remote" property set. // Verify (through the configuration entry) that the local remote is set as expected. - Assert.Null(branch.Remote); + Assert.Null(branch.RemoteName); ConfigurationEntry remoteConfigEntry = repo.Config.Get("branch", testBranchName, "remote"); Assert.NotNull(remoteConfigEntry); Assert.Equal(".", remoteConfigEntry.Value); @@ -861,7 +861,7 @@ public void CanUnsetTrackedBranch() // Verify this is no longer a tracking branch Assert.False(branch.IsTracking); - Assert.Null(branch.Remote); + Assert.Null(branch.RemoteName); Assert.Null(branch.UpstreamBranchCanonicalName); } } @@ -1134,8 +1134,7 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone() Assert.Null(repo.Head.TrackingDetails.BehindBy); Assert.Null(repo.Head.TrackingDetails.CommonAncestor); - Assert.NotNull(repo.Head.Remote); - Assert.Equal("origin", repo.Head.Remote.Name); + Assert.Equal("origin", repo.Head.RemoteName); Touch(repo.Info.WorkingDirectory, "a.txt", "a"); repo.Stage("a.txt"); @@ -1163,7 +1162,7 @@ public void RemoteBranchesDoNotTrackAnything() foreach (var branch in branches) { Assert.True(branch.IsRemote); - Assert.NotNull(branch.Remote); + Assert.NotNull(branch.RemoteName); Assert.False(branch.IsTracking); Assert.Null(branch.TrackedBranch); diff --git a/LibGit2Sharp.Tests/NetworkFixture.cs b/LibGit2Sharp.Tests/NetworkFixture.cs index dd5350b56..fe5a2b04f 100644 --- a/LibGit2Sharp.Tests/NetworkFixture.cs +++ b/LibGit2Sharp.Tests/NetworkFixture.cs @@ -252,7 +252,10 @@ public void CanMergeFetchedRefs() Assert.False(repo.RetrieveStatus().Any()); Assert.Equal(repo.Lookup("refs/remotes/origin/master~1"), repo.Head.Tip); - repo.Network.Fetch(repo.Head.Remote); + using (var remote = repo.Network.Remotes[repo.Head.RemoteName]) + { + repo.Network.Fetch(remote); + } MergeOptions mergeOptions = new MergeOptions() { diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs index 509ff7bac..278590180 100644 --- a/LibGit2Sharp.Tests/RepositoryFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryFixture.cs @@ -612,7 +612,7 @@ public void QueryingTheRemoteForADetachedHeadBranchReturnsNull() { repo.Checkout(repo.Head.Tip.Sha, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force }); Branch trackLocal = repo.Head; - Assert.Null(trackLocal.Remote); + Assert.Null(trackLocal.RemoteName); } } diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs index dd2d4fa6c..beb51f4d0 100644 --- a/LibGit2Sharp/Branch.cs +++ b/LibGit2Sharp/Branch.cs @@ -146,7 +146,10 @@ public virtual string UpstreamBranchCanonicalName { if (IsRemote) { - return Remote.FetchSpecTransformToSource(CanonicalName); + using (var remote = repo.Network.Remotes.RemoteForName(RemoteName)) + { + return remote.FetchSpecTransformToSource(CanonicalName); + } } return UpstreamBranchCanonicalNameFromLocalBranch(); diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index f014b7d61..be4bd27ba 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -415,9 +415,12 @@ public virtual void Push( foreach (var branch in enumeratedBranches) { - Push(branch.Remote, string.Format( - CultureInfo.InvariantCulture, - "{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), pushOptions); + using (var remote = repository.Network.Remotes.RemoteForName(branch.RemoteName)) + { + Push(remote, string.Format( + CultureInfo.InvariantCulture, + "{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), pushOptions); + } } } @@ -558,13 +561,17 @@ public virtual MergeResult Pull(Signature merger, PullOptions options) throw new LibGit2SharpException("There is no tracking information for the current branch."); } - if (currentBranch.Remote == null) + string remoteName = currentBranch.RemoteName; + if (remoteName == null) { throw new LibGit2SharpException("No upstream remote for the current branch."); } - Fetch(currentBranch.Remote, options.FetchOptions); - return repository.MergeFetchedRefs(merger, options.MergeOptions); + using (var remote = repository.Network.Remotes.RemoteForName(remoteName)) + { + Fetch(remote, options.FetchOptions); + return repository.MergeFetchedRefs(merger, options.MergeOptions); + } } ///