List of usage examples for org.eclipse.jgit.api AddCommand setWorkingTreeIterator
public AddCommand setWorkingTreeIterator(WorkingTreeIterator f)
From source file:de.fkoeberle.autocommit.git.GitRepositoryAdapter.java
License:Open Source License
private void stageForCommit(Git git, FilesToAdd filesToAdd) { WorkingTreeIterator workingTreeIterator = IteratorService.createInitialIterator(repository); try {//w w w .j a v a 2s .com AddCommand addCommand = git.add(); addCommand.addFilepattern("."); addCommand.setWorkingTreeIterator(workingTreeIterator); addCommand.setUpdate(filesToAdd == FilesToAdd.REMOVED_OR_MODIFIED); addCommand.call(); } catch (NoFilepatternException e) { throw new RuntimeException(e); } }
From source file:org.commonjava.gitwrap.GitRepository.java
License:Open Source License
public GitRepository commitChanges(final String message, final String... filePatterns) throws GitWrapException { final AddCommand add = getGit().add(); add.setWorkingTreeIterator(new FileTreeIterator(getRepository())); for (final String pattern : filePatterns) { add.addFilepattern(pattern);/* www . ja va2 s. c o m*/ } try { add.call(); } catch (final NoFilepatternException e) { throw new GitWrapException("Failed to add file patterns: %s", e, e.getMessage()); } try { getGit().commit().setMessage(message).setAuthor(new PersonIdent(getRepository())).call(); } catch (final NoHeadException e) { throw new GitWrapException("Commit failed: no repository HEAD. Nested error: %s", e, e.getMessage()); } catch (final NoMessageException e) { throw new GitWrapException("Commit failed: no message provided. Nested error: %s", e, e.getMessage()); } catch (final UnmergedPathException e) { throw new GitWrapException("Commit failed: you have unmerged paths. Nested error: %s", e, e.getMessage()); } catch (final ConcurrentRefUpdateException e) { throw new GitWrapException("Commit failed: %s", e, e.getMessage()); } catch (final JGitInternalException e) { throw new GitWrapException("Commit failed: %s", e, e.getMessage()); } catch (final WrongRepositoryStateException e) { throw new GitWrapException("Commit failed: %s", e, e.getMessage()); } return this; }
From source file:org.eclipse.ptp.internal.rdt.sync.git.core.JGitRepo.java
License:Open Source License
/** * Commit files in working directory.//from w w w . j a va 2 s .co m * * assumes that no files are in conflict (do not call during merge) * * @param monitor * * @return whether any changes were committed * @throws GitAPIException * on JGit-specific problems * @throws IOException * on file system problems */ public boolean commit(IProgressMonitor monitor) throws GitAPIException, IOException { RecursiveSubMonitor subMon = RecursiveSubMonitor.convert(monitor, 10); assert (!inUnresolvedMergeState()); try { DiffFiles diffFiles = fileFilter.getDiffFiles(); // Create and add an empty file to all synchronized directories to force sync'ing of empty directories for (String dirName : diffFiles.dirSet) { IPath emptyFilePath = new Path(this.getRepository().getWorkTree().getAbsolutePath()); emptyFilePath = emptyFilePath.append(dirName); // Bug 439609 - directory may have been deleted File emptyFileDir = new File(emptyFilePath.toOSString()); if (!emptyFileDir.exists()) { continue; } emptyFilePath = emptyFilePath.append(EMPTY_FILE_NAME); File emptyFile = new File(emptyFilePath.toOSString()); boolean fileWasCreated = emptyFile.createNewFile(); if (fileWasCreated) { diffFiles.added.add(emptyFilePath.toString()); } } subMon.subTask(Messages.JGitRepo_2); if (!diffFiles.added.isEmpty()) { final AddCommand addCommand = git.add(); //Bug 401161 doesn't matter here because files are already filtered anyhow. It would be OK //if the tree iterator would always return false in isEntryIgnored addCommand.setWorkingTreeIterator(new SyncFileTreeIterator(git.getRepository(), fileFilter)); for (String fileName : diffFiles.added) { addCommand.addFilepattern(fileName); } addCommand.call(); } subMon.worked(3); subMon.subTask(Messages.JGitRepo_3); if (!diffFiles.removed.isEmpty()) { final RmCommand rmCommand = new RmCommand(git.getRepository()); rmCommand.setCached(true); for (String fileName : diffFiles.removed) { rmCommand.addFilepattern(fileName); } rmCommand.call(); } subMon.worked(3); // Check if a commit is required. subMon.subTask(Messages.JGitRepo_4); if (anyDiffInIndex() || inMergeState()) { final CommitCommand commitCommand = git.commit(); commitCommand.setMessage(GitSyncService.commitMessage); commitCommand.call(); return true; } else { return false; } } finally { if (monitor != null) { monitor.done(); } } }