@Signature public File getWorkTree() throws IOException { return getWrappedObject().getRepository().getWorkTree(); }
/** * Get submodule directory * * @param parent * the {@link org.eclipse.jgit.lib.Repository}. * @param path * submodule path * @return directory */ public static File getSubmoduleDirectory(final Repository parent, final String path) { return new File(parent.getWorkTree(), path); }
private boolean delete(File p) { boolean deleted = false; while (p != null && !p.equals(repo.getWorkTree()) && p.delete()) { deleted = true; p = p.getParentFile(); } return deleted; }
private void removeEmptyParents(File f) { File parentFile = f.getParentFile(); while (parentFile != null && !parentFile.equals(repo.getWorkTree())) { if (!parentFile.delete()) break; parentFile = parentFile.getParentFile(); } }
/** * Do the copy file action. * * @throws IOException */ public void copy() throws IOException { File srcFile = new File(repo.getWorkTree(), path + "/" + src); //$NON-NLS-1$ File destFile = new File(repo.getWorkTree(), dest); try (FileInputStream input = new FileInputStream(srcFile); FileOutputStream output = new FileOutputStream(destFile)) { FileChannel channel = input.getChannel(); output.getChannel().transferFrom(channel, 0, channel.size()); } destFile.setExecutable(srcFile.canExecute()); } }
/** * Get submodule id for given entry. * * @param e * a {@link org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry} * object. * @return non-null submodule id */ protected byte[] idSubmodule(Entry e) { if (repository == null) return zeroid; File directory; try { directory = repository.getWorkTree(); } catch (NoWorkTreeException nwte) { return zeroid; } return idSubmodule(directory, e); }
/** * Checks whether the working tree contains a .gitmodules file. That's a * hint that the repo contains submodules. * * @param repository * the repository to check * @return <code>true</code> if the working tree contains a .gitmodules file, * <code>false</code> otherwise. Always returns <code>false</code> * for bare repositories. * @throws java.io.IOException * @throws CorruptObjectException if any. * @since 3.6 */ public static boolean containsGitModulesFile(Repository repository) throws IOException { if (repository.isBare()) { return false; } File modulesFile = new File(repository.getWorkTree(), Constants.DOT_GIT_MODULES); return (modulesFile.exists()); }
/** * Get submodule repository * * @param parent * the {@link org.eclipse.jgit.lib.Repository}. * @param path * submodule path * @return repository or null if repository doesn't exist * @throws java.io.IOException */ public static Repository getSubmoduleRepository(final Repository parent, final String path) throws IOException { return getSubmoduleRepository(parent.getWorkTree(), path, parent.getFS()); }
/** * Recursively delete the *contents* of path, but leave path as an empty * directory * * @param path * the path to clean * @throws IOException */ private void deinit(String path) throws IOException { File dir = new File(repo.getWorkTree(), path); if (!dir.isDirectory()) { throw new JGitInternalException(MessageFormat.format( JGitText.get().expectedDirectoryNotSubmodule, path)); } final File[] ls = dir.listFiles(); if (ls != null) { for (int i = 0; i < ls.length; i++) { FileUtils.delete(ls[i], RECURSIVE); } } }
/** * This method implements how to handle conflicts when * {@link #failOnConflict} is false * * @throws CheckoutConflictException */ private void cleanUpConflicts() throws CheckoutConflictException { // TODO: couldn't we delete unsaved worktree content here? for (String c : conflicts) { File conflict = new File(repo.getWorkTree(), c); if (!conflict.delete()) throw new CheckoutConflictException(MessageFormat.format( JGitText.get().cannotDeleteFile, c)); removeEmptyParents(conflict); } for (String r : removed) { File file = new File(repo.getWorkTree(), r); if (!file.delete()) throw new CheckoutConflictException( MessageFormat.format(JGitText.get().cannotDeleteFile, file.getAbsolutePath())); removeEmptyParents(file); } }
private void checkoutGitlink(String path, DirCacheEntry entry) throws IOException { File gitlinkDir = new File(repo.getWorkTree(), path); FileUtils.mkdirs(gitlinkDir, true); FS fs = repo.getFS(); entry.setLastModified(fs.lastModified(gitlinkDir)); }
private File getFile(String path, boolean create) throws PatchApplyException { File f = new File(getRepository().getWorkTree(), path); if (create) try { File parent = f.getParentFile(); FileUtils.mkdirs(parent, true); FileUtils.createNewFile(f); } catch (IOException e) { throw new PatchApplyException(MessageFormat.format( JGitText.get().createNewFileFailed, f), e); } return f; }
/** * @return The path to the commit edit message file relative to the * repository's work tree, or null if the repository is bare. */ private String getCommitEditMessageFilePath() { File gitDir = getRepository().getDirectory(); if (gitDir == null) { return null; } return Repository.stripWorkDir(getRepository().getWorkTree(), new File( gitDir, Constants.COMMIT_EDITMSG)); }
public static void main(String[] args) throws IOException, GitAPIException { final File localPath; // prepare a new test-repository try (Repository repository = CookbookHelper.createNewRepository()) { localPath = repository.getWorkTree(); try (Git git = new Git(repository)) { // create the file File myFile = new File(repository.getDirectory().getParent(), "testfile"); if(!myFile.createNewFile()) { throw new IOException("Could not create file " + myFile); } // run the add-call git.add() .addFilepattern("testfile") .call(); System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory()); } } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
public static void main(String[] args) throws IOException, GitAPIException { final File localPath; // prepare a new test-repository try (Repository repository = CookbookHelper.createNewRepository()) { localPath = repository.getWorkTree(); try (Git git = new Git(repository)) { // create the file File myFile = new File(repository.getDirectory().getParent(), "testfile"); if(!myFile.createNewFile()) { throw new IOException("Could not create file " + myFile); } // run the add-call git.add() .addFilepattern("testfile") .call(); System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory()); } } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
public static void main(String[] args) throws IOException, GitAPIException { final File localPath; try (Repository repository = cloneRepository()) { localPath = repository.getWorkTree(); System.out.println("Having repository: " + repository.getDirectory() + " with head: " + repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" + repository.resolve("refs/heads/master")); // TODO: why do we get null here for HEAD?!? See also // http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception try (Git git = new Git(repository)) { PullResult call = git.pull().call(); System.out.println("Pulled from the remote repository: " + call); } } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); }
/** * Create a new iterator to traverse the work tree and its children. * * @param repo * the repository whose working tree will be scanned. * @param fileModeStrategy * the strategy to use to determine the FileMode for a FileEntry; * controls gitlinks etc. * @since 4.3 */ public FileTreeIterator(Repository repo, FileModeStrategy fileModeStrategy) { this(repo.getWorkTree(), repo.getFS(), repo.getConfig().get(WorkingTreeOptions.KEY), fileModeStrategy); initRootIterator(repo); }
public static void main(String[] args) throws IOException, GitAPIException { final File localPath; try (Repository repository = cloneRepository()) { localPath = repository.getWorkTree(); System.out.println("Having repository: " + repository.getDirectory() + " with head: " + repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" + repository.resolve("refs/heads/master")); // TODO: why do we get null here for HEAD?!? See also // http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception try (Git git = new Git(repository)) { PullResult call = git.pull().call(); System.out.println("Pulled from the remote repository: " + call); } } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); }
localPath = repository.getWorkTree();
@Override public Transport open(URIish uri, Repository local, String remoteName) throws NoRemoteRepositoryException { File localPath = local.isBare() ? local.getDirectory() : local.getWorkTree(); File path = local.getFS().resolve(localPath, uri.getPath()); // If the reference is to a local file, C Git behavior says // assume this is a bundle, since repositories are directories. if (path.isFile()) return new TransportBundleFile(local, uri, path); File gitDir = RepositoryCache.FileKey.resolve(path, local.getFS()); if (gitDir == null) throw new NoRemoteRepositoryException(uri, JGitText.get().notFound); return new TransportLocal(local, uri, gitDir); }