public boolean isRepositoryCorrupted() { boolean result = false; try { git.status().call(); } catch (Exception e) { result = true; } return result; }
/** * @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 ); } }
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; } }
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 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()); }
@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); }
private static Set<String> getModifiedFiles(Git git) throws NoWorkTreeException, GitAPIException { Status status = git.status().call(); return status.getModified(); }
private static Set<String> getModifiedFiles(Git git) throws NoWorkTreeException, GitAPIException { Status status = git.status().call(); return status.getModified(); }
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; } }
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()); } } } }
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()); } } } }
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) {
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) {
upstreamCommit)) { org.eclipse.jgit.api.Status status = Git.wrap(repo) .status().setIgnoreSubmodules(IgnoreSubmoduleMode.ALL).call(); if (status.hasUncommittedChanges()) { List<String> list = new ArrayList<>();
/** * Status. * * @return the status * @throws GitAPIException the exception */ public Status status() throws GitAPIException { if (!isUndefined()) { return git.status().call(); } return null; }
Status status = Git.wrap(submoduleRepo).status().call(); 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; } }
@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); }
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<>(); }
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()); } }