@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)); }
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; }
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()); } } } }
Set<String> missing = status.getMissing(); for(String miss : missing) { System.out.println("Missing: " + miss);
Set<String> missing = status.getMissing(); for(String miss : missing) { System.out.println("Missing: " + miss);
/** * Returns the removed (undeployed) artifact set relevant to the current status of the repository * * @param status git status * @return artifact names set */ private Set<String> getRemovedArtifacts(Status status) { return status.getMissing(); }
public boolean isDirty() throws IOException { Status status = git.status().call(); return !(status.getAdded().isEmpty() && status.getRemoved().isEmpty() && status.getChanged().isEmpty() && status.getMissing().isEmpty() && status.getModified().isEmpty() && status.getConflicting().isEmpty()); }
private boolean localRepoIsDirty(Git git) throws GitAPIException { Status status = git.status().call(); List potentialIssues = new ArrayList(); potentialIssues.addAll(status.getConflicting()); potentialIssues.addAll(status.getIgnoredNotInIndex()); potentialIssues.addAll(status.getAdded()); potentialIssues.addAll(status.getChanged()); potentialIssues.addAll(status.getMissing()); potentialIssues.addAll(status.getModified()); potentialIssues.addAll(status.getRemoved()); potentialIssues.addAll(status.getUncommittedChanges()); potentialIssues.addAll(status.getUntracked()); potentialIssues.addAll(status.getUntrackedFolders()); return !potentialIssues.isEmpty(); }
@Override public Set<String> getMissing() throws RepositoryException { return wrap(() -> git.status().call().getMissing()); }
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; } }
@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(String.format("Dirty files found: %s", dirties)); }
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(); }
@Override public void removeContent(ContentReference reference) { final Path realFile = getDeploymentContentFile(reference.getHash()); super.removeContent(reference); if (!Files.exists(realFile)) { try (Git git = gitRepository.getGit()) { Set<String> deletedFiles = git.status().call().getMissing(); RmCommand rmCommand = git.rm(); for (String file : deletedFiles) { rmCommand.addFilepattern(file); } rmCommand.addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new RuntimeException(ex); } } }
@Override public void removeContent(ContentReference reference) { final Path realFile = getDeploymentContentFile(reference.getHash()); super.removeContent(reference); if (!Files.exists(realFile)) { try (Git git = gitRepository.getGit()) { Set<String> deletedFiles = git.status().call().getMissing(); RmCommand rmCommand = git.rm(); for (String file : deletedFiles) { rmCommand.addFilepattern(file); } rmCommand.addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new RuntimeException(ex); } } }
@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); } }
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"); } }
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()); }