List of usage examples for org.eclipse.jgit.api Git add
public AddCommand add()
From source file:org.obiba.opal.core.cfg.OpalViewPersistenceStrategy.java
License:Open Source License
private void doWriteGitViews(@Nonnull String datasourceName, @Nonnull Iterable<View> views, @Nullable String comment) { File localRepo = null;// ww w .jav a 2 s. c o m try { // Fetch or clone a tmp working directory localRepo = cloneDatasourceViewsGit(datasourceName); // Serialize all view files in the repo List<String> varFilesToRemove = Lists.newArrayList(); StringBuilder message = new StringBuilder(); for (View view : views) { doWriteGitView(localRepo, view, varFilesToRemove); if (message.length() > 0) { message.append(", "); } message.append(view.getName()); } // Push changes Git git = new Git(new FileRepository(new File(localRepo, ".git"))); for (String toRemove : varFilesToRemove) { git.rm().addFilepattern(toRemove).call(); } git.add().addFilepattern(".").call(); doCommitPush(git, Strings.isNullOrEmpty(comment) ? "Update " + message : comment); } catch (Exception e) { throw new RuntimeException("Failed writing views in git for datasource: " + datasourceName, e); } finally { if (localRepo != null) localRepo.delete(); } }
From source file:org.obiba.opal.core.vcs.command.OpalWriteTaxonomyCommand.java
License:Open Source License
@Override public Iterable<PushResult> execute(Git git) { try {/*from w ww. j av a 2 s .c om*/ File localRepo = git.getRepository().getWorkTree(); serializeTaxonomy(localRepo); git.add().addFilepattern(".").call(); return commitAndPush(git); } catch (IOException | GitAPIException e) { throw new GitException(e); } }
From source file:org.obiba.opal.core.vcs.command.OpalWriteViewsCommand.java
License:Open Source License
@Override public Iterable<PushResult> execute(Git git) { try {//from w ww . ja v a 2s. c o m File localRepo = git.getRepository().getWorkTree(); List<String> varFilesToRemove = Lists.newArrayList(); StringBuilder message = new StringBuilder(); serializeAllViewFiles(localRepo, varFilesToRemove, message); String currentMessage = getCommitMessage(); setCommitMessage((Strings.isNullOrEmpty(currentMessage) ? "Update " : currentMessage + " ") + message); for (String toRemove : varFilesToRemove) { git.rm().addFilepattern(toRemove).call(); } git.add().addFilepattern(".").call(); return commitAndPush(git); } catch (IOException | GitAPIException e) { throw new GitException(e); } }
From source file:org.ocpsoft.redoculous.tests.asciidoc.AsciidocIncludeTest.java
License:Apache License
@Before public void before() throws IOException, GitAPIException { repository = File.createTempFile("redoc", "ulous-test"); repository.delete();//from www . java2 s .com repository.mkdirs(); File document = new File(repository, "document.asciidoc"); document.createNewFile(); File master = new File(repository, "master.asciidoc"); master.createNewFile(); Files.write(document, getClass().getClassLoader().getResourceAsStream("asciidoc/toc.asciidoc")); Files.write(master, "Somethingn, then...\n" + "include::document.asciidoc[]\n" + ASDF123); Git repo = Git.init().setDirectory(repository).call(); repo.add().addFilepattern("document.asciidoc").call(); repo.add().addFilepattern("master.asciidoc").call(); repo.commit().setMessage("Initial commit.").call(); }
From source file:org.ocpsoft.redoculous.tests.git.InitializeRepositoryTest.java
License:Apache License
@Before public void before() throws IOException, GitAPIException { repository = File.createTempFile("redoc", "ulous-test"); repository.delete();/*from ww w . j a v a 2s . c o m*/ repository.mkdirs(); File document = new File(repository, "document.asciidoc"); document.createNewFile(); Files.write(document, getClass().getClassLoader().getResourceAsStream("asciidoc/toc.asciidoc")); Git repo = Git.init().setDirectory(repository).call(); repo.add().addFilepattern("document.asciidoc").call(); repo.commit().setMessage("Initial commit.").call(); }
From source file:org.ocpsoft.redoculous.tests.markdown.MarkdownRenderTest.java
License:Apache License
@Before public void before() throws IOException, GitAPIException { repository = File.createTempFile("redoc", "ulous-test"); repository.delete();// ww w . j a v a 2 s. c om repository.mkdirs(); File document = new File(repository, "document.markdown"); document.createNewFile(); Files.write(document, getClass().getClassLoader().getResourceAsStream("markdown/document.markdown")); Git repo = Git.init().setDirectory(repository).call(); repo.add().addFilepattern("document.markdown").call(); repo.commit().setMessage("Initial commit.").call(); }
From source file:org.ocsoft.olivia.models.project.GitManager.java
License:Mozilla Public License
/** * //from w w w .j a v a 2 s . c o m * @throws GitAPIException */ public void addAll() throws GitAPIException { Git git = getGitInstance(); AddCommand add = git.add(); add.addFilepattern(".").call(); }
From source file:org.openengsb.connector.git.internal.GitServiceImpl.java
License:Apache License
@Override public CommitRef add(String comment, File... file) { if (file.length == 0) { LOGGER.debug("No files to add in list"); return null; }//from w w w . j av a 2 s .c o m if (repository == null) { prepareWorkspace(); try { initRepository(); } catch (IOException e) { if (repository != null) { repository.close(); } throw new ScmException(e); } } Git git = new Git(repository); AddCommand add = git.add(); try { for (File toCommit : file) { if (!toCommit.exists()) { throw new ScmException("File " + toCommit + " is not a valid file to commit."); } String filepattern = getRelativePath(toCommit.getAbsolutePath()); LOGGER.debug("Adding file {} in working directory to repository", filepattern); add.addFilepattern(filepattern); } add.call(); LOGGER.debug("Committing added files with comment '{}'", comment); return new GitCommitRef(git.commit().setMessage(comment).call()); } catch (Exception e) { throw new ScmException(e); } }
From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java
License:Apache License
@Test public void exportRepository_shouldReturnZipFileWithRepoEntries() throws Exception { localRepository = RepositoryFixture.createRepository(localDirectory); String dir = "testDirectory"; String file = "myTestFile"; File parent = new File(localDirectory, dir); parent.mkdirs();//from w w w . ja v a 2 s. c o m File child = new File(parent, file); FileWriter fw = new FileWriter(child); fw.write(file + "\n"); fw.close(); String pattern = dir + "/" + file; Git git = new Git(localRepository); git.add().addFilepattern(pattern).call(); git.commit().setMessage("My msg").call(); ZipFile zipFile = new ZipFile(service.export()); assertThat(zipFile.getEntry("testfile").getName(), is("testfile")); assertThat(zipFile.getEntry(dir + "/").getName(), is(dir + "/")); assertThat(zipFile.getEntry(dir + File.separator + file).getName(), is(dir + File.separator + file)); }
From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java
License:Apache License
public void exportRepositoryByRef_shouldReturnZipFileWithRepoEntries() throws Exception { localRepository = RepositoryFixture.createRepository(localDirectory); String dir = "testDirectory"; String file = "myTestFile"; File parent = new File(localDirectory, dir); parent.mkdirs();/*from w w w .j a va 2 s. c o m*/ File child = new File(parent, file); FileWriter fw = new FileWriter(child); fw.write(file + "\n"); fw.close(); String pattern = dir + "/" + file; Git git = new Git(localRepository); git.add().addFilepattern(pattern).call(); git.commit().setMessage("My msg").call(); AnyObjectId headId = localRepository.resolve(Constants.HEAD); RevWalk rw = new RevWalk(localRepository); RevCommit head = rw.parseCommit(headId); rw.release(); ZipFile zipFile = new ZipFile(service.export(new GitCommitRef(head))); assertThat(zipFile.getEntry("testfile").getName(), is("testfile")); assertThat(zipFile.getEntry(dir + "/").getName(), is(dir + "/")); assertThat(zipFile.getEntry(dir + "\\" + file).getName(), is(dir + "\\" + file)); }