org.eclipse.jgit.lib.Repository.getWorkTree()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中org.eclipse.jgit.lib.Repository.getWorkTree方法的一些代码示例,展示了Repository.getWorkTree的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.getWorkTree方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:getWorkTree

Repository.getWorkTree介绍

[英]Get the root directory of the working tree, where files are checked out for viewing and editing.
[中]获取工作树的根目录,从中签出文件以进行查看和编辑。

代码示例

代码示例来源:origin: jphp-group/jphp

@Signature
public File getWorkTree() throws IOException {
  return getWrappedObject().getRepository().getWorkTree();
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private boolean delete(File p) {
  boolean deleted = false;
  while (p != null && !p.equals(repo.getWorkTree()) && p.delete()) {
    deleted = true;
    p = p.getParentFile();
  }
  return deleted;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private void removeEmptyParents(File f) {
  File parentFile = f.getParentFile();
  while (parentFile != null && !parentFile.equals(repo.getWorkTree())) {
    if (!parentFile.delete())
      break;
    parentFile = parentFile.getParentFile();
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
   * 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());
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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());
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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());
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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);
    }
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

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));
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

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;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * @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));
}

代码示例来源:origin: centic9/jgit-cookbook

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);
  }
}

代码示例来源:origin: centic9/jgit-cookbook

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);
  }
}

代码示例来源:origin: centic9/jgit-cookbook

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);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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);
}

代码示例来源:origin: centic9/jgit-cookbook

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);
}

代码示例来源:origin: centic9/jgit-cookbook

localPath = repository.getWorkTree();

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

@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);
}

相关文章

Repository类方法