/** * Set the reset mode * * @param mode * the mode of the reset command * @return this instance */ public ResetCommand setMode(ResetType mode) { if (!filepaths.isEmpty()) throw new JGitInternalException(MessageFormat.format( JGitText.get().illegalCombinationOfArguments, "[--mixed | --soft | --hard]", "<paths>...")); //$NON-NLS-1$ //$NON-NLS-2$ this.mode = mode; return this; }
@Override public Ref call() throws GitAPIException { JGitInternalException lastException = null; for (int i=0; i<5; i++) { try { return super.call(); } catch (JGitInternalException e) { if (!e.getMessage().toLowerCase().contains("Could not rename file")) { throw e; } else { lastException = e; } try { Thread.sleep(250); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } } } if (lastException != null) { throw lastException; } else { return null; } }
throw new GitException("Could not reset the workspace before checkout of " + ref, e); } catch (JGitInternalException e) { if (e.getCause() instanceof LockFailedException){ throw new GitLockFailedException("Could not lock repository. Please try again", e); } else { throw new GitException("Could not checkout " + ref, e); } catch (JGitInternalException e) { if (Pattern.matches("Cannot lock.+", e.getMessage())){ throw new GitLockFailedException("Could not lock repository. Please try again", e); } else {
e.printStackTrace(); } catch (JGitInternalException e) { e.printStackTrace();
@Override public Ref call() throws GitAPIException { JGitInternalException lastException = null; for (int i=0; i<5; i++) { try { return super.call(); } catch (JGitInternalException e) { if (!e.getMessage().toLowerCase().contains("Could not rename file")) { throw e; } else { lastException = e; } try { Thread.sleep(250); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } } } if (lastException != null) { throw lastException; } else { return null; } }
/** * Repository relative path of file or directory to reset * * @param path * repository-relative path of file/directory to reset (with * <code>/</code> as separator) * @return this instance */ public ResetCommand addPath(String path) { if (mode != null) throw new JGitInternalException(MessageFormat.format( JGitText.get().illegalCombinationOfArguments, "<paths>...", //$NON-NLS-1$ "[--mixed | --soft | --hard]")); //$NON-NLS-1$ filepaths.add(path); return this; }
log.warn("Git pull unsuccessful for tenant " + gitRepoCtx.getTenantId() + ", " + e.getMessage()); return false;
private boolean isMergeDuringRebase(RepositoryState state) { if (state != RepositoryState.REBASING_INTERACTIVE && state != RepositoryState.REBASING_MERGE) return false; try { return repo.readMergeHeads() != null; } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_HEAD, e), e); } }
commit = commitCmd.call(); } catch (JGitInternalException e) { throw die(e.getMessage());
private void deleteRef(Ref stashRef) { try { Result result = createRefUpdate(stashRef).delete(); if (Result.FORCED != result) throw new JGitInternalException(MessageFormat.format( JGitText.get().stashDropDeleteRefFailed, result)); } catch (IOException e) { throw new JGitInternalException(JGitText.get().stashDropFailed, e); } }
/** * Commit dedicated path only. * <p> * This method can be called several times to add multiple paths. Full file * paths are supported as well as directory paths; in the latter case this * commits all files/directories below the specified path. * * @param only * path to commit (with <code>/</code> as separator) * @return {@code this} */ public CommitCommand setOnly(String only) { checkCallable(); if (all) throw new JGitInternalException(MessageFormat.format( JGitText.get().illegalCombinationOfArguments, "--only", //$NON-NLS-1$ "--all")); //$NON-NLS-1$ String o = only.endsWith("/") ? only.substring(0, only.length() - 1) //$NON-NLS-1$ : only; // ignore duplicates if (!this.only.contains(o)) this.only.add(o); return this; }
void verifyDirectories(URIish u) { if (directory == null && gitDir == null) { directory = new File(u.getHumanishName() + (bare ? Constants.DOT_GIT_EXT : "")); //$NON-NLS-1$ } directoryExistsInitially = directory != null && directory.exists(); gitDirExistsInitially = gitDir != null && gitDir.exists(); validateDirs(directory, gitDir, bare); if (isNonEmptyDirectory(directory)) { throw new JGitInternalException(MessageFormat.format( JGitText.get().cloneNonEmptyDirectory, directory.getName())); } if (isNonEmptyDirectory(gitDir)) { throw new JGitInternalException(MessageFormat.format( JGitText.get().cloneNonEmptyDirectory, gitDir.getName())); } }
private void checkParameters() throws InvalidMergeHeadsException { if (squash.booleanValue() && fastForwardMode == FastForwardMode.NO_FF) { throw new JGitInternalException( JGitText.get().cannotCombineSquashWithNoff); } if (commits.size() != 1) throw new InvalidMergeHeadsException( commits.isEmpty() ? JGitText.get().noMergeHeadSpecified : MessageFormat.format( JGitText.get().mergeStrategyDoesNotSupportHeads, mergeStrategy.getName(), Integer.valueOf(commits.size()))); }
/** * If set to true the Commit command automatically stages files that have * been modified and deleted, but new files not known by the repository are * not affected. This corresponds to the parameter -a on the command line. * * @param all * whether to auto-stage all files that have been modified and * deleted * @return {@code this} * @throws JGitInternalException * in case of an illegal combination of arguments/ options */ public CommitCommand setAll(boolean all) { checkCallable(); if (all && !only.isEmpty()) throw new JGitInternalException(MessageFormat.format( JGitText.get().illegalCombinationOfArguments, "--all", //$NON-NLS-1$ "--only")); //$NON-NLS-1$ this.all = all; return this; }
/** * Recursively delete the *contents* of path, but leave path as an empty * directory * * @param path * the path to clean * @throws IOException */ private void deinit(String path) throws IOException { File dir = new File(repo.getWorkTree(), path); if (!dir.isDirectory()) { throw new JGitInternalException(MessageFormat.format( JGitText.get().expectedDirectoryNotSubmodule, path)); } final File[] ls = dir.listFiles(); if (ls != null) { for (int i = 0; i < ls.length; i++) { FileUtils.delete(ls[i], RECURSIVE); } } }
private void checkoutPath(DirCacheEntry entry, ObjectReader reader, CheckoutMetadata checkoutMetadata) { try { DirCacheCheckout.checkoutEntry(repo, entry, reader, true, checkoutMetadata); } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( JGitText.get().checkoutConflictWithFile, entry.getPathString()), e); } } }
private void checkoutPath(DirCacheEntry entry, ObjectReader reader, CheckoutMetadata checkoutMetadata) { try { DirCacheCheckout.checkoutEntry(repo, entry, reader, true, checkoutMetadata); } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( JGitText.get().checkoutConflictWithFile, entry.getPathString()), e); } }
/** * {@inheritDoc} * <p> * Executes the {@code remote} command with all the options and parameters * collected by the setter methods of this class. */ @Override public List<RemoteConfig> call() throws GitAPIException { checkCallable(); try { return RemoteConfig.getAllRemoteConfigs(repo.getConfig()); } catch (URISyntaxException e) { throw new JGitInternalException(e.getMessage(), e); } }
private boolean autoGcBlockedByOldLockFile() { try { FileTime lastModified = Files.getLastModifiedTime(FileUtils.toPath(logFile)); if (lastModified.toInstant().compareTo(getLogExpiry()) > 0) { // There is an existing log file, which is too recent to ignore return true; } } catch (NoSuchFileException e) { // No existing log file, OK. } catch (IOException | ParseException e) { throw new JGitInternalException(e.getMessage(), e); } return false; }