List of usage examples for org.eclipse.jgit.lib Repository getWorkTree
@NonNull public File getWorkTree() throws NoWorkTreeException
From source file:org.sonarsource.scm.git.JGitBlameCommand.java
License:Open Source License
@Override public void blame(BlameInput input, BlameOutput output) { File basedir = input.fileSystem().baseDir(); Repository repo = buildRepository(basedir); try {//www . ja v a 2 s .c om Git git = Git.wrap(repo); File gitBaseDir = repo.getWorkTree(); ExecutorService executorService = Executors .newFixedThreadPool(Runtime.getRuntime().availableProcessors()); List<Future<Void>> tasks = submitTasks(input, output, git, gitBaseDir, executorService); waitForTaskToComplete(executorService, tasks); } finally { repo.close(); } }
From source file:org.webcat.core.FilePickerDialog.java
License:Open Source License
public JavascriptGenerator createFolderOkPressed() { JavascriptGenerator js = new JavascriptGenerator(); js.dijit(idFor.get("createFolderDialog")).call("hide"); Repository workingCopy = GitUtilities.workingCopyForRepository(createFolderRepo.repository(), true); File file = workingCopy.getWorkTree(); File destDir = file;// w ww . j av a 2 s. c o m if (createFolderLocation != null) { destDir = new File(file, createFolderLocation); } File newFolder = new File(destDir, newFolderName); if (newFolder.exists()) { js.alert("Notice", "The folder already exists."); return js; } try { newFolder.mkdirs(); File gitIgnore = new File(newFolder, ".gitignore"); FileOutputStream os = new FileOutputStream(gitIgnore); os.close(); GitUtilities.pushWorkingCopyImmediately(workingCopy, user(), "Created folder \"" + newFolderName + "\""); } catch (Exception e) { log.error("error creating the folder " + newFolderName + " as " + newFolder + ": ", e); js.alert("Notice", "The following error occurred trying to create " + "the folder \"" + newFolderName + "\": " + e.getMessage()); return js; } updateRefModel(); js.refresh(idFor.get("repositoryTree"), idFor.get("entryTree")); return js; }
From source file:org.webcat.core.FilePickerDialog.java
License:Open Source License
public JavascriptGenerator uploadFileOkPressed() { JavascriptGenerator js = new JavascriptGenerator(); js.dijit(idFor.get("uploadFileDialog")).call("hide"); if (uploadedFilePath == null) { return js; }/*w ww . j a va2 s . c o m*/ Repository workingCopy = GitUtilities.workingCopyForRepository(createFolderRepo.repository(), true); File file = workingCopy.getWorkTree(); File destDir = file; if (createFolderLocation != null) { destDir = new File(file, createFolderLocation); } File destFile = new File(destDir, uploadedFilePath); try { if (expandIfArchive && FileUtilities.isArchiveFile(uploadedFilePath)) { ArchiveManager.getInstance().unpack(destDir, uploadedFilePath, uploadedFileData.stream()); } else { FileOutputStream os = new FileOutputStream(destFile); uploadedFileData.writeToStream(os); os.close(); } GitUtilities.pushWorkingCopyImmediately(workingCopy, user(), commitMessageForUpload); } catch (IOException e) { log.error("error uploading file " + uploadedFilePath + " as " + destFile + ": ", e); js.alert("Error", "The following error occurred trying to upload the " + "file \"" + uploadedFilePath + "\": " + e.getMessage()); return js; } updateRefModel(); js.refresh(idFor.get("repositoryTree"), idFor.get("entryTree")); return js; }
From source file:org.webcat.core.git.http.GitBlobPage.java
License:Open Source License
public WOActionResults commitChanges() { if (commitMessageForChanges == null || commitMessageForChanges.length() == 0) { error("Please provide a commit message for your file upload"); } else {/*from www .ja va 2 s. com*/ Repository workingCopy = GitUtilities.workingCopyForRepository(gitContext().repository().repository(), true); File file = new File(workingCopy.getWorkTree(), gitContext().path()); try { FileWriter writer = new FileWriter(file); writer.write(blobContentString); writer.close(); GitUtilities.pushWorkingCopyImmediately(workingCopy, user(), commitMessageForChanges); } catch (IOException e) { log.error("error committing changes to " + file + ": ", e); error("The following error occurred trying to commit the " + "file \"" + gitContext().path() + "\": " + e.getMessage()); } } // Refresh the page but do a redirect to make sure we get the proper // URL in the address bar. WORedirect redirect = new WORedirect(context()); redirect.setUrl(gitContext().toURL(context())); return redirect.generateResponse(); }
From source file:org.webcat.core.git.http.GitTreePage.java
License:Open Source License
public WOActionResults createFolder() { if (folderName == null || folderName.length() == 0) { error("Please provide a folder name."); } else {//from w w w . j a v a 2 s.c om Repository workingCopy = GitUtilities.workingCopyForRepository(gitContext().repository().repository(), true); File file = workingCopy.getWorkTree(); File destDir = file; if (gitContext().path() != null) { destDir = new File(file, gitContext().path()); } File newFolder = new File(destDir, folderName); try { newFolder.mkdirs(); File gitIgnore = new File(newFolder, ".gitignore"); FileOutputStream os = new FileOutputStream(gitIgnore); os.close(); GitUtilities.pushWorkingCopyImmediately(workingCopy, user(), "created folder \"" + folderName + "\""); } catch (Exception e) { log.error("error creating the folder " + folderName + " as " + newFolder + ": ", e); error("The following error occurred trying to create " + "the folder \"" + folderName + "\": " + e.getMessage()); } } // Refresh the page but do a redirect to make sure we get the proper // URL in the address bar. WORedirect redirect = new WORedirect(context()); redirect.setUrl(gitContext().toURL(context())); return redirect.generateResponse(); }
From source file:org.webcat.core.git.http.GitTreePage.java
License:Open Source License
public WOActionResults uploadFile() { if (commitMessageForUpload == null || commitMessageForUpload.length() == 0) { error("Please provide a commit message for your file upload"); } else {//from www. j av a 2s . c om Repository workingCopy = GitUtilities.workingCopyForRepository(gitContext().repository().repository(), true); File file = workingCopy.getWorkTree(); File destDir = file; if (gitContext().path() != null) { destDir = new File(file, gitContext().path()); } File destFile = new File(destDir, filePathToUpload); try { if (expandIfArchive && FileUtilities.isArchiveFile(filePathToUpload)) { ArchiveManager.getInstance().unpack(destDir, filePathToUpload, fileDataToUpload.stream()); } else { FileOutputStream os = new FileOutputStream(destFile); fileDataToUpload.writeToStream(os); os.close(); } GitUtilities.pushWorkingCopyImmediately(workingCopy, user(), commitMessageForUpload); } catch (IOException e) { log.error("error uploading file " + filePathToUpload + " as " + destFile + ": ", e); error("The following error occurred trying to upload the " + "file \"" + filePathToUpload + "\": " + e.getMessage()); } } // Refresh the page but do a redirect to make sure we get the proper // URL in the address bar. WORedirect redirect = new WORedirect(context()); redirect.setUrl(gitContext().toURL(context())); return redirect.generateResponse(); }
From source file:support.Git.java
License:Apache License
public static RevCommit commit(Repository repository, String fileName, String contents, String commitMessage) throws IOException, GitAPIException { String wcPath = repository.getWorkTree().getAbsolutePath(); org.eclipse.jgit.api.Git git = new org.eclipse.jgit.api.Git(repository); BufferedWriter out = new BufferedWriter(new FileWriter(wcPath + "/" + fileName)); out.write(contents);/* w ww.j a v a 2 s . c o m*/ out.flush(); git.add().addFilepattern(fileName).call(); return git.commit().setMessage(commitMessage).call(); }