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; } }
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()); }
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; }
private boolean isClean() { try { return git.status().call().isClean(); } catch (GitAPIException e) { throw new RuntimeException(e); } }
private boolean isClean(Git git) { StatusCommand status = git.status(); try { return status.call().isClean(); } catch (Exception e) { String message = "Could not execute status command on local repository. Cause: (" + e.getClass().getSimpleName() + ") " + e.getMessage(); warn(message, e); return false; } }
/** * Checks that underlying repository is dirty (modified with uncommitted changes). * @return true if the underlying repository is dirty, false otherwise * @throws GitAPIException if a git eeror occured while computing status * @throws NoWorkTreeException if the underlying repsoitory directory is not git managed */ public static boolean isDirty(Git git) throws NoWorkTreeException, GitAPIException { Status status = git.status().call(); return !status.isClean(); }
return status.isClean() ? SubmoduleDeinitStatus.SUCCESS : SubmoduleDeinitStatus.DIRTY;
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; } }
public boolean hasChangesInFile(RepositoryFileReference ref) { try { if (!this.git.status().call().isClean()) { List<DiffEntry> diffEntries = this.git.diff().call(); List<DiffEntry> entries = diffEntries.stream() // we use String::startsWith() and RepositoryFileReference::getParent() // because the component is considered changed, if any file of this component is changed. // -> check if any file in the folder is changed .filter(item -> item.getNewPath().startsWith(BackendUtils.getPathInsideRepo(ref.getParent()))) .collect(Collectors.toList()); return entries.size() > 0; } } catch (GitAPIException e) { LOGGER.trace(e.getMessage(), e); } return false; }
private void createStashIfNeeded() throws GitAPIException { if (!git.status().call().isClean()) { git.stashCreate().call(); } }
boolean isGitDirectoryClean() throws GitAPIException { final Status status = new Git(gitRepo).status().call(); return status.isClean() && !status.hasUncommittedChanges(); }
public /*public for testing*/ boolean shouldPull(Git git) throws GitAPIException { boolean shouldPull; 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; }
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()); } }
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()); } }
/** * Commit all changes if there are uncommitted changes. * * @param msg the commit message. * @throws GitAPIException */ public void commit(String msg) throws GitAPIException { try (Git git = getGit()) { Status status = git.status().call(); if (!status.isClean()) { git.commit().setMessage(msg).setAll(true).setNoVerify(true).call(); } } } }
/** * Commit all changes if there are uncommitted changes. * * @param msg the commit message. * @throws GitAPIException */ public void commit(String msg) throws GitAPIException { try (Git git = getGit()) { Status status = git.status().call(); if (!status.isClean()) { git.commit().setMessage(msg).setAll(true).setNoVerify(true).call(); } } } }
private void convertStatus(org.eclipse.jgit.api.Status status) { if (!status.hasUncommittedChanges() && status.isClean()) { mResult.append("Nothing to commit, working directory clean"); return; } // TODO if working dir not clean convertStatusSet("Added files:", status.getAdded()); convertStatusSet("Changed files:", status.getChanged()); convertStatusSet("Removed files:", status.getRemoved()); convertStatusSet("Missing files:", status.getMissing()); convertStatusSet("Modified files:", status.getModified()); convertStatusSet("Conflicting files:", status.getConflicting()); convertStatusSet("Untracked files:", status.getUntracked()); }
private void convertStatus(org.eclipse.jgit.api.Status status) { if (!status.hasUncommittedChanges() && status.isClean()) { mResult.append("Nothing to commit, working directory clean"); return; } // TODO if working dir not clean convertStatusSet("Added files:", status.getAdded()); convertStatusSet("Changed files:", status.getChanged()); convertStatusSet("Removed files:", status.getRemoved()); convertStatusSet("Missing files:", status.getMissing()); convertStatusSet("Modified files:", status.getModified()); convertStatusSet("Conflicting files:", status.getConflicting()); convertStatusSet("Untracked files:", status.getUntracked()); }
@Override public void commitAllChanges(Git git, String message) throws JGitFlowReleaseException { try { Status status = git.status().call(); if (!status.isClean()) { git.add().addFilepattern(".").call(); git.commit().setMessage(message).call(); } } catch (GitAPIException e) { throw new JGitFlowReleaseException("error committing changes: " + e.getMessage(), e); } }
@Before public void setUp() throws Exception { super.setUp(); repoDir = createTempDirectory(); init(); DataSource dataSource = new DataSource(); dataSource.setName(DefaultSources.PUBLIC); dataSource.setLocation(repoDir.getAbsolutePath()); repo = new SmSnGitRepository(brain, dataSource); git = repo.getGit(); assertNotNull(git.getRepository().getRef(Constants.HEAD)); assertTrue(git.status().call().isClean()); addOrigin(); }