use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitServerUtilTest method url_with_newline.
@TestFor(issues = "TW-50043")
@Test(dataProviderClass = GitVcsRootTest.class, dataProvider = "urlsWithNewLines")
public void url_with_newline(@NotNull String url) throws Exception {
File dir = myTempFiles.createTempDir();
try {
GitServerUtil.getRepository(dir, new URIish(url));
fail("No error for url '" + url + "'");
} catch (VcsException e) {
// expected
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class CheckoutDirectoryCleanerTest method runCommand.
private void runCommand(@NotNull String name, String... params) throws VcsException {
final GeneralCommandLine cl = new GeneralCommandLine();
cl.setExePath(myGitPath);
cl.setWorkDirectory(myRepo.getAbsolutePath());
cl.addParameters("-c", "user.name=test", "-c", "user.email=test@test.com");
cl.addParameter(name);
cl.addParameters(params);
final ExecResult result = SimpleCommandLineProcessRunner.runCommand(cl, null);
final VcsException commandError = CommandLineUtil.getCommandLineError(name, result);
if (commandError != null)
throw commandError;
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method shallow_fetch_tag_with_older_revision.
@Test
public void shallow_fetch_tag_with_older_revision() throws Exception {
final File remote = dataFile("repo_for_shallow_fetch.git");
final LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
loggingFactory.addCallback(FetchCommand.class.getName() + ".setRefspec", new GitCommandProxyCallback() {
@Override
public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
if (args.length == 1 && "a1d6299597f8d6f6d8316577c46cc8fffd657d5e".equals(args[0]))
return null;
fail("Unexpected fetch refspec " + Arrays.toString(args));
return null;
}
});
loggingFactory.addCallback(FetchCommand.class.getName() + ".setDepth", new GitCommandProxyCallback() {
@Override
public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
if (args.length == 1 && Integer.valueOf(1).equals(args[0]))
return null;
fail("Unexpected fetch depth " + Arrays.toString(args));
return null;
}
});
myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(new MockFS()).build();
final AgentRunningBuild build = createRunningBuild(CollectionsUtil.asMap(PluginConfigImpl.USE_SHALLOW_CLONE_INTERNAL, "true"));
myVcsSupport.updateSources(createRoot(remote, "refs/tags/tag1"), new CheckoutRules(""), "a1d6299597f8d6f6d8316577c46cc8fffd657d5e", myCheckoutDir, build, false);
assertEquals(1, loggingFactory.getNumberOfCalls(FetchCommand.class));
final Repository checkout = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
assertEquals("a1d6299597f8d6f6d8316577c46cc8fffd657d5e", checkout.getBranch());
assertFalse(checkout.getObjectDatabase().has(ObjectId.fromString("fd1eb9776b5fad5cc433586f7933811c6853917d")));
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method should_remap_mirror_if_its_fetch_and_remove_failed.
@TestFor(issues = "TW-43884")
public void should_remap_mirror_if_its_fetch_and_remove_failed() 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);
// make first fetch in local mirror to fail:
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("TEST ERROR");
return null;
}
});
File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
// try to fetch unknown branch, fetch fails and delete of the mirror also fails
// build should succeed anyway
fs.makeDeleteFail(mirror);
VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
AgentRunningBuild build = runningBuild().useLocalMirrors(true).sharedConfigParams("teamcity.internal.git.remoteOperationAttempts", "1").withAgentConfiguration(myBuilder.getAgentConfiguration()).build();
myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
// repository was remapped to another dir
then(mirrorAfterBuild).isNotEqualTo(mirror);
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method should_fail_when_ls_remote_fails.
// we run ls-remote during outdated refs cleanup which is needed to
// successfully checkout when ref a/b is renamed to A/b on win or mac (TW-28735).
// If we continue silently this can cause performance problems (TW-44944)
@TestFor(issues = "TW-44944")
public void should_fail_when_ls_remote_fails() throws Exception {
LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).build();
File repo = dataFile("repo_for_fetch.1");
File remoteRepo = myTempFiles.createTempDir();
copyRepository(repo, remoteRepo);
// run build to prepare working dir
VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).build();
myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, createRunningBuild(false), false);
loggingFactory.addCallback(LsRemoteCommand.class.getName() + ".call", new GitCommandProxyCallback() {
@Override
public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
throw new VcsException("TEST ERROR");
}
});
// ls-remote will fail during this build
try {
myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, createRunningBuild(false), false);
fail("should fail");
} catch (VcsException e) {
assertTrue(true);
}
}
Aggregations