use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class VcsRootBuilder method build.
@NotNull
public VcsRootImpl build() {
final int id = myId != null ? myId : 1;
VcsRootImpl result = new VcsRootImpl(id, Constants.VCS_NAME);
result.setName(myFetchUrl);
result.addProperty(VcsUtil.VCS_NAME_PROP, Constants.VCS_NAME);
result.addProperty(Constants.FETCH_URL, myFetchUrl);
if (myPushUrl != null)
result.addProperty(Constants.PUSH_URL, myPushUrl);
result.addProperty(Constants.BRANCH_NAME, myBranchName);
result.addProperty(Constants.USERNAME_FOR_TAGS, myUsernameForTags);
result.addProperty(Constants.BRANCH_SPEC, myBranchSpec);
if (myUseMirrors != null)
result.addProperty(Constants.CHECKOUT_POLICY, String.valueOf(myUseMirrors));
if (myUsername != null)
result.addProperty(Constants.USERNAME, myUsername);
if (myPassword != null)
result.addProperty(Constants.PASSWORD, myPassword);
if (mySubmodulePolicy != null)
result.addProperty(Constants.SUBMODULES_CHECKOUT, mySubmodulePolicy.name());
if (myAuthMethod != null)
result.addProperty(Constants.AUTH_METHOD, myAuthMethod.name());
if (myPath != null)
result.addProperty(Constants.PATH, myPath);
if (myAgentGitPath != null)
result.addProperty(Constants.AGENT_GIT_PATH, myAgentGitPath);
if (myPrivateKeyPath != null) {
result.addProperty(Constants.PRIVATE_KEY_PATH, myPrivateKeyPath);
}
if (myTeamCitySshKey != null) {
result.addProperty("teamcitySshKey", myTeamCitySshKey);
}
if (myPassphrase != null) {
result.addProperty(Constants.PASSPHRASE, myPassphrase);
}
if (myRequestToken != null) {
result.addProperty(PluginConfigImpl.SSH_SEND_ENV_REQUEST_TOKEN, myRequestToken);
}
result.addProperty(Constants.SERVER_SIDE_AUTO_CRLF, String.valueOf(myAutoCrlf));
result.addProperty(Constants.REPORT_TAG_REVISIONS, String.valueOf(myReportTags));
result.addProperty(Constants.IGNORE_KNOWN_HOSTS, String.valueOf(myIgnoreKnownHosts));
return result;
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class GitVcsSupportTest method getCurrentVersion_should_not_do_fetch.
@TestFor(issues = "TW-17435")
@Test
public void getCurrentVersion_should_not_do_fetch() throws Exception {
ServerPluginConfig config = myConfigBuilder.build();
VcsRootSshKeyManager manager = new EmptyVcsRootSshKeyManager();
FetchCommand fetchCommand = new FetchCommandImpl(config, new TransportFactoryImpl(config, manager), new FetcherProperties(config), manager);
FetchCommandCountDecorator fetchCounter = new FetchCommandCountDecorator(fetchCommand);
GitVcsSupport git = gitSupport().withPluginConfig(myConfigBuilder).withResetCacheManager(myResetCacheManager).withFetchCommand(fetchCounter).build();
File remoteRepositoryDir = new File(myTmpDir, "repo_for_fetch");
copyRepository(dataFile("repo_for_fetch.1"), remoteRepositoryDir);
VcsRootImpl root = getRoot("master", false, remoteRepositoryDir);
git.getCurrentState(root);
assertEquals(0, fetchCounter.getFetchCount());
git.getCurrentState(root);
assertEquals(0, fetchCounter.getFetchCount());
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class GitVcsSupportTest method should_update_refs_when_packed_refs_locked.
// test recover from .git/packed-refs.lock when updating several refs
@Test
@TestFor(issues = "TW-64281")
public void should_update_refs_when_packed_refs_locked() throws Exception {
setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true");
GitVcsSupport git = getSupport();
final File repo = new File(myTmpDir, "TW-64281");
FileUtil.copyDir(dataFile("TW-64281-1"), repo);
final VcsRootImpl root = getRoot("master", false, repo);
final File customRootDir = new File(myTmpDir, "custom-dir");
root.addProperty(Constants.PATH, customRootDir.getAbsolutePath());
final RepositoryStateData s = createVersionState("refs/heads/master", CollectionsUtil.asMap("refs/heads/master", "650e7fb0b9c655c3e0468a8c01c446fdeba08823", "refs/heads/br", "f3d37d0d8db3d2f78fdf58294ec57965bcbdab02"));
git.getCollectChangesPolicy().collectChanges(root, createVersionState("refs/heads/master", CollectionsUtil.asMap("refs/heads/master", null, "refs/heads/branch", null)), s, CheckoutRules.DEFAULT);
File packedRefsLockFile = new File(customRootDir, "packed-refs.lock");
FileUtil.writeFileAndReportErrors(packedRefsLockFile, "branch");
assertTrue(packedRefsLockFile.exists());
// copy new repo that contains new commits - this will cause fetch during collecting changes
FileUtil.copyDir(dataFile("TW-64281-2"), repo);
git.getCollectChangesPolicy().collectChanges(root, s, createVersionState("refs/heads/master", CollectionsUtil.asMap("refs/heads/master", "edad18e2ee4380197a7746355d5ad79ae4a71e2a", "refs/heads/br", "7361e8beff17c08095a418615030065c9262123a")), CheckoutRules.DEFAULT);
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class GitVcsSupportTest method disable_auto_gc.
@Test
@TestFor(issues = "TW-65641")
public void disable_auto_gc() throws Exception {
myConfigBuilder.setSeparateProcessForFetch(false);
final File repo = createTempDir();
ZipUtil.extract(new File(getTestDataPath(), "TW-65641-1.zip"), repo, null);
final GitVcsSupport support = getSupport();
final VcsRootImpl root = getRoot("master", false, repo);
final OperationContext context = support.createContext(root, "fetch");
final GitVcsRoot gitRoot = context.getGitRoot();
final File mirror = gitRoot.getRepositoryDir();
ZipUtil.extract(new File(getTestDataPath(), "TW-65641.zip"), mirror, null);
// make sure old pack files won't be kept
final StoredConfig config = context.getRepository().getConfig();
config.setString("gc", null, "prunepackexpire", "now");
config.save();
final File gitObjects = new File(mirror + "/objects");
Assert.assertTrue(gitObjects.isDirectory());
final HashSet<String> before = listObjectsRecursively(mirror);
support.collectChanges(root, "2faa6375bf6139923245a625a47bef046e5e6550", "ba04d81036c5953d17469f532e520fc1ecbcd3f1", CheckoutRules.DEFAULT);
// enough time for auto gc to start
Thread.sleep(5000);
new WaitFor() {
@Override
protected boolean condition() {
return !new File(mirror, "gc.log.lock").isFile();
}
};
final HashSet<String> after = listObjectsRecursively(mirror);
Assert.assertTrue(after.containsAll(before));
after.removeAll(before);
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class GitVcsSupportTest method should_retry_getCurrentState_if_it_fails.
@Test
@TestFor(issues = "TW-24084")
public void should_retry_getCurrentState_if_it_fails() throws Exception {
VcsRootImpl root = vcsRoot().withFetchUrl("ssh://some.org/repo.git").withAuthMethod(AuthenticationMethod.PRIVATE_KEY_DEFAULT).build();
final FetchConnection connection = myContext.mock(FetchConnection.class);
final Ref masterRef = myContext.mock(Ref.class, "master");
final Ref topicRef = myContext.mock(Ref.class, "topic");
myContext.checking(new Expectations() {
{
allowing(masterRef).getName();
will(returnValue("refs/heads/master"));
allowing(masterRef).getObjectId();
will(returnValue(ObjectId.fromString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
allowing(topicRef).getName();
will(returnValue("refs/heads/topic"));
allowing(topicRef).getObjectId();
will(returnValue(ObjectId.fromString("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")));
allowing(connection).getRefsMap();
will(returnValue(map("refs/heads/master", masterRef, "refs/heads/topic", topicRef)));
allowing(connection).close();
}
});
// setup TransportFactory so that it fails to get connection several times with well known exceptions
// and then successfully gets it on the last call
final AtomicInteger failCount = new AtomicInteger(0);
final List<TransportException> recoverableErrors = Arrays.asList(new TransportException("Session.connect: java.net.SocketException: Connection reset", new JSchException("test")), new TransportException("Session.connect: java.net.SocketException: Software caused connection abort", new JSchException("test")), new TransportException("com.jcraft.jsch.JSchException: connection is closed by foreign host", new JSchException("test")), new TransportException("java.net.UnknownHostException: some.org", new JSchException("test")), new TransportException("com.jcraft.jsch.JSchException: verify: false", new JSchException("test")), new TransportException("com.jcraft.jsch.JSchException: channel is not opened.", new JSchException("test")));
ServerPluginConfig config = myConfigBuilder.withGetConnectionRetryAttempts(recoverableErrors.size() + 1).withConnectionRetryIntervalMillis(0).setCurrentStateTimeoutSeconds(1).build();
VcsRootSshKeyManager manager = new EmptyVcsRootSshKeyManager();
TransportFactory transportFactory = new TransportFactoryImpl(config, manager) {
@Override
public Transport createTransport(@NotNull Repository r, @NotNull URIish url, @NotNull AuthSettings authSettings, int timeoutSeconds) throws NotSupportedException, VcsException {
return new Transport(r, url) {
@Override
public FetchConnection openFetch() throws NotSupportedException, TransportException {
if (failCount.get() < recoverableErrors.size()) {
TransportException error = recoverableErrors.get(failCount.get());
failCount.incrementAndGet();
throw error;
} else {
return connection;
}
}
@Override
public PushConnection openPush() throws NotSupportedException, TransportException {
return null;
}
@Override
public void close() {
}
};
}
};
FetchCommand fetchCommand = new FetchCommandImpl(config, transportFactory, new FetcherProperties(config), manager);
FetchCommandCountDecorator fetchCounter = new FetchCommandCountDecorator(fetchCommand);
GitVcsSupport git = gitSupport().withPluginConfig(config).withTransportFactory(transportFactory).withFetchCommand(fetchCounter).build();
RepositoryStateData state = git.getCurrentState(root);
assertEquals(state.getBranchRevisions(), map("refs/heads/master", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "refs/heads/topic", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
}
Aggregations