List of usage examples for org.eclipse.jgit.api AddCommand setUpdate
public AddCommand setUpdate(boolean update)
From source file:de.br0tbox.gitfx.ui.controllers.CommitDialogController.java
License:Apache License
@FXML public void stageSelected() { try {//from www . j a v a 2s . c o m if (unstagedFiles.getSelectionModel().getSelectedItems().size() < 1) { return; } final AddCommand add = projectModel.getFxProject().getGit().add(); add.setUpdate(true); final List<String> selectedItems = unstagedFiles.getSelectionModel().getSelectedItems(); for (final String unstagedFile : selectedItems) { add.addFilepattern(unstagedFile); } add.call(); } catch (final GitAPIException e) { Dialogs.create().owner(getStage()).message("Error while Staging").masthead("An error occured") .title("Error").showException(e); } }
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 {//from w w w.jav a2 s . c om 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.ajoberstar.gradle.git.tasks.GitAdd.java
License:Apache License
/** * Adds the selected files to the staging area. *///from www . j av a2 s .com @TaskAction void add() { final AddCommand cmd = getGit().add(); cmd.setUpdate(isIgnoreUntracked()); getSource().visit(new FileVisitor() { public void visitDir(FileVisitDetails arg0) { // visitFile(arg0); } public void visitFile(FileVisitDetails arg0) { cmd.addFilepattern(arg0.getPath()); } }); try { cmd.call(); } catch (NoFilepatternException e) { getLogger().info("No files included in the add command for task {}", getName()); } catch (GitAPIException e) { throw new GradleException("Problem adding files to staging area.", e); } }
From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java
License:Open Source License
/** * Commit a model with any changes to local repo * @param model//from www. j a v a 2s . c om * @param localGitFolder * @param personIdent * @param commitMessage * @return * @throws GitAPIException * @throws IOException */ public static RevCommit commitModel(IArchimateModel model, File localGitFolder, PersonIdent personIdent, String commitMessage) throws GitAPIException, IOException { GraficoModelExporter exporter = new GraficoModelExporter(); exporter.exportModelToLocalGitRepository(model, localGitFolder); try (Git git = Git.open(localGitFolder)) { Status status = git.status().call(); // Nothing changed if (status.isClean()) { return null; } // Add modified files to index AddCommand addCommand = git.add(); addCommand.addFilepattern("."); //$NON-NLS-1$ addCommand.setUpdate(false); addCommand.call(); // Add missing files to index for (String s : status.getMissing()) { git.rm().addFilepattern(s).call(); } // Commit CommitCommand commitCommand = git.commit(); commitCommand.setAuthor(personIdent); commitCommand.setMessage(commitMessage); return commitCommand.call(); } }
From source file:org.archicontribs.modelrepository.grafico.GraficoUtilsTests.java
License:Open Source License
@Test public void getFileContents_IsCorrect() throws Exception { File localGitFolder = new File(getTempTestsFolder(), "testRepo"); String contents = "Hello World!\nTesting."; try (Repository repo = GitHelper.createNewRepository(localGitFolder)) { File file = new File(localGitFolder, "test.txt"); try (FileWriter fw = new FileWriter(file)) { fw.write(contents);//from ww w. ja v a2 s .co m fw.flush(); } assertTrue(file.exists()); // Add file to index AddCommand addCommand = new AddCommand(repo); addCommand.addFilepattern("."); //$NON-NLS-1$ addCommand.setUpdate(false); addCommand.call(); // Commit file CommitCommand commitCommand = Git.wrap(repo).commit(); commitCommand.setAuthor("Test", "Test"); commitCommand.setMessage("Message"); commitCommand.call(); assertEquals(contents, GraficoUtils.getFileContents(localGitFolder, "test.txt", "HEAD")); } }
From source file:org.archicontribs.modelrepository.grafico.MergeConflictHandler.java
License:Open Source License
public void mergeAndCommit() throws IOException, GitAPIException { try (Git git = Git.open(fLocalGitFolder)) { if (fOurs != null && !fOurs.isEmpty()) { checkout(git, Stage.OURS, fOurs); }/*from w w w . j a v a 2s . c om*/ if (fTheirs != null && !fTheirs.isEmpty()) { checkout(git, Stage.THEIRS, fTheirs); } // Add to index all files AddCommand addCommand = git.add(); addCommand.addFilepattern("."); //$NON-NLS-1$ addCommand.setUpdate(false); addCommand.call(); // Commit CommitCommand commitCommand = git.commit(); String userName = ModelRepositoryPlugin.INSTANCE.getPreferenceStore() .getString(IPreferenceConstants.PREFS_COMMIT_USER_NAME); String userEmail = ModelRepositoryPlugin.INSTANCE.getPreferenceStore() .getString(IPreferenceConstants.PREFS_COMMIT_USER_EMAIL); commitCommand.setAuthor(userName, userEmail); commitCommand.call(); } }
From source file:org.webcat.core.git.GitUtilities.java
License:Open Source License
/** * Sets up a new base Git repository for the specified object. * * @param object the object whose file store is desired * @param location the file system location for the repository * @return the newly created repository//from w w w . j a v a 2 s .c om */ private static Repository setUpNewRepository(EOEnterpriseObject object, File location) throws IOException { // This method performs the following actions to set up a new // repository: // // 1) Creates a new bare repository in the location requested by the // method argument. // 2) Creates a temporary non-bare repository in the system temp // directory, which is then configured to use the bare repository // as a remote repository. // 3) Creates a README.txt file in the temporary repository's working // directory, which contains a welcome message determined by the // type of object that created the repo. // 4) Adds the README.txt to the repository, commits the change, and // then pushes the changes to the bare repository. // 5) Finally, the temporary repository is deleted. // // This results in a usable bare repository being created, which a user // can now clone locally in order to manage their Web-CAT file store. // Create the bare repository. InitCommand init = new InitCommand(); init.setDirectory(location); init.setBare(true); Repository bareRepository = init.call().getRepository(); // Create the temporary repository. File tempRepoDir = File.createTempFile("newgitrepo", null); tempRepoDir.delete(); tempRepoDir.mkdirs(); init = new InitCommand(); init.setDirectory(tempRepoDir); Repository tempRepository = init.call().getRepository(); // Create the welcome files in the temporary repo. if (object instanceof RepositoryProvider) { RepositoryProvider provider = (RepositoryProvider) object; try { provider.initializeRepositoryContents(tempRepoDir); } catch (Exception e) { log.error( "The following exception occurred when trying to " + "initialize the repository contents at " + location.getAbsolutePath() + ", but I'm continuing " + "anyway to ensure that the repository isn't corrupt.", e); } } // Make sure we created at least one file, since we can't do much with // an empty repository. If the object didn't put anything in the // staging area, we'll just create a dummy README file. File[] files = tempRepoDir.listFiles(); boolean foundFile = false; for (File file : files) { String name = file.getName(); if (!".".equals(name) && !"..".equals(name) && !".git".equalsIgnoreCase(name)) { foundFile = true; break; } } if (!foundFile) { PrintWriter writer = new PrintWriter(new File(tempRepoDir, "README.txt")); writer.println("This readme file is provided so that the initial repository\n" + "has some content. You may delete it when you push other files\n" + "into the repository, if you wish."); writer.close(); } // Create an appropriate default .gitignore file. PrintWriter writer = new PrintWriter(new File(tempRepoDir, ".gitignore")); writer.println("~*"); writer.println("._*"); writer.println(".TemporaryItems"); writer.println(".DS_Store"); writer.println("Thumbs.db"); writer.close(); // Add the files to the temporary repository. AddCommand add = new AddCommand(tempRepository); add.addFilepattern("."); add.setUpdate(false); try { add.call(); } catch (NoFilepatternException e) { log.error("An exception occurred when adding the welcome files " + "to the repository: ", e); return bareRepository; } // Commit the changes. String email = Application.configurationProperties().getProperty("coreAdminEmail"); CommitCommand commit = new Git(tempRepository).commit(); commit.setAuthor("Web-CAT", email); commit.setCommitter("Web-CAT", email); commit.setMessage("Initial repository setup."); try { commit.call(); } catch (Exception e) { log.error("An exception occurred when committing the welcome files " + "to the repository: ", e); return bareRepository; } // Push the changes to the bare repository. PushCommand push = new Git(tempRepository).push(); @SuppressWarnings("deprecation") String url = location.toURL().toString(); push.setRemote(url); push.setRefSpecs(new RefSpec("master"), new RefSpec("master")); try { push.call(); } catch (Exception e) { log.error("An exception occurred when pushing the welcome files " + "to the repository: ", e); return bareRepository; } // Cleanup after ourselves. FileUtilities.deleteDirectory(tempRepoDir); return bareRepository; }
From source file:org.zend.sdkcli.internal.commands.GitPushApplicationCommand.java
License:Open Source License
@Override protected boolean doExecute() { Repository repo = null;//from w w w.ja va2 s . c o m try { File gitDir = getRepo(); if (!gitDir.exists()) { getLogger().error("Git repository is not available in provided location"); return false; } repo = FileRepositoryBuilder.create(getRepo()); } catch (IOException e) { getLogger().error(e); return false; } if (repo != null) { Git git = new Git(repo); String remote = doGetRemote(repo); if (remote == null) { getLogger().error("Invalid remote value: " + getRemote()); return false; } // perform operation only if it is clone of phpCloud repository String repoUrl = git.getRepository().getConfig().getString("remote", remote, "url"); AddCommand addCommand = git.add(); addCommand.setUpdate(false); // add all new files addCommand.addFilepattern("."); try { addCommand.call(); } catch (NoFilepatternException e) { // should not occur because '.' is used getLogger().error(e); return false; } catch (GitAPIException e) { getLogger().error(e); return false; } CommitCommand commitCommand = git.commit(); // automatically stage files that have been modified and deleted commitCommand.setAll(true); PersonIdent ident = getPersonalIdent(repoUrl); if (ident == null) { getLogger().error("Invalid author information provided: " + getAuthor()); return false; } commitCommand.setAuthor(ident); commitCommand.setInsertChangeId(true); commitCommand.setMessage(getMessage()); try { commitCommand.call(); } catch (Exception e) { getLogger().error(e); return false; } // at the end push all changes PushCommand pushCommand = git.push(); pushCommand.setPushAll(); pushCommand.setRemote(remote); pushCommand.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))); try { URIish uri = new URIish(repoUrl); if (GITHUB_HOST.equals(uri.getHost()) && "git".equals(uri.getUser())) { if (!prepareSSHFactory()) { return false; } } else { CredentialsProvider credentials = getCredentials(repoUrl); if (credentials != null) { pushCommand.setCredentialsProvider(credentials); } } Iterable<PushResult> result = pushCommand.call(); for (PushResult pushResult : result) { pushResult.getAdvertisedRefs(); Collection<RemoteRefUpdate> updates = pushResult.getRemoteUpdates(); for (RemoteRefUpdate remoteRefUpdate : updates) { TrackingRefUpdate trackingRefUpdate = remoteRefUpdate.getTrackingRefUpdate(); getLogger().info(MessageFormat.format("Remote name: {0}, status: {1}", remoteRefUpdate.getRemoteName(), remoteRefUpdate.getStatus().toString())); getLogger().info(MessageFormat.format("Remote name: {0}, result: {1}", trackingRefUpdate.getRemoteName(), trackingRefUpdate.getResult().toString())); } } } catch (JGitInternalException e) { getLogger().error(e); return false; } catch (InvalidRemoteException e) { // should not occur because selected remote is available getLogger().error(e); return false; } catch (URISyntaxException e) { getLogger().error(e); return false; } catch (TransportException e) { getLogger().error(e); return false; } catch (GitAPIException e) { getLogger().error(e); return false; } } return true; }