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

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

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

Repository.isBare介绍

[英]Whether this repository is bare
[中]该存储库是否为空

代码示例

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

@Signature
public boolean isBare() {
  return getWrappedObject().getRepository().isBare();
}

代码示例来源: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 the index file location or {@code null} if repository isn't local.
 *
 * @return the index file location or {@code null} if repository isn't
 *         local.
 * @throws org.eclipse.jgit.errors.NoWorkTreeException
 *             if this is bare, which implies it has no working directory.
 *             See {@link #isBare()}.
 */
@NonNull
public File getIndexFile() throws NoWorkTreeException {
  if (isBare())
    throw new NoWorkTreeException();
  return indexFile;
}

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

/**
 * Get the root directory of the working tree, where files are checked out
 * for viewing and editing.
 *
 * @return the root directory of the working tree, where files are checked
 *         out for viewing and editing.
 * @throws org.eclipse.jgit.errors.NoWorkTreeException
 *             if this is bare, which implies it has no working directory.
 *             See {@link #isBare()}.
 */
@NonNull
public File getWorkTree() throws NoWorkTreeException {
  if (isBare())
    throw new NoWorkTreeException();
  return workTree;
}

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

private static Repository openMainRepo(File mainRepoDir) throws IOException {
  FileRepositoryBuilder builder = new FileRepositoryBuilder();
  Repository mainRepo = builder.setGitDir(new File(mainRepoDir.getAbsolutePath(), ".git"))
   .readEnvironment() // scan environment GIT_* variables
   .findGitDir() // scan up the file system tree
   .build();
  if(mainRepo.isBare()) {
    throw new IllegalStateException("Repository at " + mainRepoDir + " should not be bare");
  }
  return mainRepo;
}

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

private static Repository openMainRepo(File mainRepoDir) throws IOException {
  FileRepositoryBuilder builder = new FileRepositoryBuilder();
  Repository mainRepo = builder.setGitDir(new File(mainRepoDir.getAbsolutePath(), ".git"))
   .readEnvironment() // scan environment GIT_* variables
   .findGitDir() // scan up the file system tree
   .build();
  if(mainRepo.isBare()) {
    throw new IllegalStateException("Repository at " + mainRepoDir + " should not be bare");
  }
  return mainRepo;
}

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

private static void addSubmodule(Repository mainRepo) throws GitAPIException {
  System.out.println("Adding submodule");
  try (Git git = new Git(mainRepo)) {
    try (Repository subRepoInit = git.submoduleAdd().
        setURI("https://github.com/github/testrepo.git").
        setPath("testrepo").
        call()) {
      if(subRepoInit.isBare()) {
        throw new IllegalStateException("Repository at " + subRepoInit.getDirectory() + " should not be bare");
      }
    }
  }
}

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

private static void addSubmodule(Repository mainRepo) throws GitAPIException {
  System.out.println("Adding submodule");
  try (Git git = new Git(mainRepo)) {
    try (Repository subRepoInit = git.submoduleAdd().
        setURI("https://github.com/github/testrepo.git").
        setPath("testrepo").
        call()) {
      if(subRepoInit.isBare()) {
        throw new IllegalStateException("Repository at " + subRepoInit.getDirectory() + " should not be bare");
      }
    }
  }
}

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

@Nullable
private String readCommitMsgFile(String msgFilename) throws IOException {
  if (isBare() || getDirectory() == null)
    throw new NoWorkTreeException();
  File mergeMsgFile = new File(getDirectory(), msgFilename);
  try {
    return RawParseUtils.decode(IO.readFully(mergeMsgFile));
  } catch (FileNotFoundException e) {
    if (mergeMsgFile.exists()) {
      throw e;
    }
    // the file has disappeared in the meantime ignore it
    return null;
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
  File mainRepoDir = createRepository();
  try (Repository mainRepo = openMainRepo(mainRepoDir)) {
    addSubmodule(mainRepo);
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    try (Repository subRepo = builder.setGitDir(new File("testrepo/.git"))
        .readEnvironment() // scan environment GIT_* variables
        .findGitDir() // scan up the file system tree
        .build()) {
      if (subRepo.isBare()) {
        throw new IllegalStateException("Repository at " + subRepo.getDirectory() + " should not be bare");
      }
    }
  }
  System.out.println("All done!");
  // clean up here to not keep using more and more disk-space for these samples
  FileUtils.deleteDirectory(mainRepoDir);
}

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

public static void main(String[] args) throws IOException, GitAPIException {
  File mainRepoDir = createRepository();
  try (Repository mainRepo = openMainRepo(mainRepoDir)) {
    addSubmodule(mainRepo);
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    try (Repository subRepo = builder.setGitDir(new File("testrepo/.git"))
        .readEnvironment() // scan environment GIT_* variables
        .findGitDir() // scan up the file system tree
        .build()) {
      if (subRepo.isBare()) {
        throw new IllegalStateException("Repository at " + subRepo.getDirectory() + " should not be bare");
      }
    }
  }
  System.out.println("All done!");
  // clean up here to not keep using more and more disk-space for these samples
  FileUtils.deleteDirectory(mainRepoDir);
}

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

/**
 * Return the information stored in the file $GIT_DIR/MERGE_HEAD. In this
 * file operations triggering a merge will store the IDs of all heads which
 * should be merged together with HEAD.
 *
 * @return a list of commits which IDs are listed in the MERGE_HEAD file or
 *         {@code null} if this file doesn't exist. Also if the file exists
 *         but is empty {@code null} will be returned
 * @throws java.io.IOException
 * @throws org.eclipse.jgit.errors.NoWorkTreeException
 *             if this is bare, which implies it has no working directory.
 *             See {@link #isBare()}.
 */
@Nullable
public List<ObjectId> readMergeHeads() throws IOException, NoWorkTreeException {
  if (isBare() || getDirectory() == null)
    throw new NoWorkTreeException();
  byte[] raw = readGitDirectoryFile(Constants.MERGE_HEAD);
  if (raw == null)
    return null;
  LinkedList<ObjectId> heads = new LinkedList<>();
  for (int p = 0; p < raw.length;) {
    heads.add(ObjectId.fromString(raw, p));
    p = RawParseUtils
        .nextLF(raw, p + Constants.OBJECT_ID_STRING_LENGTH);
  }
  return heads;
}

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

/**
 * Return the information stored in the file $GIT_DIR/ORIG_HEAD.
 *
 * @return object id from ORIG_HEAD file or {@code null} if this file
 *         doesn't exist. Also if the file exists but is empty {@code null}
 *         will be returned
 * @throws java.io.IOException
 * @throws org.eclipse.jgit.errors.NoWorkTreeException
 *             if this is bare, which implies it has no working directory.
 *             See {@link #isBare()}.
 */
@Nullable
public ObjectId readOrigHead() throws IOException, NoWorkTreeException {
  if (isBare() || getDirectory() == null)
    throw new NoWorkTreeException();
  byte[] raw = readGitDirectoryFile(Constants.ORIG_HEAD);
  return raw != null ? ObjectId.fromString(raw, 0) : null;
}

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

/**
 * Return the information stored in the file $GIT_DIR/REVERT_HEAD.
 *
 * @return object id from REVERT_HEAD file or {@code null} if this file
 *         doesn't exist. Also if the file exists but is empty {@code null}
 *         will be returned
 * @throws java.io.IOException
 * @throws org.eclipse.jgit.errors.NoWorkTreeException
 *             if this is bare, which implies it has no working directory.
 *             See {@link #isBare()}.
 */
@Nullable
public ObjectId readRevertHead() throws IOException, NoWorkTreeException {
  if (isBare() || getDirectory() == null)
    throw new NoWorkTreeException();
  byte[] raw = readGitDirectoryFile(Constants.REVERT_HEAD);
  if (raw == null)
    return null;
  return ObjectId.fromString(raw, 0);
}

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

/**
 * Return the information stored in the file $GIT_DIR/CHERRY_PICK_HEAD.
 *
 * @return object id from CHERRY_PICK_HEAD file or {@code null} if this file
 *         doesn't exist. Also if the file exists but is empty {@code null}
 *         will be returned
 * @throws java.io.IOException
 * @throws org.eclipse.jgit.errors.NoWorkTreeException
 *             if this is bare, which implies it has no working directory.
 *             See {@link #isBare()}.
 */
@Nullable
public ObjectId readCherryPickHead() throws IOException,
    NoWorkTreeException {
  if (isBare() || getDirectory() == null)
    throw new NoWorkTreeException();
  byte[] raw = readGitDirectoryFile(Constants.CHERRY_PICK_HEAD);
  if (raw == null)
    return null;
  return ObjectId.fromString(raw, 0);
}

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

/** {@inheritDoc} */
@Override
public RefUpdate newUpdate(String name, boolean detach) throws IOException {
  if (!repo.isBare() && name.indexOf('/') < 0 && !HEAD.equals(name)) {
    return bootstrap.newUpdate(name, detach);
  }
  if (conflictsWithBootstrap(name)) {
    return new AlwaysFailUpdate(this, name);
  }
  Ref r = exactRef(name);
  if (r == null) {
    r = new ObjectIdRef.Unpeeled(Storage.NEW, name, null);
  }
  boolean detaching = detach && r.isSymbolic();
  if (detaching) {
    r = new ObjectIdRef.Unpeeled(LOOSE, name, r.getObjectId());
  }
  RefTreeUpdate u = new RefTreeUpdate(this, r);
  if (detaching) {
    u.setDetachingSymbolicRef();
  }
  return u;
}

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

/** {@inheritDoc} */
@Override
public Ref exactRef(String name) throws IOException {
  if (!repo.isBare() && name.indexOf('/') < 0 && !HEAD.equals(name)) {
    // Pass through names like MERGE_HEAD, ORIG_HEAD, FETCH_HEAD.
    return bootstrap.exactRef(name);
  } else if (conflictsWithBootstrap(name)) {
    return null;
  }
  boolean partial = false;
  Ref src = bootstrap.exactRef(txnCommitted);
  Scanner.Result c = refs;
  if (c == null || !c.refTreeId.equals(idOf(src))) {
    c = Scanner.scanRefTree(repo, src, prefixOf(name), false);
    partial = true;
  }
  Ref r = c.all.get(name);
  if (r != null && r.isSymbolic()) {
    r = c.sym.get(name);
    if (partial && r.getObjectId() == null) {
      // Attempting exactRef("HEAD") with partial scan will leave
      // an unresolved symref as its target e.g. refs/heads/master
      // was not read by the partial scan. Scan everything instead.
      return getRefs(ALL).get(name);
    }
  }
  return r;
}

代码示例来源: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);
}

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

? getRef().getName()
    : getRef().getLeaf().getName();
if (myName.startsWith(Constants.R_HEADS) && !getRepository().isBare()) {

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

private void addSubmodule(String name, String url, String path,
    String revision, List<CopyFile> copyfiles, List<LinkFile> linkfiles,
    Git git) throws GitAPIException, IOException {
  assert (!repo.isBare());
  assert (git != null);
  if (!linkfiles.isEmpty()) {
    throw new UnsupportedOperationException(
        JGitText.get().nonBareLinkFilesNotSupported);
  }
  SubmoduleAddCommand add = git.submoduleAdd().setName(name).setPath(path)
      .setURI(url);
  if (monitor != null)
    add.setProgressMonitor(monitor);
  Repository subRepo = add.call();
  if (revision != null) {
    try (Git sub = new Git(subRepo)) {
      sub.checkout().setName(findRef(revision, subRepo)).call();
    }
    subRepo.close();
    git.add().addFilepattern(path).call();
  }
  for (CopyFile copyfile : copyfiles) {
    copyfile.copy();
    git.add().addFilepattern(copyfile.dest).call();
  }
}

相关文章

Repository类方法