@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); } }
public static void reconfigure(GitBasedRepositoryConfiguration gitBasedRepositoryConfiguration) throws IOException, GitAPIException { RepositoryFactory.gitBasedRepositoryConfiguration = gitBasedRepositoryConfiguration; RepositoryFactory.fileBasedRepositoryConfiguration = null; RepositoryFactory.jCloudsConfiguration = null; repository = new GitBasedRepository(gitBasedRepositoryConfiguration); }
if (data.reset) { try { ((GitBasedRepository) RepositoryFactory.getRepository()).cleanAndResetHard(); writeInSession(session, "{ \"success\": \"Successfully reset the workingtree!\" }"); ((GitBasedRepository) RepositoryFactory.getRepository()).postEventMap(); } catch (GitAPIException e) { LOGGER.warn("Git reset failed", e); repository.getStatus().getAdded(), repository.getStatus().getUntracked(), repository.getStatus().getModified()); list.toArray(patterns); repository.addCommit(patterns, data.commitMessage); } else { repository.addCommit(data.commitMessage); ((GitBasedRepository) RepositoryFactory.getRepository()).postEventMap();
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!"); } } }
/** * 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); }
boolean changesInFile = gitRepo.hasChangesInFile(BackendUtils.getRefOfDefinitions(id));
public void addCommit(String[] patterns, String message) throws GitAPIException { if (!message.isEmpty()) { synchronized (COMMIT_LOCK) { AddCommand add = this.git.add(); Status status = this.git.status().call(); for (String pattern : patterns) { add.addFilepattern(pattern); } if (!status.getMissing().isEmpty() || !status.getRemoved().isEmpty()) { RmCommand remove = this.git.rm(); for (String file : Iterables.concat(status.getMissing(), status.getRemoved())) { remove.addFilepattern(file); } remove.call(); } add.call(); CommitCommand commit = this.git.commit(); commit.setMessage(message); commit.call(); } } postEventMap(); }
public void cleanAndResetHard() throws NoWorkTreeException, GitAPIException { // enable updating by resetting the content of the repository this.clean(); // reset to the latest version ResetCommand reset = this.git.reset(); reset.setMode(ResetType.HARD); reset.call(); }
/** * Initialization code for the repository. Should go into separate class, but being here should be OK for a * prototype * <p> * Called from both the constructor for JUnit and the servlet-based initialization * <p> * Pre-Condition: Environment is loaded */ private void doRepositoryInitialization() throws Exception { RepositoryFactory.reconfigure(); if (RepositoryFactory.getRepository() instanceof GitBasedRepository) { GitWebSocket socket = new GitWebSocket(); ((GitBasedRepository) RepositoryFactory.getRepository()).registerForEvents(socket); } }
/** * 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); } }
if (repo instanceof GitBasedRepository && ((GitBasedRepository) repo).hasChangesInFile(BackendUtils.getRefOfDefinitions(oldId))) { try { repo.rename(oldId, id);
public void setRevisionTo(String ref) throws GitAPIException { this.clean(); // reset repository to the desired reference ResetCommand reset = this.git.reset(); reset.setMode(ResetType.HARD); reset.setRef(ref); reset.call(); }
/** * @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."); } }