private void deleteBaseDirIfExists() { if (getBasedir().exists()) { for (File file : getBasedir().listFiles()) { try { FileUtils.delete(file, FileUtils.RECURSIVE); } catch (IOException e) { throw new IllegalStateException("Failed to initialize base directory", e); } } } }
private synchronized Git copyRepository() throws IOException, GitAPIException { deleteBaseDirIfExists(); getBasedir().mkdirs(); Assert.state(getBasedir().exists(), "Could not create basedir: " + getBasedir()); if (getUri().startsWith(FILE_URI_PREFIX)) { return copyFromLocalRepository(); } else { return cloneToBasedir(); } }
private JGitEnvironmentRepository getRepository(JGitEnvironmentRepository source, String uri) { JGitEnvironmentRepository repository = new JGitEnvironmentRepository(null, new JGitEnvironmentProperties()); File basedir = repository.getBasedir(); BeanUtils.copyProperties(source, repository); repository.setUri(uri); repository.setBasedir( new File(source.getBasedir().getParentFile(), basedir.getName())); return repository; }
private Git cloneToBasedir() throws GitAPIException { CloneCommand clone = this.gitFactory.getCloneCommandByCloneRepository() .setURI(getUri()).setDirectory(getBasedir()); configureCommand(clone); try { return clone.call(); } catch (GitAPIException e) { logger.warn("Error occured cloning to base directory.", e); deleteBaseDirIfExists(); throw e; } }