List of usage examples for org.eclipse.jgit.api AddCommand addFilepattern
public AddCommand addFilepattern(String filepattern)
From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java
License:Apache License
public void add(List<String> paths) throws Exception { AddCommand add = git.add(); for (String path : paths) add.addFilepattern(path); add.call();//w ww. jav a2s. co m }
From source file:com.cisco.step.jenkins.plugins.jenkow.JenkowWorkflowRepository.java
License:Open Source License
private void addAndCommit(Repository r, String filePattern, String msg) throws IOException { try {/*from w w w . j a v a 2s . c o m*/ Git git = new Git(r); AddCommand cmd = git.add(); cmd.addFilepattern(filePattern); cmd.call(); CommitCommand co = git.commit(); co.setAuthor("Jenkow", "noreply@jenkins-ci.org"); co.setMessage(msg); co.call(); } catch (GitAPIException e) { LOGGER.log(Level.WARNING, "Adding seeded jenkow-repository content to Git failed", e); } }
From source file:com.google.gerrit.acceptance.git.GitUtil.java
License:Apache License
public static void add(Git git, String path, String content) throws GitAPIException, IOException { File f = new File(git.getRepository().getDirectory().getParentFile(), path); File p = f.getParentFile();/*w w w . ja v a 2s .co m*/ if (!p.exists() && !p.mkdirs()) { throw new IOException("failed to create dir: " + p.getAbsolutePath()); } FileWriter w = new FileWriter(f); BufferedWriter out = new BufferedWriter(w); try { out.write(content); } finally { out.close(); } final AddCommand addCmd = git.add(); addCmd.addFilepattern(path); addCmd.call(); }
From source file:com.googlesource.gerrit.plugins.findowners.OwnersValidatorTest.java
License:Apache License
private static void addFiles(Git git, Map<File, byte[]> files) throws IOException, GitAPIException { AddCommand ac = git.add(); for (File f : files.keySet()) { if (!f.exists()) { FileUtils.touch(f);// w ww .j a v a2s .com } if (files.get(f) != null) { FileUtils.writeByteArrayToFile(f, files.get(f)); } ac = ac.addFilepattern(generateFilePattern(f, git)); } ac.call(); }
From source file:com.meltmedia.cadmium.core.git.GitService.java
License:Apache License
/** * Checks in content from a source directory into the current git repository. * @param sourceDirectory The directory to pull content in from. * @param message The commit message to use. * @return The new SHA revision.// w w w . j av a 2 s .c o m * @throws Exception */ public String checkinNewContent(String sourceDirectory, String message) throws Exception { RmCommand remove = git.rm(); boolean hasFiles = false; for (String filename : new File(getBaseDirectory()).list()) { if (!filename.equals(".git")) { remove.addFilepattern(filename); hasFiles = true; } } if (hasFiles) { log.info("Removing old content."); remove.call(); } log.info("Copying in new content."); FileSystemManager.copyAllContent(sourceDirectory, getBaseDirectory(), true); log.info("Adding new content."); AddCommand add = git.add(); for (String filename : new File(getBaseDirectory()).list()) { if (!filename.equals(".git")) { add.addFilepattern(filename); } } add.call(); log.info("Committing new content."); git.commit().setMessage(message).call(); return getCurrentRevision(); }
From source file:com.meltmedia.cadmium.core.git.GitServiceTest.java
License:Apache License
@Before public void createDirForTests() throws Exception { configManager.setDefaultProperties(new Properties()); testDir = new File("./target/git-test"); if (!testDir.exists()) { if (testDir.mkdir()) { gitRepo1 = new File(testDir, "checkout1"); git1 = GitService.cloneRepo("git://github.com/meltmedia/test-content-repo.git", gitRepo1.getAbsolutePath()); gitRepo2 = new File(testDir, "checkout2"); git2 = GitService.cloneRepo("git://github.com/meltmedia/test-content-repo.git", gitRepo2.getAbsolutePath()); gitRepo3 = new File(testDir, "checkout3"); git3 = GitService.cloneRepo("git://github.com/meltmedia/test-content-repo.git", gitRepo3.getAbsolutePath()); localGitRepo = new File(testDir, "local-git"); localGitRepo.mkdirs();//from ww w. j ava2 s . c om new File(localGitRepo, "delete.me").createNewFile(); new File(localGitRepo, "dir1").mkdirs(); new File(localGitRepo, "dir1/remove.me").createNewFile(); localGit = new GitService(Git.init().setDirectory(localGitRepo).call()); AddCommand add = localGit.git.add(); add.addFilepattern("delete.me"); add.addFilepattern("dir1"); add.call(); localGit.git.commit().setMessage("initial commit").call(); localGit.git.branchCreate().setName("test").call(); localGit.git.branchCreate().setName("test-delete").call(); localGitRepoCloned = new File(testDir, "local-git-cloned"); localClone = GitService.cloneRepo( new File(localGitRepo, ".git").getAbsoluteFile().getAbsolutePath(), localGitRepoCloned.getAbsoluteFile().getAbsolutePath()); } else { throw new Exception("Failed to set up tests"); } } else { gitRepo1 = new File(testDir, "checkout1"); git1 = GitService.createGitService(new File(gitRepo1, ".git").getAbsolutePath()); gitRepo2 = new File(testDir, "checkout2"); git2 = GitService.createGitService(new File(gitRepo2, ".git").getAbsolutePath()); gitRepo3 = new File(testDir, "checkout3"); git3 = GitService.createGitService(new File(gitRepo3, ".git").getAbsolutePath()); localGitRepo = new File(testDir, "local-git"); localGit = GitService.createGitService(new File(localGitRepo, ".git").getAbsolutePath()); localGitRepoCloned = new File(testDir, "local-git-cloned"); localClone = GitService.createGitService(new File(localGitRepoCloned, ".git").getAbsolutePath()); } File source = new File(testDir, "source"); source.mkdirs(); source = new File(source, "other.file"); source.createNewFile(); source = new File(testDir, "source/dir2"); source.mkdirs(); source = new File(source, "other.file"); source.createNewFile(); source = new File(testDir, "source2"); source.mkdirs(); source = new File(source, "other2.file"); source.createNewFile(); source = new File(testDir, "source2/dir3"); source.mkdirs(); source = new File(source, "other2.file"); source.createNewFile(); }
From source file:com.microsoft.tfs.client.common.ui.teambuild.egit.dialogs.GitBuildDefinitionDialog.java
License:Open Source License
@Override protected SelectionListener getCreateButtonSelectionListener(final Shell shell) { return new SelectionAdapter() { @Override//from w ww .ja va 2 s . c om public void widgetSelected(final SelectionEvent e) { final CreateGitBuildConfigurationWizard wizard = new CreateGitBuildConfigurationWizard(); updateAndVerifyBuildDefinition(true); wizard.init(buildDefinition); final WizardDialog dialog = new WizardDialog(getShell(), wizard); final int rc = dialog.open(); if (rc == IDialogConstants.OK_ID) { localBuildProjectCreated = true; /* * TFSBuild proj/resp files are created in a cloned * repository, but they could be outside of projects * imported into the Eclipse workspace. */ final List<IResource> resources = new ArrayList<IResource>(); final LocationInfo buildProjectLocation = new LocationInfo( new Path(getBuildProjectAbsolutePath())); if (buildProjectLocation.isPotentialSubProjectResource()) { resources.add(buildProjectLocation.getSubProjectResource(false)); } final LocationInfo buildResponceLocation = new LocationInfo( new Path(getBuildResponseAbsolutePath())); if (buildResponceLocation.isPotentialSubProjectResource()) { resources.add(buildResponceLocation.getSubProjectResource(false)); } if (resources.size() > 0) { final AddToIndexOperation op = new AddToIndexOperation(resources); try { op.execute(new NullProgressMonitor()); } catch (final CoreException ex) { log.error("Error adding build files to index", ex); //$NON-NLS-1$ } } else { final GitRepository repository = getBuildProjectRepository(); final Git git = new Git(repository.getLocalRepository()); final AddCommand addCommand = git.add(); addCommand.addFilepattern(getBuildProjectRelativePath()); addCommand.addFilepattern(getBuildResponseRelativePath()); try { addCommand.call(); } catch (final Exception ex) { log.error("Error adding build files to index", ex); //$NON-NLS-1$ } } checkForBuildFileExistence(true); validate(); } } }; }
From source file:com.osbitools.ws.shared.prj.utils.GitUtils.java
License:Open Source License
public static String commitFile(Git git, String fname, String comment, String user) throws WsSrvException { AddCommand add = git.add(); try {/*from w w w.j a va 2 s . co m*/ add.addFilepattern(fname).call(); } catch (GitAPIException e) { throw new WsSrvException(239, e); } CommitCommand commit = git.commit(); try { RevCommit rev = commit.setMessage(comment).setCommitter(user, "").call(); return rev.getName(); } catch (GitAPIException e) { throw new WsSrvException(240, e); } }
From source file:com.photon.phresco.framework.impl.SCMManagerImpl.java
License:Apache License
private void importToGITRepo(RepoDetail repodetail, ApplicationInfo appInfo, File appDir) throws Exception { if (debugEnabled) { S_LOGGER.debug("Entering Method SCMManagerImpl.importToGITRepo()"); }/*from ww w. jav a 2 s .co m*/ boolean gitExists = false; if (new File(appDir.getPath() + FORWARD_SLASH + DOT + GIT).exists()) { gitExists = true; } try { //For https and ssh additionalAuthentication(repodetail.getPassPhrase()); CredentialsProvider cp = new UsernamePasswordCredentialsProvider(repodetail.getUserName(), repodetail.getPassword()); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(appDir).readEnvironment().findGitDir().build(); String dirPath = appDir.getPath(); File gitignore = new File(dirPath + GITIGNORE_FILE); gitignore.createNewFile(); if (gitignore.exists()) { String contents = FileUtils.readFileToString(gitignore); if (!contents.isEmpty() && !contents.contains(DO_NOT_CHECKIN_DIR)) { String source = NEWLINE + DO_NOT_CHECKIN_DIR + NEWLINE; OutputStream out = new FileOutputStream((dirPath + GITIGNORE_FILE), true); byte buf[] = source.getBytes(); out.write(buf); out.close(); } else if (contents.isEmpty()) { String source = NEWLINE + DO_NOT_CHECKIN_DIR + NEWLINE; OutputStream out = new FileOutputStream((dirPath + GITIGNORE_FILE), true); byte buf[] = source.getBytes(); out.write(buf); out.close(); } } Git git = new Git(repository); InitCommand initCommand = Git.init(); initCommand.setDirectory(appDir); git = initCommand.call(); AddCommand add = git.add(); add.addFilepattern("."); add.call(); CommitCommand commit = git.commit().setAll(true); commit.setMessage(repodetail.getCommitMessage()).call(); StoredConfig config = git.getRepository().getConfig(); config.setString(REMOTE, ORIGIN, URL, repodetail.getRepoUrl()); config.setString(REMOTE, ORIGIN, FETCH, REFS_HEADS_REMOTE_ORIGIN); config.setString(BRANCH, MASTER, REMOTE, ORIGIN); config.setString(BRANCH, MASTER, MERGE, REF_HEAD_MASTER); config.save(); try { PushCommand pc = git.push(); pc.setCredentialsProvider(cp).setForce(true); pc.setPushAll().call(); } catch (Exception e) { git.getRepository().close(); PomProcessor appPomProcessor = new PomProcessor(new File(appDir, appInfo.getPhrescoPomFile())); appPomProcessor.removeProperty(Constants.POM_PROP_KEY_SRC_REPO_URL); appPomProcessor.save(); throw e; } if (appInfo != null) { updateSCMConnection(appInfo, repodetail.getRepoUrl()); } git.getRepository().close(); } catch (Exception e) { Exception s = e; resetLocalCommit(appDir, gitExists, e); throw s; } }
From source file:com.rimerosolutions.ant.git.tasks.AddTask.java
License:Apache License
@Override protected void doExecute() { try {/*from w w w . ja v a 2 s .c om*/ AddCommand addCommand = git.add().setUpdate(update); String prefix = getDirectory().getCanonicalPath(); String[] allFiles = getPath().list(); if (allFiles.length == 0) { return; } for (String file : allFiles) { String addedFile = translateFilePathUsingPrefix(file, prefix); addCommand.addFilepattern(addedFile); } addCommand.call(); } catch (GitAPIException e) { throw new GitBuildException(e); } catch (Exception e) { throw new GitBuildException("Unexpected error.", e); } }