/** * 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; }
/** * 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; }
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); } }
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); } }
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()))); }
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; }
private void updateRef(Ref stashRef, ObjectId newId) { try { RefUpdate update = createRefUpdate(stashRef); update.setNewObjectId(newId); Result result = update.update(); switch (result) { case FORCED: case NEW: case NO_CHANGE: return; default: throw new JGitInternalException(MessageFormat.format( JGitText.get().updatingRefFailed, R_STASH, newId, result)); } } catch (IOException e) { throw new JGitInternalException(JGitText.get().stashDropFailed, e); } }
private RevCommit parseCommit(ObjectId commitId) { try (RevWalk rw = new RevWalk(repo)) { return rw.parseCommit(commitId); } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( JGitText.get().cannotReadCommit, commitId.toString()), e); } }
private ObjectId getObjectIdFromRef(Ref r) throws JGitInternalException { try { ObjectId key = repo.getRefDatabase().peel(r).getPeeledObjectId(); if (key == null) { key = r.getObjectId(); } return key; } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } }
private ObjectId resolveRefToCommitId() { try { return repo.resolve(getRefOrHEAD() + "^{commit}"); //$NON-NLS-1$ } catch (IOException e) { throw new JGitInternalException( MessageFormat.format(JGitText.get().cannotRead, getRefOrHEAD()), e); } }
/** * Set the upstream commit * * @param upstream * id of the upstream commit * @return {@code this} */ public RebaseCommand setUpstream(AnyObjectId upstream) { try { this.upstreamCommit = walk.parseCommit(upstream); this.upstreamCommitName = upstream.name(); } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( JGitText.get().couldNotReadObjectWhileParsingCommit, upstream.name()), e); } return this; }
private Ref getHead() throws GitAPIException { try { Ref head = repo.exactRef(Constants.HEAD); if (head == null || head.getObjectId() == null) throw new NoHeadException(JGitText.get().headRequiredToStash); return head; } catch (IOException e) { throw new JGitInternalException(JGitText.get().stashFailed, e); } }
@Override public String call() throws GitAPIException { try { DirCache index = repo.lockDirCache(); DirCacheEntry entry = index.getEntry(fileName); if (entry != null) { entry.setAssumeValid(assumeUnchanged); index.write(); index.commit(); return entry.getPathString(); } } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } return null; } }
@Override public String call() throws GitAPIException { try { DirCache index = repo.lockDirCache(); DirCacheEntry entry = index.getEntry(fileName); if (entry != null) { entry.setAssumeValid(assumeUnchanged); index.write(); index.commit(); return entry.getPathString(); } } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } return null; } }
/** {@inheritDoc} */ @Override public Note call() throws GitAPIException { checkCallable(); NoteMap map = NoteMap.newEmptyMap(); RevCommit notesCommit = null; try (RevWalk walk = new RevWalk(repo)) { Ref ref = repo.exactRef(notesRef); // if we have a notes ref, use it if (ref != null) { notesCommit = walk.parseCommit(ref.getObjectId()); map = NoteMap.read(walk.getObjectReader(), notesCommit); } return map.getNote(id); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } }
/** {@inheritDoc} */ @Override public void autoGC(ProgressMonitor monitor) { GC gc = new GC(this); gc.setPackConfig(new PackConfig(this)); gc.setProgressMonitor(monitor); gc.setAuto(true); gc.setBackground(shouldAutoDetach()); try { gc.gc(); } catch (ParseException | IOException e) { throw new JGitInternalException(JGitText.get().gcFailed, e); } } }