use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method mirror_delete_can_be_disabled.
@TestFor(issues = "TW-43884")
public void mirror_delete_can_be_disabled() 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);
// create refs/heads/personal/1 so that incremental fetch will 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 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).sharedConfigParams(AgentRuntimeProperties.FAIL_ON_CLEAN_CHECKOUT, "true").withAgentConfiguration(myBuilder.getAgentConfiguration()).sharedConfigParams("teamcity.git.fetchMirrorRetryTimeouts", "0").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);
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method should_not_retry_fetch_mirror_for_exec_timeout.
@Test(enabled = false)
@TestFor(issues = "TW-56415")
public void should_not_retry_fetch_mirror_for_exec_timeout() 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 two fetches in local mirror to fail:
loggingFactory.addCallback(FetchCommand.class.getName() + ".call", new GitCommandProxyCallback() {
volatile boolean thrown = false;
@Override
public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
if (!thrown) {
thrown = true;
throw new GitExecTimeout();
}
fail("Should not try to fetch again");
return null;
}
});
File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
// try to fetch unknown branch, first fetch fails with exec timeout, repo would be remapped
VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
AgentRunningBuild build = runningBuild().useLocalMirrors(true).sharedConfigParams("teamcity.git.fetchMirrorRetryTimeouts", "0,0").withAgentConfiguration(myBuilder.getAgentConfiguration()).build();
try {
myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
fail("GitExecTimeout exception expected");
} catch (GitExecTimeout ignored) {
}
// try again, should succeed without remapping, means previous code has not changed mirror directory
loggingFactory.addCallback(FetchCommand.class.getName() + ".call", (method, args) -> null);
myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
// repository was not remapped to another dir
then(mirrorAfterBuild).isEqualTo(mirror);
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method shallow_fetch_with_older_revision.
@Test
public void shallow_fetch_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:refs/remotes/origin/main".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/heads/main"), new CheckoutRules(""), "a1d6299597f8d6f6d8316577c46cc8fffd657d5e", myCheckoutDir, build, false);
assertEquals(1, loggingFactory.getNumberOfCalls(FetchCommand.class));
final Repository checkout = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
assertEquals("main", checkout.getBranch());
final Ref main = checkout.getRefDatabase().findRef("main");
assertNotNull(main);
assertEquals("a1d6299597f8d6f6d8316577c46cc8fffd657d5e", main.getObjectId().getName());
assertNotNull(checkout.getRefDatabase().findRef("refs/remotes/origin/main"));
assertNull(checkout.getRefDatabase().findRef("refs/tags/tag1"));
assertNotNull(checkout.getRefDatabase().findRef("refs/tags/tag2"));
assertFalse(checkout.getObjectDatabase().has(ObjectId.fromString("fd1eb9776b5fad5cc433586f7933811c6853917d")));
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AutoCheckoutTest method should_respect_root_settings_when_checking_multi_root_constraints2.
@TestFor(issues = "TW-49786")
public void should_respect_root_settings_when_checking_multi_root_constraints2() throws Exception {
VcsRoot root1 = vcsRoot().withId(1).withFetchUrl("http://some.org/repo1.git").build();
VcsRoot root2 = vcsRoot().withId(2).withFetchUrl("http://some.org/repo2.git").build();
AgentRunningBuild build = runningBuild().addRootEntry(root1, "+:dir1").addRootEntry(root2, "+:dir2").build();
// both roots require sparse checkout and mapped into the same directory, but the second
// root uses git version which doesn't support sparse checkout; we shouldn't take it into
// account during canCheckout() check for the first root
GitDetector detector = new GitDetector() {
@NotNull
public GitExec getGitPathAndVersion(@NotNull VcsRoot root, @NotNull BuildAgentConfiguration config, @NotNull AgentRunningBuild build) throws VcsException {
if (root.equals(root1)) {
return new GitExec("git1", GIT_WITH_SPARSE_CHECKOUT);
}
if (root.equals(root2)) {
return new GitExec("git2", GIT_WITH_SPARSE_CHECKOUT.previousVersion());
}
throw new VcsException("Unexpected VCS root");
}
@NotNull
@Override
public GitExec getGitPathAndVersion(@NotNull AgentRunningBuild build) throws VcsException {
throw new UnsupportedOperationException();
}
};
myVcsSupport = createVcsSupport(detector);
AgentCheckoutAbility canCheckout1 = myVcsSupport.canCheckout(root1, new CheckoutRules("+:dir1"), build);
AgentCheckoutAbility canCheckout2 = myVcsSupport.canCheckout(root2, new CheckoutRules("+:dir2"), build);
then(canCheckout1.getCanNotCheckoutReason()).isNull();
then(canCheckout2.getCanNotCheckoutReason().getType()).isEqualTo(AgentCanNotCheckoutReason.NOT_SUPPORTED_CHECKOUT_RULES);
then(canCheckout2.getCanNotCheckoutReason().getDetails()).contains("Cannot perform sparse checkout using git " + GIT_WITH_SPARSE_CHECKOUT.previousVersion());
}
use of jetbrains.buildServer.vcs.VcsException 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);
}
}
Aggregations