org.eclipse.jgit.api.Git.status()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(255)

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

Git.status介绍

[英]Return a command object to execute a status command
[中]返回命令对象以执行状态命令

代码示例

代码示例来源:origin: gocd/gocd

public boolean isRepositoryCorrupted() {
  boolean result = false;
  try {
    git.status().call();
  } catch (Exception e) {
    result = true;
  }
  return result;
}

代码示例来源:origin: apache/usergrid

/**
 * @param gitConfigFolder e.g. /your/project/root/.git
 *
 * @return Returns true if 'git status' has modified files inside the 'Changes to be committed' section
 */
public static boolean isCommitNecessary( String gitConfigFolder ) throws MojoExecutionException {
  try {
    Repository repo = new FileRepository( gitConfigFolder );
    Git git = new Git( repo );
    Status status = git.status().call();
    Set<String> modified = status.getModified();
    return ( modified.size() != 0 );
  }
  catch ( Exception e ) {
    throw new MojoExecutionException( "Error trying to find out if git commit is needed", e );
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-config

private boolean isClean(Git git, String label) {
  StatusCommand status = git.status();
  try {
    BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(git.getRepository(), label);
    boolean isBranchAhead = trackingStatus != null && trackingStatus.getAheadCount() > 0;
    return status.call().isClean() && !isBranchAhead;
  }
  catch (Exception e) {
    String message = "Could not execute status command on local repository. Cause: ("
        + e.getClass().getSimpleName() + ") " + e.getMessage();
    warn(message, e);
    return false;
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-config

protected boolean shouldPull(Git git) throws GitAPIException {
  boolean shouldPull;
  if (this.refreshRate > 0 && System.currentTimeMillis() - this.lastRefresh < (this.refreshRate * 1000)) {
    return false;
  }
  Status gitStatus = git.status().call();
  boolean isWorkingTreeClean = gitStatus.isClean();
  String originUrl = git.getRepository().getConfig().getString("remote", "origin",
      "url");
  if (this.forcePull && !isWorkingTreeClean) {
    shouldPull = true;
    logDirty(gitStatus);
  }
  else {
    shouldPull = isWorkingTreeClean && originUrl != null;
  }
  if (!isWorkingTreeClean && !this.forcePull) {
    this.logger.info("Cannot pull from remote " + originUrl
        + ", the working tree is not clean.");
  }
  return shouldPull;
}

代码示例来源:origin: oracle/helidon

private void pull() throws GitAPIException {
  Git git = recordGit(Git.wrap(repository));
  PullCommand pull = git.pull()
      .setRebase(true);
  PullResult result = pull.call();
  if (!result.isSuccessful()) {
    LOGGER.log(Level.WARNING, () -> String.format("Cannot pull from git '%s', branch '%s'", uri.toASCIIString(), branch));
    if (LOGGER.isLoggable(Level.FINEST)) {
      Status status = git.status().call();
      LOGGER.finest(() -> "git status cleanliness: " + status.isClean());
      if (!status.isClean()) {
        LOGGER.finest(() -> "git status uncommitted changes: " + status.getUncommittedChanges());
        LOGGER.finest(() -> "git status untracked: " + status.getUntracked());
      }
    }
  } else {
    LOGGER.fine("Pull was successful.");
  }
  LOGGER.finest(() -> "git rebase result: " + result.getRebaseResult().getStatus().name());
  LOGGER.finest(() -> "git fetch result: " + result.getFetchResult().getMessages());
}

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

@Signature
public Memory status(@Nullable Set<String> paths, ArrayMemory settings) throws GitAPIException {
  StatusCommand status = getWrappedObject().status();
  if (paths != null) {
    for (String path : paths) {
      status.addPath(path);
    }
  }
  if (settings != null && settings.isNotNull()) {
    if (settings.containsKey("ignoreSubmoduleMode")) {
      status.setIgnoreSubmodules(SubmoduleWalk.IgnoreSubmoduleMode.valueOf(settings.valueOfIndex("ignoreSubmoduleMode").toString()));
    }
  }
  Status call = status.call();
  return GitUtils.valueOf(call);
}

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

private static Set<String> getModifiedFiles(Git git) throws NoWorkTreeException, GitAPIException {
  Status status = git.status().call();
  return status.getModified();
}

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

private static Set<String> getModifiedFiles(Git git) throws NoWorkTreeException, GitAPIException {
  Status status = git.status().call();
  return status.getModified();
}

代码示例来源:origin: git-commit-id/maven-git-commit-id-plugin

public static boolean isRepositoryInDirtyState(Repository repo) throws GitAPIException {
  Git git = Git.wrap(repo);
  Status status = git.status().call();

  // Git describe doesn't mind about untracked files when checking if
  // repo is dirty. JGit does this, so we cannot use the isClean method
  // to get the same behaviour. Instead check dirty state without
  // status.getUntracked().isEmpty()
  boolean isDirty = !(status.getAdded().isEmpty()
    && status.getChanged().isEmpty()
    && status.getRemoved().isEmpty()
    && status.getMissing().isEmpty()
    && status.getModified().isEmpty()
    && status.getConflicting().isEmpty());

  return isDirty;
 }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        Status status = git.status().call();
        System.out.println("Added: " + status.getAdded());
        System.out.println("Changed: " + status.getChanged());
        System.out.println("Conflicting: " + status.getConflicting());
        System.out.println("ConflictingStageState: " + status.getConflictingStageState());
        System.out.println("IgnoredNotInIndex: " + status.getIgnoredNotInIndex());
        System.out.println("Missing: " + status.getMissing());
        System.out.println("Modified: " + status.getModified());
        System.out.println("Removed: " + status.getRemoved());
        System.out.println("Untracked: " + status.getUntracked());
        System.out.println("UntrackedFolders: " + status.getUntrackedFolders());
      }
    }
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        Status status = git.status().call();
        System.out.println("Added: " + status.getAdded());
        System.out.println("Changed: " + status.getChanged());
        System.out.println("Conflicting: " + status.getConflicting());
        System.out.println("ConflictingStageState: " + status.getConflictingStageState());
        System.out.println("IgnoredNotInIndex: " + status.getIgnoredNotInIndex());
        System.out.println("Missing: " + status.getMissing());
        System.out.println("Modified: " + status.getModified());
        System.out.println("Removed: " + status.getRemoved());
        System.out.println("Untracked: " + status.getUntracked());
        System.out.println("UntrackedFolders: " + status.getUntrackedFolders());
      }
    }
  }
}

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

System.out.println("Listing uncommitted changes:");
try (Git git = new Git(repository)) {
  Status status = git.status().call();
  Set<String> conflicting = status.getConflicting();
  for(String conflict : conflicting) {

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

System.out.println("Listing uncommitted changes:");
try (Git git = new Git(repository)) {
  Status status = git.status().call();
  Set<String> conflicting = status.getConflicting();
  for(String conflict : conflicting) {

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

upstreamCommit)) {
org.eclipse.jgit.api.Status status = Git.wrap(repo)
    .status().setIgnoreSubmodules(IgnoreSubmoduleMode.ALL).call();
if (status.hasUncommittedChanges()) {
  List<String> list = new ArrayList<>();

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

/**
 * Status.
 *
 * @return the status
 * @throws GitAPIException the exception
 */
public Status status() throws GitAPIException {
  if (!isUndefined()) {
    return git.status().call();
  }
  return null;
}

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

Status status = Git.wrap(submoduleRepo).status().call();
return status.isClean() ? SubmoduleDeinitStatus.SUCCESS
    : SubmoduleDeinitStatus.DIRTY;

代码示例来源:origin: org.ajoberstar.reckon/reckon-core

private boolean isClean() {
 try {
  return new Git(repo).status().call().isClean();
 } catch (GitAPIException e) {
  logger.error("Failed to determine status of repository. Assuming not clean.", e);
  // TODO should this throw up?
  return false;
 }
}

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

@Override
protected void run() throws Exception {
  StatusCommand statusCommand = new Git(db).status();
  if (filterPaths != null && filterPaths.size() > 0)
    for (String path : filterPaths)
      statusCommand.addPath(path);
  org.eclipse.jgit.api.Status status = statusCommand.call();
  printStatus(status);
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

private Collection<String> applyStashIfNeeded() throws GitAPIException {
  if (!git.stashList().call().isEmpty()) {
    try {
      git.stashApply().call();
    } catch (final Exception e) {
      val conflicts = git.status().call().getConflicting();
      git.close();
      return conflicts;
    }
  }
  return new HashSet<>();
}

代码示例来源:origin: org.wildfly.core/wildfly-server

protected void gitCommit(String msg) {
  try (Git git = repository.getGit()) {
    if(!git.status().call().isClean()) {
      git.commit().setMessage(msg).setAll(true).setNoVerify(true).call();
    }
  } catch (GitAPIException e) {
    MGMT_OP_LOGGER.failedToStoreConfiguration(e, file.getName());
  }
}

相关文章