Refine search
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()); } } } }
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; } }
public static ArrayMemory valueOf(Status value) { ArrayMemory memory = new ArrayMemory(); memory.refOfIndex("added").assign(ArrayMemory.ofStringCollection(value.getAdded())); memory.refOfIndex("changed").assign(ArrayMemory.ofStringCollection(value.getChanged())); memory.refOfIndex("conflicting").assign(ArrayMemory.ofStringCollection(value.getConflicting())); memory.refOfIndex("ignoredNotInIndex").assign(ArrayMemory.ofStringCollection(value.getIgnoredNotInIndex())); memory.refOfIndex("missing").assign(ArrayMemory.ofStringCollection(value.getMissing())); memory.refOfIndex("modified").assign(ArrayMemory.ofStringCollection(value.getModified())); memory.refOfIndex("removed").assign(ArrayMemory.ofStringCollection(value.getRemoved())); memory.refOfIndex("uncommittedChanges").assign(ArrayMemory.ofStringCollection(value.getUncommittedChanges())); memory.refOfIndex("untracked").assign(ArrayMemory.ofStringCollection(value.getUntracked())); memory.refOfIndex("untrackedFolders").assign(ArrayMemory.ofStringCollection(value.getUntrackedFolders())); return memory; }
@SuppressWarnings("unchecked") private void logDirty(Status status) { Set<String> dirties = dirties(status.getAdded(), status.getChanged(), status.getRemoved(), status.getMissing(), status.getModified(), status.getConflicting(), status.getUntracked()); this.logger.warn(format("Dirty files found: %s", dirties)); }
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()); }
git = Git.open(gitRepository); File dst = new File(git.getRepository().getWorkTree(), "fabric/profiles"); git.add().addFilepattern(".").call(); for (String missing : git.status().call().getMissing()) { git.rm().addFilepattern(missing).call();
@Override public void flush(boolean success) { if (success) { try (Git git = gitRepository.getGit()) { Status status = git.status().call(); if (!status.isClean()) { String message = git.getRepository().parseCommit(git.getRepository().resolve(HEAD)).getFullMessage(); if(! status.getUntracked().isEmpty() || ! status.getUntrackedFolders().isEmpty()) { AddCommand addCommand = git.add(); for(String untracked : status.getUntrackedFolders()) { addCommand = addCommand.addFilepattern(untracked); } for(String untracked : status.getUntracked()) { addCommand = addCommand.addFilepattern(untracked); } addCommand.call(); } git.commit().setMessage(message).setAmend(true).setAll(true).setNoVerify(true).call(); } } catch (RevisionSyntaxException | IOException | GitAPIException ex) { throw new RuntimeException(ex); } } }
File wcDir = git.getRepository().getWorkTree(); Status status = git.status().call(); if (!status.isClean()) { boolean amend = false; if (status.getUntracked().size() == 0 && status.getMissing().size() == 0 && status.getModified().size() == 1) { if ("etc/io.fabric8.mq.fabric.server-broker.cfg".equals(status.getModified().iterator().next())) { amend = true; git.add() .addFilepattern(".") .call();
Git git = null; try { git = Git.open(repoDir); CheckoutCommand coCmd = git.checkout(); git.merge() .setStrategy(MergeStrategy.OURS) .include(ref) .addFilepattern(filename).call(); org.eclipse.jgit.api.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("Missing: " + status.getMissing()); System.out.println("Modified: " + status.getModified()); System.out.println("Removed: " + status.getRemoved()); System.out.println("Untracked: " + status.getUntracked());
private void updateRepositoryIfDirty(Repository repo, AbstractExtensionEvent event, Bundle bundle) throws IOException, NoFilepatternException, NoHeadException, NoMessageException, ConcurrentRefUpdateException, WrongRepositoryStateException Git git = new Git(repo); git.add().addFilepattern(path).call(); Status status = git.status().call(); if (!status.getAdded().isEmpty() || !status.getChanged().isEmpty() || !status.getMissing().isEmpty() || !status.getRemoved().isEmpty() || !status.getUntracked().isEmpty()) git.commit().
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; } }
boolean isGitDirectoryClean() throws GitAPIException { final Status status = new Git(gitRepo).status().call(); return status.isClean() && !status.hasUncommittedChanges(); }
public synchronized void backup() throws Exception { repo.add().setUpdate(false).addFilepattern(".").call(); Status status = repo.status().setIgnoreSubmodules(SubmoduleWalk.IgnoreSubmoduleMode.ALL).call(); log.debug("status.getUncommittedChanges() = " + status.getUncommittedChanges()); if (!status.getUncommittedChanges().isEmpty()) { for (String missingPath : status.getMissing()) { repo.rm().addFilepattern(missingPath).call(); } log.info("Changes detected in the following files: " + status.getUncommittedChanges()); repo.commit() .setMessage("Backing up data dir") .setAuthor("AppRunner BackupService", "noemail@example.org") .call(); Iterable<PushResult> pushResults = repo.push().call(); for (PushResult pushResult : pushResults) { log.info("Result of pushing to remote: " + pushResult.getRemoteUpdates()); } } else { log.info("No changes to back up"); } }
/** * @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 ); } }
Log.info("[{}] Writing commit", name); contents.write(); Git git = new Git(getJGitRepository()); Log.info("[{}] Getting missing files", name); Set<String> missingFiles = git.status().call().getMissing(); for (String missing : missingFiles) { Log.info("[{}] Git rm {}", name, missing); git.rm().setCached(true).addFilepattern(missing).call();
@Override public void addCommitPush() { try { Git git = gitOpen(); git.add().addFilepattern(".").call(); // status Status status=git.status().call(); // rm the deleted ones if(status.getMissing().size() >0){ for(String rm : status.getMissing()){ git.rm().addFilepattern(rm).call(); } } // commit and push if needed if(!status.hasUncommittedChanges()){ log.debug("not commiting git, because there are no changes"); return; } git.commit().setMessage("Automatic commit by releasetrain").call(); git.push().setCredentialsProvider(credentialsProvider()).call(); } catch (Exception e) { throw new GitException(e.getMessage(), e); } }
Status gitStatus = git.status().call(); if (!gitStatus.isClean()) { this.getLogger().debug("Commit repairnator files..."); filesChanged.addAll(gitStatus.getUncommittedChanges()); filesChanged.addAll(gitStatus.getUntracked()); filesChanged.addAll(gitStatus.getUntrackedFolders()); .directory(git.getRepository().getDirectory().getParentFile()).inheritIO(); git.commit() .setMessage("repairnator: add files created to push \n"+commitMsg) .setCommitter(this.getCommitterIdent())
protected boolean isClean(Git git) throws GitAPIException, IOException { if (git.getRepository().getBranch().equals(BASE_BRANCH)) { Optional<Ref> baseBranch = getOriginHead(git); if (baseBranch.isPresent()) { RevWalk walk = new RevWalk(git.getRepository()); RevCommit baseCommit = walk.parseCommit(getBaseObjectId(git)); RevCommit headCommit = walk.parseCommit(getHead(git).getObjectId()); log.info(String.format("origin/master sha: [%s], head: [%s]", baseCommit.getName(), headCommit.getName())); return baseCommit.equals(headCommit) && git.status().call().isClean(); } else { // there is no origin Status status = git.status().call(); boolean isClean = status.isClean(); if (!isClean) { log.info("Untracked Folders: " + Arrays.toString(status.getUntrackedFolders().toArray())); log.info("Untracked Files: " + Arrays.toString(status.getUntracked().toArray())); log.info("Changed Files: " + Arrays.toString(status.getChanged().toArray())); log.info("Added Files: " + Arrays.toString(status.getAdded().toArray())); log.info("Removed Files: " + Arrays.toString(status.getRemoved().toArray())); log.info("Uncommitted Files: " + Arrays.toString(status.getUncommittedChanges().toArray())); } return isClean; } } return false; }
public void addCommit(String[] patterns, String message) throws GitAPIException { if (!message.isEmpty()) { synchronized (COMMIT_LOCK) { AddCommand add = this.git.add(); Status status = this.git.status().call(); for (String pattern : patterns) { add.addFilepattern(pattern); } if (!status.getMissing().isEmpty() || !status.getRemoved().isEmpty()) { RmCommand remove = this.git.rm(); for (String file : Iterables.concat(status.getMissing(), status.getRemoved())) { remove.addFilepattern(file); } remove.call(); } add.call(); CommitCommand commit = this.git.commit(); commit.setMessage(message); commit.call(); } } postEventMap(); }