/** {@inheritDoc} */ @Override public String getMessage() { return MessageFormat.format(JGitText.get().commandRejectedByHook, hookName, super.getMessage()); } }
@Override public boolean isDirty() throws GitCommitIdExecutionException { try { return JGitCommon.isRepositoryInDirtyState(git); } catch (GitAPIException e) { throw new GitCommitIdExecutionException("Failed to get git status: " + e.getMessage(), e); } }
/** * Init git repo with bare * * @param gitPath xxx.git folder * @throws GitException */ public static void init(Path gitPath, boolean bare) throws GitException { try { if (bare) { Git.init().setBare(bare).setGitDir(gitPath.toFile()).call(); } else { Git.init().setDirectory(gitPath.toFile()).call(); } } catch (GitAPIException e) { throw new GitException(e.getMessage()); } }
/** {@inheritDoc} */ @Override public String getMessage() { return MessageFormat.format(JGitText.get().commandRejectedByHook, hookName, super.getMessage()); } }
@Override public String getMessage() { return MessageFormat.format(JGitText.get().commandRejectedByHook, hookName, super.getMessage()); } }
public Status getStatus() { try { return this.git.status().call(); } catch (GitAPIException e) { LOGGER.trace(e.getMessage(), e); return null; } } }
@Override public boolean isDirty() throws GitCommitIdExecutionException { try { return JGitCommon.isRepositoryInDirtyState(git); } catch (GitAPIException e) { throw new GitCommitIdExecutionException("Failed to get git status: " + e.getMessage(), e); } }
@Override public Ref switchBranch(final Git repo, final String branchName) { try { return repo.checkout().setName(branchName).call(); } catch (GitAPIException e) { throw new RuntimeException("Couldn't switch to branch " + branchName + ": " + e.getMessage(), e); } }
@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); } }
private Git gitClone(File dir) { Git git = gitOpen(dir); if (git != null) { log.info("already cloned ..."); return git; } CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(repo); cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); cloneCommand.setDirectory(dir); try { cloneCommand.call(); } catch (GitAPIException e) { log.error(e.getMessage(), e); } return gitOpen(dir); }
@Override public byte[] addContentToExploded(byte[] deploymentHash, List<ExplodedContent> addFiles, boolean overwrite) throws ExplodedContentException { byte[] result = super.addContentToExploded(deploymentHash, addFiles, overwrite); if (!Arrays.equals(deploymentHash, result)) { final Path realFile = getDeploymentContentFile(result, true); try (Git git = gitRepository.getGit()) { git.add().addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new ExplodedContentException(ex.getMessage(), ex); } } return result; }
@Override public byte[] addContentToExploded(byte[] deploymentHash, List<ExplodedContent> addFiles, boolean overwrite) throws ExplodedContentException { byte[] result = super.addContentToExploded(deploymentHash, addFiles, overwrite); if (!Arrays.equals(deploymentHash, result)) { final Path realFile = getDeploymentContentFile(result, true); try (Git git = gitRepository.getGit()) { git.add().addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new ExplodedContentException(ex.getMessage(), ex); } } return result; }
@Override public byte[] removeContentFromExploded(byte[] deploymentHash, List<String> paths) throws ExplodedContentException { byte[] result = super.removeContentFromExploded(deploymentHash, paths); if (!Arrays.equals(deploymentHash, result)) { final Path realFile = getDeploymentContentFile(result, true); try (Git git = gitRepository.getGit()) { git.add().addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new ExplodedContentException(ex.getMessage(), ex); } } return result; }
@Override public byte[] explodeSubContent(byte[] deploymentHash, String relativePath) throws ExplodedContentException { byte[] result = super.explodeSubContent(deploymentHash, relativePath); if (!Arrays.equals(deploymentHash, result)) { final Path realFile = getDeploymentContentFile(result, true); try (Git git = gitRepository.getGit()) { git.add().addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new ExplodedContentException(ex.getMessage(), ex); } } return result; }
@Override public byte[] explodeContent(byte[] deploymentHash) throws ExplodedContentException { byte[] result = super.explodeContent(deploymentHash); if (!Arrays.equals(deploymentHash, result)) { final Path realFile = getDeploymentContentFile(result, true); try (Git git = gitRepository.getGit()) { git.add().addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new ExplodedContentException(ex.getMessage(), ex); } } return result; }
@Override public byte[] explodeSubContent(byte[] deploymentHash, String relativePath) throws ExplodedContentException { byte[] result = super.explodeSubContent(deploymentHash, relativePath); if (!Arrays.equals(deploymentHash, result)) { final Path realFile = getDeploymentContentFile(result, true); try (Git git = gitRepository.getGit()) { git.add().addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new ExplodedContentException(ex.getMessage(), ex); } } return result; }
@Override public byte[] removeContentFromExploded(byte[] deploymentHash, List<String> paths) throws ExplodedContentException { byte[] result = super.removeContentFromExploded(deploymentHash, paths); if (!Arrays.equals(deploymentHash, result)) { final Path realFile = getDeploymentContentFile(result, true); try (Git git = gitRepository.getGit()) { git.add().addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new ExplodedContentException(ex.getMessage(), ex); } } return result; }
@Override public byte[] explodeContent(byte[] deploymentHash) throws ExplodedContentException { byte[] result = super.explodeContent(deploymentHash); if (!Arrays.equals(deploymentHash, result)) { final Path realFile = getDeploymentContentFile(result, true); try (Git git = gitRepository.getGit()) { git.add().addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new ExplodedContentException(ex.getMessage(), ex); } } return result; }
public static GitException buildErrorOnReference(GitAPIException e, String reference) { if (e instanceof RefAlreadyExistsException) { return new GitException("A reference <" + reference + "> already exist.", e.getCause()); } else if (e instanceof InvalidRefNameException) { return new GitException("The reference <" + reference + "> is invalid.", e.getCause()); } else if (e instanceof RefNotFoundException) { return new GitException("The reference <" + reference + "> is not found.", e.getCause()); } else { return new GitException(e.getMessage()); } } }
public void stageAndPushDeletedFile() { try { Git git = this.gitOpen(gitDir); git.add().addFilepattern(".").setUpdate(true).call(); git.commit().setMessage("wipe").call(); PushCommand command = git.push().setForce(true); command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); command.call(); } catch (GitAPIException e) { log.error(e.getMessage(), e); } }