Skip to content

Fix Branch.Remote deprecations #1289

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

Merged
merged 1 commit into from
Mar 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -464,7 +464,7 @@ public void QueryUnresolvableRemoteForRemoteBranch()
Assert.NotNull(branch);
Assert.True(branch.IsRemote);

Assert.Null(branch.Remote);
Assert.Null(branch.RemoteName);
}
}

Expand All @@ -486,7 +486,7 @@ public void QueryAmbigousRemoteForRemoteBranch()
Assert.NotNull(branch);
Assert.True(branch.IsRemote);

Assert.Null(branch.Remote);
Assert.Null(branch.RemoteName);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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<string> remoteConfigEntry = repo.Config.Get<string>("branch", testBranchName, "remote");
Assert.NotNull(remoteConfigEntry);
Assert.Equal(".", remoteConfigEntry.Value);
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion LibGit2Sharp.Tests/NetworkFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ public void CanMergeFetchedRefs()
Assert.False(repo.RetrieveStatus().Any());
Assert.Equal(repo.Lookup<Commit>("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()
{
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
5 changes: 4 additions & 1 deletion LibGit2Sharp/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 13 additions & 6 deletions LibGit2Sharp/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}

/// <summary>
Expand Down