/** * This method is synchronized with an extra static object (meaning all instances are locked). The same lock object * is also used in {@link #addCommit(RepositoryFileReference)}. This is to ensure that every commit only has one * change. * * @param message The message that is used in the commit. * @throws GitAPIException thrown when anything with adding or committing goes wrong. */ public void addCommit(String message) throws GitAPIException { addCommit(new String[] {"."}, message); }
/** * This method is synchronized with an extra static object (meaning all instances are locked). The same lock object * is also used in {@link #addCommit(String)}. This is to ensure that every commit only has one change. * * @param ref RepositoryFileReference to the file that was changed. * @throws GitAPIException thrown when anything with adding or committing goes wrong. */ public void addCommit(RepositoryFileReference ref) throws GitAPIException { synchronized (COMMIT_LOCK) { String message; if (ref == null) { message = "Files changed externally."; } else { message = ref.toString() + " was updated"; } addCommit(message); } }
public static void commit(DefinitionsChildId componentToCommit, String commitMessagePrefix) throws GitAPIException { if (RepositoryFactory.getRepository() instanceof GitBasedRepository) { GitBasedRepository gitRepo = (GitBasedRepository) RepositoryFactory.getRepository(); List<String> filePatternsToCommit = new ArrayList<>(); if (gitRepo.hasChangesInFile(BackendUtils.getRefOfDefinitions(componentToCommit))) { /*WineryVersion predecessor = BackendUtils.getPredecessor(componentToCommit); ToscaDiff diff = BackendUtils.compare(componentToCommit, predecessor); String changeLog = diff.getChangeLog(); // get changelog.md and append changeLog*/ filePatternsToCommit.add(Util.getPathInsideRepo(componentToCommit)); gitRepo.addCommit(filePatternsToCommit.toArray(new String[filePatternsToCommit.size()]), commitMessagePrefix + " " + componentToCommit.getQName()); } } else { throw new RuntimeException("Repository does not support git!"); } } }
@Override public void putContentToFile(RepositoryFileReference ref, InputStream inputStream, MediaType mediaType) throws IOException { super.putContentToFile(ref, inputStream, mediaType); try { if (gitBasedRepositoryConfiguration.isAutoCommit()) { this.addCommit(ref); } else { postEventMap(); } } catch (GitAPIException e) { LOGGER.trace(e.getMessage(), e); } }
/** * @param gitBasedRepositoryConfiguration the configuration of the repository * @throws IOException thrown if repository does not exist * @throws GitAPIException thrown if there was an error while checking the status of the repository * @throws NoWorkTreeException thrown if the directory is not a git work tree */ public GitBasedRepository(GitBasedRepositoryConfiguration gitBasedRepositoryConfiguration) throws IOException, NoWorkTreeException, GitAPIException { super(Objects.requireNonNull(gitBasedRepositoryConfiguration)); this.gitBasedRepositoryConfiguration = gitBasedRepositoryConfiguration; FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository gitRepo = builder.setWorkTree(this.repositoryRoot.toFile()).setMustExist(false).build(); if (!Files.exists(this.repositoryRoot.resolve(".git"))) { gitRepo.create(); } // explicitly enable longpaths to ensure proper handling of long pathss gitRepo.getConfig().setBoolean("core", null, "longpaths", true); gitRepo.getConfig().save(); this.eventBus = new EventBus(); this.git = new Git(gitRepo); if (gitBasedRepositoryConfiguration.isAutoCommit() && !this.git.status().call().isClean()) { this.addCommit("Files changed externally."); } }