use of alien4cloud.exception.GitException in project alien4cloud by alien4cloud.
the class RepositoryManager method renameBranches.
public static void renameBranches(Path repositoryDirectory, Map<String, String> branchOldNameToNewName) {
Git git = null;
try {
git = Git.open(repositoryDirectory.toFile());
for (Map.Entry<String, String> entry : branchOldNameToNewName.entrySet()) {
String oldBranchName = entry.getKey();
String newBranchName = entry.getValue();
if (branchExistsLocally(git, oldBranchName)) {
git.branchRename().setOldName(oldBranchName).setNewName(newBranchName).call();
}
}
} catch (IOException | GitAPIException e) {
throw new GitException("Unable to rename all branches", e);
} finally {
close(git);
}
}
use of alien4cloud.exception.GitException in project alien4cloud by alien4cloud.
the class RepositoryManager method pull.
/**
* Trigger a Pull Request on an existing repository.
*
* @param repository The git repository to pull.
* @param username The username to use for the repository connection.
* @param password The password to use for the repository connection.
* @return True if the pull request has updated the data, false if the repository was already up to date.
*/
public static boolean pull(Git repository, String username, String password) {
try {
PullCommand pullCommand = repository.pull();
setCredentials(pullCommand, username, password);
PullResult result = pullCommand.call();
MergeResult mergeResult = result.getMergeResult();
return mergeResult == null || MergeResult.MergeStatus.ALREADY_UP_TO_DATE != mergeResult.getMergeStatus();
} catch (GitAPIException e) {
throw new GitException("Failed to pull git repository", e);
}
}
use of alien4cloud.exception.GitException in project alien4cloud by alien4cloud.
the class RepositoryManager method cloneOrCheckout.
/**
* @param targetDirectory The root directory that will contains the localDirectory in which to checkout the archives.
* @param repositoryUrl The url of the repository to checkout or clone.
* @param username The username to use for the repository connection.
* @param password The password to use for the repository connection.
* @param branch The branch to checkout or clone.
* @param localDirectory The path, relative to targetDirectory, in which to checkout or clone the git directory.
*/
public static Git cloneOrCheckout(Path targetDirectory, String repositoryUrl, String username, String password, String branch, String localDirectory) {
try {
Files.createDirectories(targetDirectory);
Path targetPath = targetDirectory.resolve(localDirectory);
Git repository;
if (Files.exists(targetPath)) {
try {
repository = Git.open(targetPath.toFile());
fetch(repository, username, password);
checkoutRepository(repository, branch);
} catch (RepositoryNotFoundException e) {
// TODO delete the folder
FileUtil.delete(targetPath);
repository = cloneRepository(repositoryUrl, username, password, branch, targetPath);
}
} else {
Files.createDirectories(targetPath);
repository = cloneRepository(repositoryUrl, username, password, branch, targetPath);
}
return repository;
} catch (IOException e) {
throw new GitException("Error while creating target directory", e);
}
}
use of alien4cloud.exception.GitException in project alien4cloud by alien4cloud.
the class RepositoryManager method commitAll.
/**
* Commit all changes in the given repository.
*
* @param targetDirectory The target directory.
*/
public static void commitAll(Path targetDirectory, String userName, String userEmail, String commitMessage) {
Git repository = null;
try {
repository = Git.open(targetDirectory.toFile());
repository.add().addFilepattern(".").call();
String name = defaultUsernameIfNull(userName);
String email = defaultEmailIfNull(name, userEmail);
repository.commit().setCommitter(name, email).setMessage(commitMessage).call();
} catch (GitAPIException | IOException e) {
throw new GitException("Unable to commit to the git repository", e);
} finally {
close(repository);
}
}
use of alien4cloud.exception.GitException in project alien4cloud by alien4cloud.
the class DeploymentConfigurationDao method deleteAllByTopologyVersionId.
public void deleteAllByTopologyVersionId(String applicationId, String versionId) {
// delete local branch + related stash
List<Path> paths = localGitRepositoryPathResolver.findAllEnvironmentSetupLocalPath(applicationId);
for (Path path : paths) {
try {
RepositoryManager.dropStash(path, "a4c_stash_" + versionId);
RepositoryManager.deleteBranch(path, versionId, false);
} catch (GitException e) {
log.error("Error when deleting data related to the topology version <" + versionId + "> from local git.", e);
}
}
}
Aggregations