use of jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport in project teamcity-git by JetBrains.
the class GitMergeSupportTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
myPaths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
GitSupportBuilder builder = gitSupport().withServerPaths(myPaths);
myGit = builder.build();
myRepoOperations = new GitRepoOperationsImpl(builder.getPluginConfig(), builder.getTransportFactory(), r -> null, (a, b, c) -> {
});
myMergeSupport = new GitMergeSupport(myGit, builder.getCommitLoader(), builder.getRepositoryManager(), builder.getPluginConfig(), myRepoOperations);
myRoot = vcsRoot().withFetchUrl(getRemoteRepositoryDir("merge")).build();
}
use of jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport in project teamcity-git by JetBrains.
the class GitMergeSupportTest method concurrent_merge.
@TestFor(issues = "TW-48463")
public void concurrent_merge() throws Exception {
// disable merge retries
GitSupportBuilder builder = gitSupport().withPluginConfig(pluginConfig().setPaths(myPaths).setMergeRetryAttempts(0));
myGit = builder.build();
myMergeSupport = new GitMergeSupport(myGit, builder.getCommitLoader(), builder.getRepositoryManager(), builder.getPluginConfig(), myRepoOperations);
// make clone on the server, so that none of the merges perform the clone
RepositoryStateData s1 = RepositoryStateData.createVersionState("refs/heads/master", map("refs/heads/master", "f727882267df4f8fe0bc58c18559591918aefc54"));
RepositoryStateData s2 = RepositoryStateData.createVersionState("refs/heads/master", map("refs/heads/master", "f727882267df4f8fe0bc58c18559591918aefc54", "refs/heads/topic2", "cc69c22bd5d25779e58ad91008e685cbbe7f700a", "refs/heads/topic3", "68b73163526a29a1f5a341f3b6fcd0d928748579"));
myGit.getCollectChangesPolicy().collectChanges(myRoot, s1, s2, CheckoutRules.DEFAULT);
RepositoryStateData state1 = myGit.getCurrentState(myRoot);
// run concurrent merge of topic2 and topic3 into master, one of the merges should fail since branches diverged
CountDownLatch latch = new CountDownLatch(1);
CountDownLatch t1Ready = new CountDownLatch(1);
CountDownLatch t2Ready = new CountDownLatch(1);
AtomicReference<MergeResult> result1 = new AtomicReference<>();
AtomicReference<MergeResult> result2 = new AtomicReference<>();
Thread t1 = new Thread(() -> {
try {
t1Ready.countDown();
latch.await();
result1.set(myMergeSupport.merge(myRoot, "cc69c22bd5d25779e58ad91008e685cbbe7f700a", "refs/heads/master", "merge", new MergeOptions()));
} catch (Exception e) {
e.printStackTrace();
}
});
t1.start();
Thread t2 = new Thread(() -> {
try {
t2Ready.countDown();
latch.await();
result2.set(myMergeSupport.merge(myRoot, "68b73163526a29a1f5a341f3b6fcd0d928748579", "refs/heads/master", "merge", new MergeOptions()));
} catch (Exception e) {
e.printStackTrace();
}
});
t2.start();
t1Ready.await();
t2Ready.await();
latch.countDown();
t1.join();
t2.join();
RepositoryStateData state2 = myGit.getCurrentState(myRoot);
List<ModificationData> changes = myGit.getCollectChangesPolicy().collectChanges(myRoot, state1, state2, CheckoutRules.DEFAULT);
long successfulMergeCommitCommitCount = changes.stream().filter(m -> m.getParentRevisions().size() == 2).count();
// either both merges succeeds and made it into repository, or one of them fails
then(successfulMergeCommitCommitCount == 2 || result1.get().isSuccess() != result2.get().isSuccess()).overridingErrorMessage("Non-fast-forward push succeeds").isTrue();
}
Aggregations