use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.
the class AgentVcsSupportTest method should_handle_ref_pointing_to_invalid_object.
public void should_handle_ref_pointing_to_invalid_object() throws Exception {
File repo = dataFile("repo_for_fetch.1");
File remoteRepo = myTempFiles.createTempDir();
copyRepository(repo, remoteRepo);
VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).withUseMirrors(true).build();
// first build
AgentRunningBuild build = createRunningBuild(map(PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY, PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY_ALTERNATES));
myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, build, false);
// create ref pointing to invalid object
File gitDir = new File(myCheckoutDir, ".git");
String invalidObject = "bba7fbcc200b4968e6abd2f7d475dc15306cafc1";
FileUtil.writeFile(new File(gitDir, "refs/heads/brokenRef"), invalidObject);
FileUtil.writeFile(new File(gitDir, "refs/remotes/origin/brokenRef"), invalidObject);
final File packedRefs = new File(gitDir, "packed-refs");
FileUtil.writeToFile(packedRefs, (invalidObject + " refs/heads/anotherBrokenRef").getBytes(), true);
FileUtil.writeToFile(packedRefs, (invalidObject + " refs/remotes/origin/anotherBrokenRef").getBytes(), true);
// update remote repo
delete(remoteRepo);
File updatedRepo = dataFile("repo_for_fetch.3");
copyRepository(updatedRepo, remoteRepo);
// second build
build = createRunningBuild(map(PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY, PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY_ALTERNATES));
myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "bba7fbcc200b4968e6abd2f7d475dc15306cafc6", myCheckoutDir, build, false);
then(new File(gitDir, "refs/heads/brokenRef")).doesNotExist();
then(new File(gitDir, "refs/heads/anotherBrokenRef")).doesNotExist();
then(readText(packedRefs)).doesNotContain("refs/heads/brokenRef");
then(readText(packedRefs)).doesNotContain("refs/remotes/origin/brokenRef");
then(readText(packedRefs)).doesNotContain("refs/remotes/origin/anotherBrokenRef");
then(readText(packedRefs)).doesNotContain("refs/remotes/origin/anotherBrokenRef");
final ShowRefResult showRefResult = new AgentGitFacadeImpl(getGitPath()).showRef().call();
then(showRefResult.getInvalidRefs()).isEmpty();
then(showRefResult.getValidRefs()).isNotEmpty();
then(showRefResult.isFailed()).isFalse();
}
Aggregations