Example usage for org.eclipse.jgit.api Status getAdded

List of usage examples for org.eclipse.jgit.api Status getAdded

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Status getAdded.

Prototype

public Set<String> getAdded() 

Source Link

Document

Get files added to the index

Usage

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  .  jav  a 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 www. j  a  v a 2 s.  c  om*/
    }
}

From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java

License:Apache License

public GitDiffs getDiffs(String branch, String path) throws Exception {
    fetch();//  ww  w  . ja v  a 2  s  .  co  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  ww  w  .  j  a  va2s  .co  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   ww w. j a v a 2 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[] getStaged() throws GitAPIException {
    ArrayList<String> al = new ArrayList<String>();
    Status status = git.status().call();
    if (!(status.getAdded().isEmpty())) {
        for (String s : status.getAdded()) {
            al.add(s);/* w ww  . j a v a2  s. c o m*/
        }
    }
    if (!(status.getRemoved().isEmpty())) {
        for (String s : status.getRemoved()) {
            al.add(s);
        }
    }
    if (!(status.getChanged().isEmpty())) {
        for (String s : status.getChanged()) {
            al.add(s);
        }
    }
    String staged[] = new String[al.size()];
    for (int i = 0; i < staged.length; i++)
        staged[i] = al.get(i);
    return staged;
}

From source file:com.nlbhub.nlb.vcs.GitAdapter.java

License:Open Source License

private void initStatuses(boolean processExistentFiles) throws NLBVCSException {
    m_statuses.clear();//from   w w w  . j a v  a  2s . c o m
    try {
        if (processExistentFiles) {
            List<String> filePaths = listRepositoryContents();
            for (final String filePath : filePaths) {
                // Initially mark all repository files as clean
                // (i.e. under version control & without changes)
                m_statuses.put(filePath, Status.Clean);
            }
        }
        org.eclipse.jgit.api.Status status = m_git.status().call();
        putItemsStatus(status.getAdded(), Status.Added);
        putItemsStatus(status.getChanged(), Status.Modified); // ???
        putItemsStatus(status.getModified(), Status.Modified);
        putItemsStatus(status.getConflicting(), Status.Conflict);
        //System.out.println("ConflictingStageState: " + status.getConflictingStageState());
        putItemsStatus(status.getIgnoredNotInIndex(), Status.Ignored);
        putItemsStatus(status.getMissing(), Status.Missing);
        putItemsStatus(status.getRemoved(), Status.Removed);
        putItemsStatus(status.getUntracked(), Status.Unknown);
        putItemsStatus(status.getUntrackedFolders(), Status.Unknown);
    } catch (IOException | GitAPIException e) {
        throw new NLBVCSException("Error while obtaining Git repository status", e);
    }
}

From source file:com.passgit.app.PassGit.java

License:Open Source License

private void processStatus(Status status, PathModel pathModel) {
    boolean untracked = false;

    for (String filename : status.getUntracked()) {
        File untrackedFile = new File(rootPath.toFile(), filename);
        if (untrackedFile.toPath().equals(pathModel.getPath())) {
            untracked = true;/*w  w  w. j a v a  2s. c o m*/
            if (!pathModel.isUntracked()) {
                pathModel.setUntracked(true);

                List<PathModel> recursePath = getRootPathModel().recursePath(pathModel.getPath());

                getPathModelTreeModel().fireChangedEvent(recursePath);
            }
        }
    }

    if (!untracked) {
        if (pathModel.isUntracked()) {
            pathModel.setUntracked(false);

            List<PathModel> recursePath = getRootPathModel().recursePath(pathModel.getPath());

            getPathModelTreeModel().fireChangedEvent(recursePath);
        }
    }

    boolean modified = false;

    for (String filename : status.getModified()) {
        File modifiedFile = new File(rootPath.toFile(), filename);
        if (modifiedFile.toPath().equals(pathModel.getPath())) {
            modified = true;
            if (!pathModel.isModified()) {
                pathModel.setModified(true);

                List<PathModel> recursePath = getRootPathModel().recursePath(pathModel.getPath());

                getPathModelTreeModel().fireChangedEvent(recursePath);
            }
        }
    }

    if (!modified) {
        if (pathModel.isModified()) {
            pathModel.setModified(false);

            List<PathModel> recursePath = getRootPathModel().recursePath(pathModel.getPath());

            getPathModelTreeModel().fireChangedEvent(recursePath);
        }
    }

    boolean added = false;

    for (String filename : status.getAdded()) {
        File addedFile = new File(rootPath.toFile(), filename);
        if (addedFile.toPath().equals(pathModel.getPath())) {
            added = true;
            if (!pathModel.isAdded()) {
                pathModel.setAdded(true);

                List<PathModel> recursePath = getRootPathModel().recursePath(pathModel.getPath());

                getPathModelTreeModel().fireChangedEvent(recursePath);
            }
        }
    }

    if (!added) {
        if (pathModel.isAdded()) {
            pathModel.setAdded(false);

            List<PathModel> recursePath = getRootPathModel().recursePath(pathModel.getPath());

            getPathModelTreeModel().fireChangedEvent(recursePath);
        }
    }

    boolean changed = false;

    for (String filename : status.getChanged()) {
        File changedFile = new File(rootPath.toFile(), filename);
        if (changedFile.toPath().equals(pathModel.getPath())) {
            changed = true;
            if (!pathModel.isChanged()) {
                pathModel.setChanged(true);

                List<PathModel> recursePath = getRootPathModel().recursePath(pathModel.getPath());

                getPathModelTreeModel().fireChangedEvent(recursePath);
            }
        }
    }

    if (!changed) {
        if (pathModel.isChanged()) {
            pathModel.setChanged(false);

            List<PathModel> recursePath = getRootPathModel().recursePath(pathModel.getPath());

            getPathModelTreeModel().fireChangedEvent(recursePath);
        }
    }

    for (int i = 0; i < pathModel.getChildCount(); i++) {
        processStatus(status, pathModel.getChild(i));
    }
}

From source file:com.photon.phresco.framework.impl.SCMManagerImpl.java

License:Apache License

public List<RepoFileInfo> getGITCommitableFiles(File path) throws IOException, GitAPIException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(path).readEnvironment().findGitDir().build();
    Git git = new Git(repository);
    List<RepoFileInfo> fileslist = new ArrayList<RepoFileInfo>();
    InitCommand initCommand = Git.init();
    initCommand.setDirectory(path);//  w  w  w .j a  va  2  s.c  om
    git = initCommand.call();
    Status status = git.status().call();

    Set<String> added = status.getAdded();
    Set<String> changed = status.getChanged();
    Set<String> conflicting = status.getConflicting();
    Set<String> missing = status.getMissing();
    Set<String> modified = status.getModified();
    Set<String> removed = status.getRemoved();
    Set<String> untracked = status.getUntracked();

    if (!added.isEmpty()) {
        for (String add : added) {
            RepoFileInfo repoFileInfo = new RepoFileInfo();
            String filePath = path + BACK_SLASH + add;
            repoFileInfo.setCommitFilePath(filePath);
            repoFileInfo.setStatus("A");
            fileslist.add(repoFileInfo);
        }
    }

    if (!changed.isEmpty()) {
        for (String change : changed) {
            RepoFileInfo repoFileInfo = new RepoFileInfo();
            String filePath = path + BACK_SLASH + change;
            repoFileInfo.setCommitFilePath(filePath);
            repoFileInfo.setStatus("M");
            fileslist.add(repoFileInfo);
        }
    }

    if (!conflicting.isEmpty()) {
        for (String conflict : conflicting) {
            RepoFileInfo repoFileInfo = new RepoFileInfo();
            String filePath = path + BACK_SLASH + conflict;
            repoFileInfo.setCommitFilePath(filePath);
            repoFileInfo.setStatus("C");
            fileslist.add(repoFileInfo);
        }
    }

    if (!missing.isEmpty()) {
        for (String miss : missing) {
            RepoFileInfo repoFileInfo = new RepoFileInfo();
            String filePath = path + BACK_SLASH + miss;
            repoFileInfo.setCommitFilePath(filePath);
            repoFileInfo.setStatus("!");
            fileslist.add(repoFileInfo);
        }
    }

    if (!modified.isEmpty()) {
        for (String modify : modified) {
            RepoFileInfo repoFileInfo = new RepoFileInfo();
            String filePath = path + BACK_SLASH + modify;
            repoFileInfo.setCommitFilePath(filePath);
            repoFileInfo.setStatus("M");
            fileslist.add(repoFileInfo);
        }
    }

    if (!removed.isEmpty()) {
        for (String remove : removed) {
            RepoFileInfo repoFileInfo = new RepoFileInfo();
            String filePath = path + BACK_SLASH + remove;
            repoFileInfo.setCommitFilePath(filePath);
            repoFileInfo.setStatus("D");
            fileslist.add(repoFileInfo);
        }
    }

    if (!untracked.isEmpty()) {
        for (String untrack : untracked) {
            RepoFileInfo repoFileInfo = new RepoFileInfo();
            String filePath = path + BACK_SLASH + untrack;
            repoFileInfo.setCommitFilePath(filePath);
            repoFileInfo.setStatus("?");
            fileslist.add(repoFileInfo);
        }
    }
    git.getRepository().close();
    return fileslist;
}

From source file:com.rimerosolutions.ant.git.tasks.UpToDateTask.java

License:Apache License

@Override
protected void doExecute() throws BuildException {
    Repository repo = git.getRepository();

    FileTreeIterator workingTreeIterator = new FileTreeIterator(repo);

    try {/*from   ww  w.  j a  v a  2  s  .c o  m*/
        IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIterator);
        diff.diff();

        Status status = new Status(diff);

        if (!status.isClean()) {
            if (modificationExistProperty != null) {
                getProject().setProperty(modificationExistProperty, "true");
            }

            if (isFailOnError()) {
                StringBuilder msg = new StringBuilder();
                msg.append("The Git tree was modified.");
                msg.append("\n").append("Changed:").append(status.getChanged());
                msg.append("\n").append("Added:").append(status.getAdded());
                msg.append("\n").append("Modified:").append(status.getModified());
                msg.append("\n").append("Missing:").append(status.getMissing());
                msg.append("\n").append("Removed:").append(status.getRemoved());
                msg.append("\n").append("Untracked:").append(status.getUntracked());

                throw new GitBuildException(String.format(STATUS_NOT_CLEAN_TEMPLATE, msg.toString()));
            }
        } else {
            log(MESSAGE_UPTODATE_SUCCESS);
        }
    } catch (IOException ioe) {
        throw new GitBuildException(MESSAGE_UPTODATE_FAILED, ioe);
    }

}