use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class GitVcsSupportTest method getFetchExceptionMessage.
private String getFetchExceptionMessage() {
String result = null;
File notExisting = new File(myTmpDir, "not-existing");
VcsRootImpl root = new VcsRootImpl(1, Constants.VCS_NAME);
root.addProperty(Constants.FETCH_URL, GitUtils.toURL(notExisting));
try {
getSupport().getContentProvider().getContent("some/path", root, MERGE_VERSION);
fail("Should throw an exception for not-existing repository");
} catch (VcsException e) {
result = e.getMessage();
}
return result;
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class GitVcsSupportTest method gc_disabled_by_user.
@Test
public void gc_disabled_by_user() throws Exception {
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");
// disable gc externally
config.setInt("gc", null, "auto", 0);
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));
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class GitVcsSupportTest method collecting_changes_should_not_block_IDE_requests.
// @Test
public void collecting_changes_should_not_block_IDE_requests() throws Exception {
String classpath = myConfigBuilder.build().getFetchClasspath() + File.pathSeparator + ClasspathUtil.composeClasspath(new Class[] { MockFetcher.class }, null, null);
myConfigBuilder.setSeparateProcessForFetch(true).setFetchClasspath(classpath).setFetcherClassName(MockFetcher.class.getName());
final GitVcsSupport support = getSupport();
final VcsRootImpl root = (VcsRootImpl) getRoot("master");
final File customRootDir = new File(myTmpDir, "custom-dir");
root.addProperty(Constants.PATH, customRootDir.getAbsolutePath());
final String repositoryUrl = root.getProperty(Constants.FETCH_URL);
final AtomicInteger succeedIDERequestCount = new AtomicInteger(0);
final AtomicBoolean fetchBlocksIDERequests = new AtomicBoolean(false);
final List<Exception> errors = Collections.synchronizedList(new ArrayList<Exception>());
Runnable longFetch = new Runnable() {
public void run() {
try {
support.collectChanges(root, VERSION_TEST_HEAD, MERGE_VERSION, new CheckoutRules(""));
fetchBlocksIDERequests.set(succeedIDERequestCount.get() == 0);
} catch (VcsException e) {
errors.add(e);
}
}
};
Runnable requestsFromIDE = new Runnable() {
public void run() {
while (!new File(customRootDir, "mock.lock").exists()) {
// wait for fetch to begin (MockFetcher holds a lock during fetch)
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
LockFile lock = new LockFile(new File(customRootDir.getAbsolutePath(), "mock"));
try {
while (true) {
// do mapFullPath while fetch is executed (we cannot acquire a lock while it is executed)
if (!lock.lock()) {
support.mapFullPath(new VcsRootEntry(root, new CheckoutRules("")), GitUtils.versionRevision(VERSION_TEST_HEAD) + "|" + repositoryUrl + "|readme.txt");
succeedIDERequestCount.incrementAndGet();
} else {
lock.unlock();
break;
}
}
} catch (Exception e) {
errors.add(e);
}
}
};
Thread fetch = new Thread(longFetch);
Thread ideRequests = new Thread(requestsFromIDE);
fetch.start();
ideRequests.start();
fetch.join();
ideRequests.join();
if (!errors.isEmpty()) {
fail("Errors in readers thread", errors.get(0));
}
assertFalse(fetchBlocksIDERequests.get());
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class GitVcsSupportTest method should_create_teamcity_config_in_root_with_custom_path.
/*
* Repository cloned by hand could have no teamcity.remote config, we should create it otherwise we can see 'null' as remote url in error messages
* (see log in the issue for details).
*/
@TestFor(issues = "TW-15564")
@Test(dataProvider = "doFetchInSeparateProcess", dataProviderClass = FetchOptionsDataProvider.class)
public void should_create_teamcity_config_in_root_with_custom_path(boolean fetchInSeparateProcess) throws IOException, VcsException {
setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true");
System.setProperty("teamcity.git.fetch.separate.process", String.valueOf(fetchInSeparateProcess));
File customRootDir = new File(myTmpDir, "custom-dir");
VcsRootImpl root = (VcsRootImpl) getRoot("master");
root.addProperty(Constants.PATH, customRootDir.getAbsolutePath());
getSupport().getCurrentState(root);
File configFile = new File(customRootDir, "config");
String config = FileUtil.readText(configFile);
Pattern pattern = Pattern.compile("(.*)\\[teamcity\\]\\s+remote = " + Pattern.quote(GitUtils.toURL(myMainRepositoryDir)) + "\\s*(.*)", Pattern.DOTALL);
Matcher matcher = pattern.matcher(config);
assertTrue(matcher.matches(), "config is " + config);
// erase teamcity.remote config
String newConfig = matcher.group(1) + matcher.group(2);
writeFile(configFile, newConfig);
getSupport().getCurrentState(root);
config = FileUtil.readText(configFile);
assertTrue(pattern.matcher(config).matches());
}
use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class HttpAuthTest method quote_in_password.
@TestFor(issues = "TW-51968")
public void quote_in_password(@NotNull GitExec git) throws Exception {
File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.1"), "repo.git");
final String user = "user";
final String password = "pass'word";
myServer = new GitHttpServer(git.getPath(), repo);
myServer.setCredentials(user, password);
myServer.start();
VcsRootImpl root = vcsRoot().withFetchUrl(myServer.getRepoUrl()).withAuthMethod(AuthenticationMethod.PASSWORD).withUsername(user).withPassword(password).withBranch("master").build();
File buildDir = myTempFiles.createTempDir();
AgentRunningBuild build = runningBuild().sharedEnvVariable(Constants.TEAMCITY_AGENT_GIT_PATH, git.getPath()).withAgentConfiguration(myAgentConfiguration).addRoot(root).withCheckoutDir(buildDir).build();
Checkout checkout = new Checkout(root, "add81050184d3c818560bdd8839f50024c188586", buildDir, build);
checkout.run(TimeUnit.SECONDS.toMillis(10));
assertTrue(checkout.success());
}
Aggregations