Skip to content

Commit 7d833b7

Browse files
committed
Merge pull request #626 from orjan/should-not-checkout-branch-on-update
Should not checkout branch on update
2 parents ba2158d + a5091ee commit 7d833b7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/GitVersionCore.Tests/GitHelperTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,34 @@ public void UpdatesCurrentBranch()
100100
}
101101
}
102102
}
103+
104+
[Test]
105+
public void ShouldNotChangeBranchWhenNormalizingTheDirectory()
106+
{
107+
using (var fixture = new EmptyRepositoryFixture(new Config()))
108+
{
109+
fixture.Repository.MakeATaggedCommit("v1.0.0");
110+
111+
fixture.Repository.Checkout(fixture.Repository.CreateBranch("develop"));
112+
var lastCommitOnDevelop = fixture.Repository.MakeACommit();
113+
114+
fixture.Repository.Checkout(fixture.Repository.CreateBranch("feature/foo"));
115+
fixture.Repository.MakeACommit();
116+
117+
using (var localFixture = fixture.CloneRepository())
118+
{
119+
localFixture.Repository.Checkout("origin/develop");
120+
121+
// Another commit on feature/foo will force an update
122+
fixture.Checkout("feature/foo");
123+
fixture.Repository.MakeACommit();
124+
125+
GitHelper.NormalizeGitDirectory(localFixture.RepositoryPath, new Authentication(), noFetch: false, currentBranch: null);
126+
127+
localFixture.Repository.DumpGraph();
128+
localFixture.Repository.Head.Tip.Sha.ShouldBe(lastCommitOnDevelop.Sha);
129+
}
130+
}
131+
}
103132
}
104133
}

src/GitVersionCore/BuildServers/GitHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(Repository repo, s
279279
var remoteRefTipId = remotedirectReference.Target.Id;
280280
Logger.WriteInfo(string.Format("Updating local ref '{0}' to point at {1}.", localRef.CanonicalName, remoteRefTipId));
281281
repo.Refs.UpdateTarget(localRef, remoteRefTipId);
282-
repo.Checkout(branchName);
283282
continue;
284283
}
285284

0 commit comments

Comments
 (0)