use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class CleanCommandImpl method call.
public void call() throws VcsException {
GitCommandLine cmd = getCmd();
cmd.addParameters("clean", "-f", "-d");
switch(myCleanPolicy) {
case ALL_UNTRACKED:
cmd.addParameter("-x");
break;
case IGNORED_ONLY:
cmd.addParameter("-X");
break;
case NON_IGNORED_ONLY:
break;
}
addExcludes(cmd);
cmd.withMaxOutputSize(8 * 1024 * 1024);
try {
CommandUtil.runCommand(cmd.stdErrExpected(false));
} catch (VcsException e) {
Loggers.VCS.warnAndDebugDetails("Failed to clean files", e);
if (!SystemInfo.isWindows || CommandUtil.isCanceledError(e)) {
throw e;
}
if (CommandUtil.isNoSuchFileOrDirError(e)) {
throw new VcsException("Some files may be locked: " + e.getMessage(), e);
}
final File workingDir = cmd.getWorkingDirectory();
if (workingDir == null) {
throw e;
}
if (CommandUtil.isFileNameTooLongError(e)) {
handleLongFileNames(workingDir, e);
}
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class CommandLineUtil method getCommandLineError.
@Nullable
public static VcsException getCommandLineError(@NotNull String cmdName, @NotNull String details, @NotNull ExecResult res, boolean includeStdOut, boolean includeStdErr) {
// noinspection ThrowableResultOfMethodCallIgnored
Throwable exception = res.getException();
int exitCode = res.getExitCode();
if (exitCode != 0 || exception != null) {
String stderr = res.getStderr();
String stdout = res.getStdout();
final String message = "'" + cmdName + "' command failed" + details + "." + (exception != null ? "\nexception: " + exception.toString() : "") + (includeStdErr && !StringUtil.isEmpty(stderr) ? "\nstderr: " + stderr.trim() : "") + (includeStdOut && !StringUtil.isEmpty(stdout) ? "\nstdout: " + stdout.trim() : "") + (res.getElapsedTime() != -1 ? "\nelapsed time: " + TimePrinter.createMillisecondsFormatter().formatTime(res.getElapsedTime()) : "") + (exitCode != 0 ? "\nexit code: " + exitCode : "");
return exception == null ? new VcsException(message) : new VcsException(message, exception);
} else {
return null;
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitUtils method getGitDir.
public static File getGitDir(@NotNull File workingTreeDir) throws IOException, VcsException {
File dotGit = new File(workingTreeDir, ".git");
if (dotGit.isFile()) {
List<String> content = FileUtil.readFile(dotGit);
if (content.isEmpty())
throw new VcsException("Empty " + dotGit.getAbsolutePath());
String line = content.get(0);
if (!line.startsWith("gitdir:"))
throw new VcsException("Wrong format of " + dotGit.getAbsolutePath() + ": " + content);
String gitDirPath = line.substring("gitdir:".length()).trim();
File gitDir = new File(gitDirPath);
if (gitDir.isAbsolute())
return gitDir;
return new File(workingTreeDir, gitDirPath);
}
return dotGit;
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitCommandLine method withAskPassScript.
private void withAskPassScript(@Nullable String pass, @NotNull Consumer<String> action) throws VcsException {
File askPass = null;
String askPassPath;
try {
askPass = myScriptGen.generateAskPass(pass);
askPassPath = askPass.getAbsolutePath();
if (askPassPath.contains(" ") && SystemInfo.isWindows) {
askPassPath = GitUtils.getShortFileName(askPass);
}
action.accept(askPassPath);
} catch (Exception e) {
if (askPass != null) {
FileUtil.delete(askPass);
}
throw new VcsException(e);
}
final File finalAskPass = askPass;
addPostAction(() -> {
if (myCtx.isDeleteTempFiles())
FileUtil.delete(finalAskPass);
});
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitServerUtil method getRepository.
/**
* Ensures that a bare repository exists at the specified path.
* If it does not, the directory is attempted to be created.
*
* @param dir the path to the directory to init
* @param remote the remote URL
* @return a connection to repository
* @throws VcsException if the there is a problem with accessing VCS
*/
public static Repository getRepository(@NotNull final File dir, @NotNull final URIish remote) throws VcsException {
if (dir.exists() && !dir.isDirectory()) {
throw new VcsException("The specified path is not a directory: " + dir);
}
try {
ensureRepositoryIsValid(dir);
Repository r = getRepositoryWithDisabledAutoGc(dir);
String remoteUrl = remote.toString();
if (remoteUrl.contains("\n") || remoteUrl.contains("\r"))
throw new VcsException("Newline in url '" + remoteUrl + "'");
if (!new File(dir, "config").exists()) {
r.create(true);
addConfigOptions(r.getConfig(), remoteUrl).save();
} else {
final StoredConfig config = r.getConfig();
final String existingRemote = config.getString("teamcity", null, "remote");
final String refSpec = config.getString("remote", "origin", "fetch");
final String mirror = config.getString("remote", "origin", "mirror");
if (existingRemote != null && !remoteUrl.equals(existingRemote)) {
throw getWrongUrlError(dir, existingRemote, remote);
} else if (existingRemote == null || refSpec == null || mirror != null) {
addConfigOptions(config, remoteUrl).save();
}
}
return r;
} catch (Exception ex) {
if (ex instanceof NullPointerException)
LOG.warn("The repository at directory '" + dir + "' cannot be opened or created", ex);
throw new VcsException("The repository at directory '" + dir + "' cannot be opened or created, reason: " + ex.toString(), ex);
}
}
Aggregations