Search in sources :

Example 1 with ShowRefResult

use of jetbrains.buildServer.buildTriggers.vcs.git.agent.command.ShowRefResult in project teamcity-git by JetBrains.

the class ShowRefCommandImpl method call.

@NotNull
public ShowRefResult call() {
    GitCommandLine cmd = getCmd();
    cmd.addParameter("show-ref");
    if (myPattern != null)
        cmd.addParameters(myPattern);
    if (myShowTags)
        cmd.addParameter("--tags");
    try {
        ExecResult result = CommandUtil.runCommand(cmd);
        return new ShowRefResult(parseValidRefs(result.getStdout()), parseInvalidRefs(result.getStderr()), result.getExitCode());
    } catch (VcsException e) {
        getCmd().getContext().getLogger().warning("show-ref command failed, empty result will be returned: " + e.getMessage());
        return new ShowRefResult();
    }
}
Also used : ShowRefResult(jetbrains.buildServer.buildTriggers.vcs.git.agent.command.ShowRefResult) GitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine) VcsException(jetbrains.buildServer.vcs.VcsException) ExecResult(jetbrains.buildServer.ExecResult) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ShowRefResult

use of jetbrains.buildServer.buildTriggers.vcs.git.agent.command.ShowRefResult 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();
}
Also used : ShowRefResult(jetbrains.buildServer.buildTriggers.vcs.git.agent.command.ShowRefResult) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Aggregations

ShowRefResult (jetbrains.buildServer.buildTriggers.vcs.git.agent.command.ShowRefResult)2 File (java.io.File)1 ExecResult (jetbrains.buildServer.ExecResult)1 GitCommandLine (jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine)1 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)1 VcsException (jetbrains.buildServer.vcs.VcsException)1 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)1 NotNull (org.jetbrains.annotations.NotNull)1