Skip to content

Commit 2994bcf

Browse files
committed
Merge pull request libgit2#1289 from libgit2/cmn/deprecated-remote
Fix Branch.Remote deprecations
2 parents 1f5b128 + 3c32e96 commit 2994bcf

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public void CanResolveRemote()
394394
using (var repo = new Repository(path))
395395
{
396396
Branch master = repo.Branches["master"];
397-
Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
397+
Assert.Equal("origin", master.RemoteName);
398398
}
399399
}
400400

@@ -405,7 +405,7 @@ public void RemoteAndUpstreamBranchCanonicalNameForNonTrackingBranchIsNull()
405405
using (var repo = new Repository(path))
406406
{
407407
Branch test = repo.Branches["i-do-numbers"];
408-
Assert.Null(test.Remote);
408+
Assert.Null(test.RemoteName);
409409
Assert.Null(test.UpstreamBranchCanonicalName);
410410
}
411411
}
@@ -418,7 +418,7 @@ public void QueryRemoteForLocalTrackingBranch()
418418
using (var repo = new Repository(path))
419419
{
420420
Branch trackLocal = repo.Branches["track-local"];
421-
Assert.Null(trackLocal.Remote);
421+
Assert.Null(trackLocal.RemoteName);
422422
}
423423
}
424424

@@ -440,7 +440,7 @@ public void QueryRemoteForRemoteBranch()
440440
using (var repo = new Repository(path))
441441
{
442442
var master = repo.Branches["origin/master"];
443-
Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
443+
Assert.Equal("origin", master.RemoteName);
444444
}
445445
}
446446

@@ -464,7 +464,7 @@ public void QueryUnresolvableRemoteForRemoteBranch()
464464
Assert.NotNull(branch);
465465
Assert.True(branch.IsRemote);
466466

467-
Assert.Null(branch.Remote);
467+
Assert.Null(branch.RemoteName);
468468
}
469469
}
470470

@@ -486,7 +486,7 @@ public void QueryAmbigousRemoteForRemoteBranch()
486486
Assert.NotNull(branch);
487487
Assert.True(branch.IsRemote);
488488

489-
Assert.Null(branch.Remote);
489+
Assert.Null(branch.RemoteName);
490490
}
491491
}
492492

@@ -732,7 +732,7 @@ public void CanSetTrackedBranch()
732732

733733
Assert.True(branch.IsTracking);
734734
Assert.Equal(trackedBranch, branch.TrackedBranch);
735-
Assert.Equal(upstreamRemote, branch.Remote);
735+
Assert.Equal("origin", branch.RemoteName);
736736
}
737737
}
738738

@@ -793,7 +793,7 @@ public void CanSetUpstreamBranch()
793793
Assert.True(updatedBranch.IsTracking);
794794
Assert.Equal(trackedBranch, updatedBranch.TrackedBranch);
795795
Assert.Equal(upstreamBranchName, updatedBranch.UpstreamBranchCanonicalName);
796-
Assert.Equal(upstreamRemote, updatedBranch.Remote);
796+
Assert.Equal(remoteName, updatedBranch.RemoteName);
797797
}
798798
}
799799

@@ -820,7 +820,7 @@ public void CanSetLocalTrackedBranch()
820820

821821
// Branches that track the local remote do not have the "Remote" property set.
822822
// Verify (through the configuration entry) that the local remote is set as expected.
823-
Assert.Null(branch.Remote);
823+
Assert.Null(branch.RemoteName);
824824
ConfigurationEntry<string> remoteConfigEntry = repo.Config.Get<string>("branch", testBranchName, "remote");
825825
Assert.NotNull(remoteConfigEntry);
826826
Assert.Equal(".", remoteConfigEntry.Value);
@@ -861,7 +861,7 @@ public void CanUnsetTrackedBranch()
861861

862862
// Verify this is no longer a tracking branch
863863
Assert.False(branch.IsTracking);
864-
Assert.Null(branch.Remote);
864+
Assert.Null(branch.RemoteName);
865865
Assert.Null(branch.UpstreamBranchCanonicalName);
866866
}
867867
}
@@ -1134,8 +1134,7 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone()
11341134
Assert.Null(repo.Head.TrackingDetails.BehindBy);
11351135
Assert.Null(repo.Head.TrackingDetails.CommonAncestor);
11361136

1137-
Assert.NotNull(repo.Head.Remote);
1138-
Assert.Equal("origin", repo.Head.Remote.Name);
1137+
Assert.Equal("origin", repo.Head.RemoteName);
11391138

11401139
Touch(repo.Info.WorkingDirectory, "a.txt", "a");
11411140
repo.Stage("a.txt");
@@ -1163,7 +1162,7 @@ public void RemoteBranchesDoNotTrackAnything()
11631162
foreach (var branch in branches)
11641163
{
11651164
Assert.True(branch.IsRemote);
1166-
Assert.NotNull(branch.Remote);
1165+
Assert.NotNull(branch.RemoteName);
11671166
Assert.False(branch.IsTracking);
11681167
Assert.Null(branch.TrackedBranch);
11691168

LibGit2Sharp.Tests/NetworkFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ public void CanMergeFetchedRefs()
252252
Assert.False(repo.RetrieveStatus().Any());
253253
Assert.Equal(repo.Lookup<Commit>("refs/remotes/origin/master~1"), repo.Head.Tip);
254254

255-
repo.Network.Fetch(repo.Head.Remote);
255+
using (var remote = repo.Network.Remotes[repo.Head.RemoteName])
256+
{
257+
repo.Network.Fetch(remote);
258+
}
256259

257260
MergeOptions mergeOptions = new MergeOptions()
258261
{

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ public void QueryingTheRemoteForADetachedHeadBranchReturnsNull()
612612
{
613613
repo.Checkout(repo.Head.Tip.Sha, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
614614
Branch trackLocal = repo.Head;
615-
Assert.Null(trackLocal.Remote);
615+
Assert.Null(trackLocal.RemoteName);
616616
}
617617
}
618618

LibGit2Sharp/Branch.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ public virtual string UpstreamBranchCanonicalName
146146
{
147147
if (IsRemote)
148148
{
149-
return Remote.FetchSpecTransformToSource(CanonicalName);
149+
using (var remote = repo.Network.Remotes.RemoteForName(RemoteName))
150+
{
151+
return remote.FetchSpecTransformToSource(CanonicalName);
152+
}
150153
}
151154

152155
return UpstreamBranchCanonicalNameFromLocalBranch();

LibGit2Sharp/Network.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,12 @@ public virtual void Push(
415415

416416
foreach (var branch in enumeratedBranches)
417417
{
418-
Push(branch.Remote, string.Format(
419-
CultureInfo.InvariantCulture,
420-
"{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), pushOptions);
418+
using (var remote = repository.Network.Remotes.RemoteForName(branch.RemoteName))
419+
{
420+
Push(remote, string.Format(
421+
CultureInfo.InvariantCulture,
422+
"{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), pushOptions);
423+
}
421424
}
422425
}
423426

@@ -558,13 +561,17 @@ public virtual MergeResult Pull(Signature merger, PullOptions options)
558561
throw new LibGit2SharpException("There is no tracking information for the current branch.");
559562
}
560563

561-
if (currentBranch.Remote == null)
564+
string remoteName = currentBranch.RemoteName;
565+
if (remoteName == null)
562566
{
563567
throw new LibGit2SharpException("No upstream remote for the current branch.");
564568
}
565569

566-
Fetch(currentBranch.Remote, options.FetchOptions);
567-
return repository.MergeFetchedRefs(merger, options.MergeOptions);
570+
using (var remote = repository.Network.Remotes.RemoteForName(remoteName))
571+
{
572+
Fetch(remote, options.FetchOptions);
573+
return repository.MergeFetchedRefs(merger, options.MergeOptions);
574+
}
568575
}
569576

570577
/// <summary>

0 commit comments

Comments
 (0)