use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitHubRawFileContentProvider method getContent.
@NotNull
public byte[] getContent(@NotNull String filePath, @NotNull VcsRoot root, @NotNull String version) throws VcsException {
OperationContext ctx = myVcs.createContext(root, "retrieving content");
InputStream is = null;
try {
URLConnection conn = getConnection(ctx.getGitRoot(), filePath, version);
is = conn.getInputStream();
return readStream(is);
} catch (Exception e) {
// LOG
return myGenericProvider.getContent(filePath, root, version);
} finally {
ctx.close();
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class UpdaterWithMirror method updateLocalMirror.
protected void updateLocalMirror(File bareRepositoryDir, CommonURIish fetchUrl, Ref... revisions) throws VcsException {
final boolean isSubmodule = !isRootRepositoryDir(bareRepositoryDir);
String mirrorDescription = (isSubmodule ? "submodule " : "") + "local mirror of root " + myRoot.getName() + " at " + bareRepositoryDir;
LOG.info("Update " + mirrorDescription);
if (isValidGitRepo(bareRepositoryDir)) {
removeOrphanedIdxFiles(bareRepositoryDir);
} else {
FileUtil.delete(bareRepositoryDir);
}
final AgentGitFacade git = myGitFactory.create(bareRepositoryDir);
final SSLInvestigator sslInvestigator = getSSLInvestigator(fetchUrl);
boolean fetchRequired;
if (!bareRepositoryDir.exists()) {
LOG.info("Init " + mirrorDescription);
bareRepositoryDir.mkdirs();
git.init().setBare(true).call();
configureRemoteUrl(bareRepositoryDir, fetchUrl);
sslInvestigator.setCertificateOptions(git);
fetchRequired = true;
} else {
configureRemoteUrl(bareRepositoryDir, fetchUrl);
sslInvestigator.setCertificateOptions(git);
fetchRequired = removeOutdatedRefs(bareRepositoryDir);
}
final AgentCommitLoader commitLoader = isSubmodule ? AgentCommitLoaderFactory.getCommitLoaderForSubmodule(myRoot, myBuild, bareRepositoryDir, myGitFactory, myPluginConfig, myLogger) : AgentCommitLoaderFactory.getCommitLoaderForMirror(myRoot, myBuild, bareRepositoryDir, myGitFactory, myPluginConfig, myLogger);
try {
loadCommits(fetchRequired, commitLoader, revisions);
} catch (VcsException e) {
if (myPluginConfig.isFailOnCleanCheckout() || !CommandUtil.shouldFetchFromScratch(e)) {
throw e;
}
LOG.warnAndDebugDetails("Failed to fetch mirror, will try removing it and cloning from scratch", e);
if (cleanDir(bareRepositoryDir)) {
git.init().setBare(true).call();
configureRemoteUrl(bareRepositoryDir, fetchUrl);
sslInvestigator.setCertificateOptions(git);
loadCommits(true, commitLoader, revisions);
} else {
LOG.info("Failed to delete repository " + bareRepositoryDir + " after failed checkout, clone repository in another directory");
myMirrorManager.invalidate(bareRepositoryDir);
updateLocalMirror(myMirrorManager.getMirrorDir(fetchUrl.toString()), fetchUrl, revisions);
}
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class CheckoutDirectoryCleaner method runGitCommand.
// protected for tests
protected void runGitCommand(@NotNull File repo, @NotNull String pathToGit, @NotNull String cmdName, int timeout, @NotNull String... params) {
final String cmd = " '" + cmdName + "' in repo " + repo.getAbsolutePath();
try {
final GeneralCommandLine cl = new GeneralCommandLine();
cl.setWorkingDirectory(repo);
cl.setExePath(pathToGit);
cl.addParameters(params);
final long start = System.currentTimeMillis();
ExecResult result = SimpleCommandLineProcessRunner.runCommand(cl, null, new SimpleCommandLineProcessRunner.ProcessRunCallback() {
@Override
public void onProcessStarted(@NotNull Process ps) {
LOG.debug("Start" + cmd);
}
@Override
public void onProcessFinished(@NotNull Process ps) {
final long finish = System.currentTimeMillis();
LOG.debug("Finish" + cmd + ", duration: " + (finish - start) + "ms");
}
@Override
public Integer getOutputIdleSecondsTimeout() {
return timeout;
}
@Override
public Integer getMaxAcceptedOutputSize() {
return COMMAND_OUTPUT_THRESHOLD;
}
@Override
public boolean terminateEntireProcessTree() {
return false;
}
});
final VcsException commandError = CommandLineUtil.getCommandLineError(cmd, result);
if (commandError != null) {
LOG.warnAndDebugDetails("Error while running" + cmd, commandError);
}
if (result.getStderr().length() > 0) {
LOG.debug("Output produced by" + cmd);
LOG.debug(result.getStderr());
}
} catch (Exception e) {
LOG.debug("Error while running" + cmd, e);
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class AgentMirrorCleaner method getRunningBuildRepositories.
private Set<String> getRunningBuildRepositories(@NotNull DirectoryCleanersProviderContext context) {
Set<String> repositories = new HashSet<String>();
for (VcsRootEntry entry : context.getRunningBuild().getVcsRootEntries()) {
VcsRoot root = entry.getVcsRoot();
if (!Constants.VCS_NAME.equals(root.getVcsName()))
continue;
try {
GitVcsRoot gitRoot = new AgentGitVcsRoot(myMirrorManager, root, myTokenStorage);
String repositoryUrl = gitRoot.getRepositoryFetchURL().toString();
LOG.debug("Repository " + repositoryUrl + " is used in the build, its mirror won't be cleaned");
addRepositoryWithSubmodules(repositories, gitRoot.getRepositoryFetchURL().toString());
} catch (VcsException e) {
LOG.warn("Error while creating git root " + root.getName() + ". If the root has a mirror on agent, the mirror might be cleaned", e);
}
}
return repositories;
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class RemoteRepositoryConfigurator method configure.
/**
* Configures and save the remote repository for specified VCS root
* @param fetchUrl fetchUrl remote repository URL
* @throws VcsException in case of any error
*/
public void configure(@NotNull CommonURIish fetchUrl) throws VcsException {
File gitDir = getGitDir();
Repository repository = null;
try {
repository = new RepositoryBuilder().setGitDir(gitDir).build();
StoredConfig config = repository.getConfig();
String scheme = fetchUrl.getScheme();
String user = fetchUrl.getUser();
if (myExcludeUsernameFromHttpUrls && isHttp(scheme) && !StringUtil.isEmpty(user)) {
URIish fetchUrlNoUser = ((URIish) fetchUrl.get()).setUser(null);
config.setString("remote", "origin", "url", fetchUrlNoUser.toString());
config.setString("credential", null, "username", user);
} else {
config.setString("remote", "origin", "url", fetchUrl.toString());
config.unset("credential", null, "username");
}
config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
config.save();
} catch (Exception e) {
throw new VcsException("Error while configuring remote repository at " + gitDir + ": " + e.getMessage(), e);
} finally {
if (repository != null)
repository.close();
}
}
Aggregations