use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class TestConnectionTest method testConnection_should_not_be_blocked_by_long_fetch.
public void testConnection_should_not_be_blocked_by_long_fetch() throws Exception {
PluginConfigBuilder config = pluginConfig().withDotBuildServerDir(myTempFiles.createTempDir()).setSeparateProcessForFetch(false);
final Semaphore fetchStarted = new Semaphore(1);
final Semaphore fetchCanFinish = new Semaphore(1);
final GitVcsSupport git = gitSupport().withBeforeFetchHook(new Runnable() {
public void run() {
fetchStarted.release();
fetchCanFinish.acquireUninterruptibly();
}
}).withPluginConfig(config).build();
final VcsRoot root = vcsRoot().withFetchUrl(getRemoteRepositoryUrl("repo.git")).build();
// don't allow fetch to start
fetchStarted.acquireUninterruptibly();
// don't allow fetch to finish
fetchCanFinish.acquireUninterruptibly();
Thread longFetch = new Thread(new Runnable() {
public void run() {
try {
git.collectChanges(root, "2276eaf76a658f96b5cf3eb25f3e1fda90f6b653", "ad4528ed5c84092fdbe9e0502163cf8d6e6141e7", CheckoutRules.DEFAULT);
} catch (VcsException e) {
e.printStackTrace();
}
}
});
longFetch.start();
Assert.assertTrue(fetchStarted.tryAcquire(10, TimeUnit.SECONDS));
// test connection during long fetch
git.testConnection(root);
// allow fetch to finish
fetchCanFinish.release();
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class TestConnectionTest method wrong_github_username.
@TestFor(issues = "TW-24074")
@Test(dataProvider = "common-github-auth-errors")
public void wrong_github_username(@NotNull final String error) {
TransportFactory factoryWithGivenError = new TransportFactory() {
public Transport createTransport(@NotNull Repository r, @NotNull URIish url, @NotNull AuthSettings authSettings) throws NotSupportedException, VcsException, TransportException {
return createTransport(r, url, authSettings, 60);
}
public Transport createTransport(@NotNull Repository r, @NotNull URIish url, @NotNull AuthSettings authSettings, int timeoutSeconds) throws NotSupportedException, VcsException, TransportException {
throw new TransportException(url.toString() + ": " + error, new JSchException(error));
}
@NotNull
@Override
public SshSessionFactory getSshSessionFactory(@NotNull URIish url, @NotNull AuthSettings authSettings) throws VcsException {
throw new UnsupportedOperationException();
}
};
myGit = gitSupport().withTransportFactory(factoryWithGivenError).withServerPaths(myPaths).build();
String wrongUsername = "user";
VcsRootImpl root = vcsRoot().withFetchUrl("git@github.com:user/repo.git").withBranch("master").withAuthMethod(AuthenticationMethod.PRIVATE_KEY_DEFAULT).withUsername(wrongUsername).build();
try {
myGit.testConnection(root);
fail("should fail during transport creation");
} catch (VcsException e) {
assertTrue(e.getMessage(), e.getMessage().contains("Wrong username: '" + wrongUsername + "', GitHub expects the 'git' username"));
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class FetchCommandImplTest method should_throw_special_exception_when_stderr_mentions_broken_index.
@TestFor(issues = "TW-18853")
public void should_throw_special_exception_when_stderr_mentions_broken_index() throws VcsException {
AgentGitCommandLine failedCmd = new AgentGitCommandLine(null, getFakeGen(), new StubContext()) {
@Override
public ExecResult run(@NotNull GitCommandSettings settings) throws VcsException {
throw new VcsException("fatal: index file smaller than expected");
}
};
FetchCommand fetch = new FetchCommandImpl(failedCmd).setRefspec("+refs/heads/*:refs/remotes/origin/*").setTimeout(3600).setAuthSettings(getEmptyAuthSettings());
try {
fetch.call();
} catch (GitIndexCorruptedException e) {
// expected
} catch (VcsException e) {
fail("GitIndexCorruptedException should be thrown");
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class RepositoryManagerTest method should_throw_exception_when_repository_configured_for_different_url.
public void should_throw_exception_when_repository_configured_for_different_url() throws Exception {
RepositoryManager repositoryManager = getRepositoryManager();
File dir = repositoryManager.getMirrorDir("git://some.org/repo.git");
repositoryManager.openRepository(new URIish("git://some.org/repo.git"));
try {
repositoryManager.openRepository(dir, new URIish("git://some.org/other-repo.git"));
fail("Expect error, dir is used for another url");
} catch (VcsException e) {
assertTrue(true);
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AgentStartupGitDetector method afterAgentConfigurationLoaded.
@Override
public void afterAgentConfigurationLoaded(@NotNull BuildAgent agent) {
if (pathToGitConfigured(agent)) {
LOG.debug("Path to git configured, will not try to detect git");
return;
}
for (String path : getCandidatePaths()) {
try {
final GitVersion version = new AgentGitFacadeImpl(path).version().call();
agent.getConfiguration().addEnvironmentVariable(Constants.TEAMCITY_AGENT_GIT_VERSION, version.toString());
if (version.isSupported()) {
LOG.info("Detect git at " + path);
setPathToGit(agent, path);
break;
} else {
LOG.debug("TeamCity supports Git version " + GitVersion.MIN + " or higher, git at " + path + " has version " + version + " and will not be used");
}
} catch (VcsException e) {
LOG.debug("Cannot run git at " + path, e);
}
}
detectGitLfs(agent);
detectSSH(agent);
}
Aggregations