use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method build_on_pull_request.
@TestFor(issues = "TW-31039")
@Test(dataProvider = "mirrors")
public void build_on_pull_request(Boolean useMirrors) throws Exception {
// Remote repo contains a pull request branch refs/changes/2/1 which is not under refs/heads/*,
// this branch points to a commit which is not reachable from the default branch in vcs root
// and from any other branches under refs/heads/.
// Ensure that once we pass a pull request branch name, checkout it successful
VcsRootImpl root = createRoot(myMainRepo, "master");
String pullRequestCommit = "ea5e05051fbfaa7d8da97586807b009cbfebae9d";
AgentRunningBuild build = createRunningBuild(map(PluginConfigImpl.USE_MIRRORS, String.valueOf(useMirrors), GitUtils.getGitRootBranchParamName(root), "refs/changes/2/1"));
myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, pullRequestCommit, myCheckoutDir, build, false);
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method fetch_interrupted.
@TestFor(issues = "TW-65373")
public void fetch_interrupted() throws Exception {
MockFS fs = new MockFS();
LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(fs).build();
File repo = dataFile("repo_for_fetch.1");
File remoteRepo = myTempFiles.createTempDir();
copyRepository(repo, remoteRepo);
// run build to prepare mirror
VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).build();
myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, createRunningBuild(true), false);
// update remote repo: add personal branch
delete(remoteRepo);
File updatedRepo = dataFile("repo_for_fetch.2.personal");
copyRepository(updatedRepo, remoteRepo);
AtomicInteger invocationCount = new AtomicInteger(0);
loggingFactory.addCallback(FetchCommand.class.getName() + ".call", new GitCommandProxyCallback() {
@Override
public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
if (invocationCount.getAndIncrement() == 0)
throw new VcsException(new InterruptedException());
return Optional.empty();
}
});
File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
fs.makeDeleteFail(mirror);
try {
AgentRunningBuild build = runningBuild().useLocalMirrors(true).withAgentConfiguration(myBuilder.getAgentConfiguration()).build();
myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
fail("Should fail");
} catch (VcsException e) {
File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
// should fail on first fetch attempt and not remap or delete the mirror
then(mirrorAfterBuild).isEqualTo(mirror);
then(invocationCount.get()).isEqualTo(1);
}
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class TestConnectionTest method testConnection_should_validate_branchSpec.
public void testConnection_should_validate_branchSpec() throws Exception {
VcsRootImpl root = vcsRoot().withFetchUrl(getRemoteRepositoryUrl("repo.git")).withBranch("master").withBranchSpec("+:/refs/heads/*").build();
try {
myGit.testConnection(root);
fail("Test connection should validate branchSpec");
} catch (VcsException e) {
assertTrue(e.getMessage().contains("pattern should not start with /"));
}
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class TestConnectionTest method testConnection_should_throw_exception_for_anonymous_git_url_with_username.
public void testConnection_should_throw_exception_for_anonymous_git_url_with_username() throws Exception {
ServerPluginConfig config = pluginConfig().withDotBuildServerDir(myTempFiles.createTempDir()).setIdleTimeoutSeconds(2).setFetchTimeout(2).setCurrentStateTimeoutSeconds(2).build();
myGit = gitSupport().withServerPaths(myPaths).withPluginConfig(config).build();
String url = "git://git@some.org/repository";
VcsRootImpl root = vcsRoot().withFetchUrl(url).build();
try {
myGit.testConnection(root);
fail("should fail, because native git fails for such url");
} catch (VcsException e) {
assertTrue(e.getMessage().contains("Incorrect url " + url + ": anonymous git url should not contain a username"));
}
// that means old roots that have such urls and use server-side checkout will still work
try {
myGit.collectChanges(root, "f3f826ce85d6dad25156b2d7550cedeb1a422f4c", "ce6044093939bb47283439d97a1c80f759669ff5", CheckoutRules.DEFAULT);
fail("should fail, because no such root exists");
} catch (VcsException e) {
assertFalse(e.getMessage().contains("Incorrect url " + url + ": anonymous git url should not contain a username"));
}
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class TransportFactoryTest method createTransport.
private Transport createTransport(TransportFactory factory) throws Exception {
File original = dataFile("repo.git");
File copy = myTempFiles.createTempDir();
FileUtil.copyDir(original, copy);
VcsRootImpl root = getVcsRoot(copy);
MirrorManager mirrorManager = new MirrorManagerImpl(myConfigBuilder.build(), new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
GitVcsRoot gitRoot = new GitVcsRoot(mirrorManager, root, new URIishHelperImpl());
Repository repository = new RepositoryBuilder().setGitDir(copy).setBare().build();
return factory.createTransport(repository, new URIish(GitUtils.toURL(original)), gitRoot.getAuthSettings());
}
Aggregations