List of usage examples for org.eclipse.jgit.api Status getUntracked
public Set<String> getUntracked()
From source file:bluej.groupwork.git.GitStatusCommand.java
License:Open Source License
@Override public TeamworkCommandResult getResult() { LinkedList<TeamStatusInfo> returnInfo = new LinkedList<>(); try (Git repo = Git.open(this.getRepository().getProjectPath().getParentFile())) { Status s = repo.status().call(); File gitPath = new File(this.getRepository().getProjectPath().getParent()); s.getMissing().stream().map((item) -> new TeamStatusInfo(new File(gitPath, item), "", null, TeamStatusInfo.STATUS_NEEDSCHECKOUT)).forEach((teamInfo) -> { returnInfo.add(teamInfo); });/*from w w w . j a va 2 s . c om*/ s.getUncommittedChanges().stream().map((item) -> new TeamStatusInfo(new File(gitPath, item), "", null, TeamStatusInfo.STATUS_NEEDSCOMMIT)).forEach((teamInfo) -> { returnInfo.add(teamInfo); }); s.getConflicting().stream().map((item) -> new TeamStatusInfo(new File(gitPath, item), "", null, TeamStatusInfo.STATUS_NEEDSMERGE)).forEach((teamInfo) -> { returnInfo.add(teamInfo); }); s.getUntracked().stream().map( (item) -> new TeamStatusInfo(new File(gitPath, item), "", null, TeamStatusInfo.STATUS_NEEDSADD)) .forEach((teamInfo) -> { returnInfo.add(teamInfo); }); s.getUntrackedFolders().stream().map( (item) -> new TeamStatusInfo(new File(gitPath, item), "", null, TeamStatusInfo.STATUS_NEEDSADD)) .forEach((teamInfo) -> { returnInfo.add(teamInfo); }); s.getRemoved().stream().map( (item) -> new TeamStatusInfo(new File(gitPath, item), "", null, TeamStatusInfo.STATUS_REMOVED)) .forEach((teamInfo) -> { returnInfo.add(teamInfo); }); } catch (IOException | GitAPIException | NoWorkTreeException ex) { Logger.getLogger(GitStatusCommand.class.getName()).log(Level.SEVERE, null, ex); } if (listener != null) { while (!returnInfo.isEmpty()) { TeamStatusInfo teamInfo = (TeamStatusInfo) returnInfo.removeFirst(); listener.gotStatus(teamInfo); } listener.statusComplete(new GitStatusHandle(getRepository())); } return new TeamworkCommandResult(); }
From source file:ch.sourcepond.maven.release.scm.git.GitRepository.java
License:Apache License
@Override public void errorIfNotClean() throws SCMException { final Status status = currentStatus(); final boolean isClean = status.isClean(); if (!isClean) { final SCMException exception = new SCMException( "Cannot release with uncommitted changes. Please check the following files:"); final Set<String> uncommittedChanges = status.getUncommittedChanges(); if (uncommittedChanges.size() > 0) { exception.add("Uncommitted:"); for (final String path : uncommittedChanges) { exception.add(" * %s", path); }//from w w w . ja va2 s . c o m } final Set<String> untracked = status.getUntracked(); if (untracked.size() > 0) { exception.add("Untracked:"); for (final String path : untracked) { exception.add(" * %s", path); } } throw exception.add("Please commit or revert these changes before releasing."); } }
From source file:com.buildautomation.jgit.api.ListUncommittedChanges.java
License:Apache License
public static void listUncommittedChanges() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { 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("Conflicting: " + conflict); }/*from www . j a va 2 s . co m*/ Set<String> added = status.getAdded(); for (String add : added) { System.out.println("Added: " + add); } Set<String> changed = status.getChanged(); for (String change : changed) { System.out.println("Change: " + change); } Set<String> missing = status.getMissing(); for (String miss : missing) { System.out.println("Missing: " + miss); } Set<String> modified = status.getModified(); for (String modify : modified) { System.out.println("Modification: " + modify); } Set<String> removed = status.getRemoved(); for (String remove : removed) { System.out.println("Removed: " + remove); } Set<String> uncommittedChanges = status.getUncommittedChanges(); for (String uncommitted : uncommittedChanges) { System.out.println("Uncommitted: " + uncommitted); } Set<String> untracked = status.getUntracked(); for (String untrack : untracked) { System.out.println("Untracked: " + untrack); } Set<String> untrackedFolders = status.getUntrackedFolders(); for (String untrack : untrackedFolders) { System.out.println("Untracked Folder: " + untrack); } Map<String, StageState> conflictingStageState = status.getConflictingStageState(); for (Map.Entry<String, StageState> entry : conflictingStageState.entrySet()) { System.out.println("ConflictingState: " + entry); } } } }
From source file:com.buildautomation.jgit.api.ShowStatus.java
License:Apache License
public static void showStatus() 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()); }//from w ww. ja va2s . com } }
From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java
License:Apache License
public GitDiffs getDiffs(String branch, String path) throws Exception { fetch();/* w ww .j av a 2 s. c o m*/ GitDiffs diffs = new GitDiffs(); ObjectId remoteHead = localRepo.resolve("origin/" + branch + "^{tree}"); if (remoteHead == null) throw new IOException("Unable to determine Git Diffs due to missing remote HEAD"); CanonicalTreeParser newTreeIter = new CanonicalTreeParser(); newTreeIter.reset(localRepo.newObjectReader(), remoteHead); DiffCommand dc = git.diff().setNewTree(newTreeIter); if (path != null) dc.setPathFilter(PathFilter.create(path)); dc.setShowNameAndStatusOnly(true); for (DiffEntry diff : dc.call()) { if (diff.getChangeType() == ChangeType.ADD || diff.getChangeType() == ChangeType.COPY) { diffs.add(DiffType.MISSING, diff.getNewPath()); } else if (diff.getChangeType() == ChangeType.MODIFY) { diffs.add(DiffType.DIFFERENT, diff.getNewPath()); } else if (diff.getChangeType() == ChangeType.DELETE) { diffs.add(DiffType.EXTRA, diff.getOldPath()); } else if (diff.getChangeType() == ChangeType.RENAME) { diffs.add(DiffType.MISSING, diff.getNewPath()); diffs.add(DiffType.EXTRA, diff.getOldPath()); } } // we're purposely omitting folders Status status = git.status().addPath(path).call(); for (String untracked : status.getUntracked()) { if (!untracked.startsWith(path + "/Archive/")) diffs.add(DiffType.EXTRA, untracked); } for (String added : status.getAdded()) { diffs.add(DiffType.EXTRA, added); } for (String missing : status.getMissing()) { diffs.add(DiffType.MISSING, missing); } for (String removed : status.getRemoved()) { diffs.add(DiffType.MISSING, removed); } for (String changed : status.getChanged()) { diffs.add(DiffType.DIFFERENT, changed); } for (String modified : status.getModified()) { diffs.add(DiffType.DIFFERENT, modified); } for (String conflict : status.getConflicting()) { diffs.add(DiffType.DIFFERENT, conflict); } return diffs; }
From source file:com.chungkwong.jgitgui.GitTreeItem.java
License:Open Source License
@Override public Node getContentPage() { GridPane node = new GridPane(); try {/*from w w w . jav a 2s .c o m*/ Status status = ((Git) getValue()).status().call(); Set<String> untrackedSet = new HashSet<>(status.getUntrackedFolders()); untrackedSet.addAll(status.getUntracked()); untrackedSet.removeAll(status.getIgnoredNotInIndex()); TitledPane untracked = createList( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("UNTRACKED FILE"), untrackedSet); TitledPane missing = createList( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("MISSING"), status.getMissing()); TitledPane modified = createList( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("MODIFIED"), status.getModified()); TitledPane added = createList( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("ADDED"), status.getAdded()); TitledPane removed = createList( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("REMOVED"), status.getRemoved()); TitledPane changed = createList( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("CHANGED"), status.getChanged()); Button add = new Button( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("ADD")); add.setOnAction((e) -> gitAdd(untracked, modified, added, changed)); Button commit = new Button( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("COMMIT")); commit.setOnAction((e) -> gitCommit(added, removed, changed)); Button clean = new Button( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("CLEAN")); clean.setOnAction((e) -> gitClean(untracked)); node.addColumn(0, untracked, missing, modified, add); node.addColumn(1, added, removed, changed, commit, clean); } catch (Exception ex) { Logger.getLogger(GitTreeItem.class.getName()).log(Level.SEVERE, null, ex); Util.informUser(ex); } return node; }
From source file:com.docmd.behavior.GitManager.java
public void gitStatus(JTextArea console) throws GitAPIException { Status status = git.status().call(); console.append("\n\n$git status"); boolean flag = false; if ((!(status.getAdded().isEmpty())) || (!(status.getChanged().isEmpty())) || (!(status.getRemoved().isEmpty()))) { console.append("\n\n>>> STAGED CHANGES:"); if (!(status.getAdded().isEmpty())) { console.append("\n\n> Added:"); for (String s : status.getAdded()) { console.append("\n" + s); flag = true;/*from w w w . ja va2 s .c o m*/ } } if (!(status.getChanged().isEmpty())) { console.append("\n\n> Changed:"); for (String s : status.getChanged()) { console.append("\n" + s); flag = true; } } if (!(status.getRemoved().isEmpty())) { console.append("\n\n> Removed:"); for (String s : status.getRemoved()) { console.append("\n" + s); flag = true; } } } if (!(status.getConflicting().isEmpty())) { console.append("\n\n> Conflicting:"); for (String s : status.getConflicting()) { console.append("\n" + s); flag = true; } } if (!(status.getIgnoredNotInIndex().isEmpty())) { console.append("\n\n> IgnoredNotInIndex:"); for (String s : status.getIgnoredNotInIndex()) { console.append("\n" + s); flag = true; } } if ((!(status.getModified().isEmpty())) || (!(status.getMissing().isEmpty())) || (!(status.getUntracked().isEmpty())) || (!(status.getUntrackedFolders().isEmpty()))) { console.append("\n\n>>> UNSTAGED CHANGES:"); if (!(status.getModified().isEmpty())) { console.append("\n\n> Modified:"); for (String s : status.getModified()) { console.append("\n" + s); flag = true; } } if (!(status.getMissing().isEmpty())) { console.append("\n\n> Deleted:"); for (String s : status.getMissing()) { console.append("\n" + s); flag = true; } } if (!(status.getUntracked().isEmpty())) { console.append("\n\n> Untracked:"); for (String s : status.getUntracked()) { console.append("\n" + s); flag = true; } } if (!(status.getUntrackedFolders().isEmpty())) { console.append("\n\n> UntrackedFolders:"); for (String s : status.getUntrackedFolders()) { console.append("\n" + s); flag = true; } } } if (!flag) { console.append("\nNo changes."); } }
From source file:com.docmd.behavior.GitManager.java
public String[] getChanges() throws GitAPIException { ArrayList<String> al = new ArrayList<String>(); Status status = git.status().call(); if (!(status.getModified().isEmpty())) { for (String s : status.getModified()) { al.add(s);//ww w . j a v a 2s.com } } if (!(status.getMissing().isEmpty())) { for (String s : status.getMissing()) { al.add("[RMV]" + s); } } if (!(status.getUntracked().isEmpty())) { for (String s : status.getUntracked()) { al.add(s); } } if (!(status.getUntrackedFolders().isEmpty())) { for (String s : status.getUntrackedFolders()) { al.add(s); } } String changes[] = new String[al.size()]; for (int i = 0; i < changes.length; i++) changes[i] = al.get(i); return changes; }
From source file:com.google.devtools.build.lib.bazel.repository.GitCloneFunction.java
License:Open Source License
private boolean isUpToDate(GitRepositoryDescriptor descriptor) { // Initializing/checking status of/etc submodules cleanly is hard, so don't try for now. if (descriptor.initSubmodules) { return false; }//from w ww. j a va 2 s. c o m Repository repository = null; try { repository = new FileRepositoryBuilder() .setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile()).setMustExist(true) .build(); ObjectId head = repository.resolve(Constants.HEAD); ObjectId checkout = repository.resolve(descriptor.checkout); if (head != null && checkout != null && head.equals(checkout)) { Status status = Git.wrap(repository).status().call(); if (!status.hasUncommittedChanges()) { // new_git_repository puts (only) BUILD and WORKSPACE, and // git_repository doesn't add any files. Set<String> untracked = status.getUntracked(); if (untracked.isEmpty() || (untracked.size() == 2 && untracked.contains("BUILD") && untracked.contains("WORKSPACE"))) { return true; } } } } catch (GitAPIException | IOException e) { // Any exceptions here, we'll just blow it away and try cloning fresh. // The fresh clone avoids any weirdness due to what's there and has nicer // error reporting. } finally { if (repository != null) { repository.close(); } } return false; }
From source file:com.google.devtools.build.lib.bazel.repository.GitCloner.java
License:Open Source License
private static boolean isUpToDate(GitRepositoryDescriptor descriptor) { // Initializing/checking status of/etc submodules cleanly is hard, so don't try for now. if (descriptor.initSubmodules) { return false; }// ww w . j ava2 s . c om Repository repository = null; try { repository = new FileRepositoryBuilder() .setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile()).setMustExist(true) .build(); ObjectId head = repository.resolve(Constants.HEAD); ObjectId checkout = repository.resolve(descriptor.checkout); if (head != null && checkout != null && head.equals(checkout)) { Status status = Git.wrap(repository).status().call(); if (!status.hasUncommittedChanges()) { // new_git_repository puts (only) BUILD and WORKSPACE, and // git_repository doesn't add any files. Set<String> untracked = status.getUntracked(); if (untracked.isEmpty() || (untracked.size() == 2 && untracked.contains("BUILD") && untracked.contains("WORKSPACE"))) { return true; } } } } catch (GitAPIException | IOException e) { // Any exceptions here, we'll just blow it away and try cloning fresh. // The fresh clone avoids any weirdness due to what's there and has nicer // error reporting. } finally { if (repository != null) { repository.close(); } } return false; }