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

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

Introduction

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

Prototype

public Set<String> getUncommittedChanges() 

Source Link

Document

Get uncommitted changes, i.e.

Usage

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 2s .  com

        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  ww  .j  a  v  a  2s .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 ww w  .  j av  a 2 s. c o  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.wadpam.gimple.GimpleMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    try {//from w  ww  .  ja va  2  s.  c o  m
        Repository repo = builder.setGitDir(new File(new File(gitDir), ".git")).readEnvironment().findGitDir()
                .build();
        final String branch = repo.getBranch();
        if (null != branch) {
            if (!currentVersion.endsWith(SUFFIX_SNAPSHOT)) {
                throw new MojoExecutionException("Maven project version not in SNAPSHOT: " + currentVersion);
            }

            getLog().info("gimple executing on " + gitDir);
            getLog().info("branch " + branch);

            if (null == releaseVersion) {
                releaseVersion = currentVersion.substring(0,
                        currentVersion.length() - SUFFIX_SNAPSHOT.length());
            }
            getLog().info(
                    "Transforming version from " + currentVersion + " to release version " + releaseVersion);

            Git git = new Git(repo);
            StatusCommand statusCommand = git.status();
            Status status = statusCommand.call();

            if (!status.isClean()) {
                throw new MojoExecutionException("Git project is not clean: " + status.getUncommittedChanges());
            }

            // versions:set releaseVersion
            transformPomVersions(git, releaseVersion);

            // tag release
            Ref tagRef = git.tag().setMessage(GIMPLE_MAVEN_PLUGIN + "tagging release " + releaseVersion)
                    .setName(releaseVersion).call();

            // next development version
            if (null == nextVersion) {
                nextVersion = getNextDevelopmentVersion(releaseVersion);
            }

            // versions:set nextVersion
            RevCommit nextRef = transformPomVersions(git, nextVersion);

            // push it all
            String developerConnection = mavenProject.getScm().getDeveloperConnection();
            if (developerConnection.startsWith(PREFIX_SCM_GIT)) {
                developerConnection = developerConnection.substring(PREFIX_SCM_GIT.length());
            }
            RefSpec spec = new RefSpec(branch + ":" + branch);
            git.push().setRemote(developerConnection).setRefSpecs(spec).add(tagRef).call();
        }
    } catch (IOException e) {
        throw new MojoExecutionException("executing", e);
    } catch (GitAPIException e) {
        throw new MojoExecutionException("status", e);
    }
}

From source file:com.wadpam.gimple.GimpleMojo.java

License:Open Source License

private RevCommit transformPomVersions(Git git, String newVersion)
        throws MojoExecutionException, GitAPIException {
    executeMojo(plugin("org.codehaus.mojo", "versions-maven-plugin", "2.1"), goal("set"),
            configuration(element(name("newVersion"), newVersion)),
            executionEnvironment(mavenProject, mavenSession, pluginManager));

    StatusCommand statusCommand = git.status();
    Status status = statusCommand.call();

    // git add/*from   w ww .j  a  va2s.  c o  m*/
    for (String uncommitted : status.getUncommittedChanges()) {
        getLog().info("  adding to git index: " + uncommitted);
        AddCommand add = git.add();
        add.addFilepattern(uncommitted);
        add.call();
    }

    // git commit
    CommitCommand commit = git.commit();
    commit.setMessage(GIMPLE_MAVEN_PLUGIN + "pom version " + newVersion);
    return commit.call();
}

From source file:edu.nju.cs.inform.jgit.porcelain.ListUncommittedChanges.java

License:Apache License

public static void main(String[] args) 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 w ww  .ja  v  a2  s.  c  o 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:gov.va.isaac.sync.git.SyncServiceGIT.java

License:Apache License

private String statusToString(Status status) {
    StringBuilder sb = new StringBuilder();
    sb.append("Is clean: " + status.isClean() + eol);
    sb.append("Changed: " + status.getChanged() + eol);
    sb.append("Added: " + status.getAdded() + eol);
    sb.append("Conflicting: " + status.getConflicting() + eol);
    sb.append("Ignored, unindexed: " + status.getIgnoredNotInIndex() + eol);
    sb.append("Missing: " + status.getMissing() + eol);
    sb.append("Modified: " + status.getModified() + eol);
    sb.append("Removed: " + status.getRemoved() + eol);
    sb.append("UncomittedChanges: " + status.getUncommittedChanges() + eol);
    sb.append("Untracked: " + status.getUntracked() + eol);
    sb.append("UntrackedFolders: " + status.getUntrackedFolders() + eol);
    return sb.toString();
}

From source file:org.apache.openaz.xacml.admin.model.GitStatusContainer.java

License:Apache License

public void refreshStatus(Status status) {
    ///*from ww  w .j  a  v  a  2 s  . c o m*/
    // Save this
    //
    this.conflictingStage = status.getConflictingStageState();
    if (logger.isDebugEnabled()) {
        logger.debug("conflictingStage: " + this.conflictingStage.size());
    }
    //
    // Re-create this
    //
    this.map = new TreeMap<String, GitEntry>();
    this.conflictCount = 0;
    //
    // Iterate through everything
    //
    for (String id : status.getAdded()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setAdded(true);
    }
    for (String id : status.getChanged()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setChanged(true);
    }
    for (String id : status.getConflicting()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setConflicting(true);
        //
        //
        //
        conflictCount++;
    }
    for (String id : status.getMissing()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setMissing(true);
    }
    for (String id : status.getModified()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setModified(true);
    }
    for (String id : status.getRemoved()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setRemoved(true);
    }
    for (String id : status.getUncommittedChanges()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setUncommitted(true);
    }
    for (String id : status.getUntracked()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setUntracked(true);
    }
    for (String id : status.getUntrackedFolders()) {
        if (id.endsWith(".gitignore") || id.endsWith(".DS_Store")) {
            continue;
        }
        GitEntry entry = this.map.get(id);
        if (entry == null) {
            entry = new GitEntry(id);
            this.map.put(id, entry);
        }
        entry.setUntrackedFolders(true);
    }
}

From source file:org.codehaus.mojo.versions.BumpMojo.java

License:Apache License

boolean gitModified() throws MojoExecutionException {
    StatusCommand statusCommand = git.status();
    try {//from w ww  . j ava2 s. com
        Status status = statusCommand.call();
        if (notEmpty(status.getModified()))
            return true;

        if (notEmpty(status.getAdded()))
            return true;

        if (notEmpty(status.getChanged()))
            return true;

        if (notEmpty(status.getConflicting()))
            return true;

        if (notEmpty(status.getRemoved()))
            return true;

        if (notEmpty(status.getUncommittedChanges()))
            return true;

        if (notEmpty(status.getUntracked()))
            return true;

        return false;
    } catch (NoWorkTreeException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (GitAPIException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:org.codehaus.mojo.versions.BumpMojo.java

License:Apache License

/**
 * Called when this mojo is executed.//from   w w w. j a v a  2  s  .  co  m
 * 
 * @throws org.apache.maven.plugin.MojoExecutionException
 *             when things go wrong.
 * @throws org.apache.maven.plugin.MojoFailureException
 *             when things go wrong.
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        init();

        if (StringUtils.isEmpty(bump)) {
            out("Current tags:");
            gitLastTags();
            out("");
            out("type version like 'mvn -q com.github.axet:versions-maven-plugin:bump -Dbump=server-1.0.0'");
            System.exit(1);
        }

        if (gitTagExists(bump)) {
            out("Current tags:");
            gitLastTags();
            out("");
            out("tag '" + bump + "' already exist");
            System.exit(1);
        }

        String tag = bump;
        String branch;
        String version;

        String[] bb = tag.split("-");

        branch = bb[0];
        version = bb[bb.length - 1];

        if (gitModified()) {
            StatusCommand statusCommand = git.status();
            try {
                out("Can't bump version on modified tree:");
                Status status = statusCommand.call();
                out(status.getModified());

                out((status.getAdded()));

                out((status.getChanged()));

                out((status.getConflicting()));

                out((status.getRemoved()));

                out((status.getUncommittedChanges()));

                out((status.getUntracked()));
            } catch (NoWorkTreeException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            } catch (GitAPIException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            System.exit(1);
        }

        // merge master. we allowd to change master if it is a readme file
        // git fetch
        gitFetch();
        // git checkout master
        gitCheckout(master);
        // git rebase
        gitRebase();
        // git checkout dev
        gitCheckout(dev);
        // git merge -m "Merge master" master
        gitMerge("Merge master", master);

        // bump version in dev tree, otherwise it will produce conflict merge on master on second
        // tag for pom.xml
        // git checkout dev
        gitCheckout(dev);
        final List<String> tags = new ArrayList<String>();
        SwitchReleaseMojo release = new SwitchReleaseMojo() {
            @Override
            synchronized String incrementModuleVersion(String groupId, String artifactId, String version) {
                String newVersion = super.incrementVersion(SwitchReleaseMojo.release(version));
                tags.add(artifactId + "-" + newVersion);
                return newVersion;
            }
        };
        release.projectBuilder = projectBuilder;
        release.localRepository = localRepository;
        release.setProject(project);
        release.setGenerateBackupPoms(false);
        release.setNewVersion(version);
        release.setLog(getLog());
        release.execute();
        // git commit -m "Bump version $BRANCH $VERSION" -a
        git.commit().setAll(true).setMessage("Bump version " + branch + " " + version).call();

        // create proper branch (server-1.0.0), helps produce nice git history
        // git checkout -b $TAG dev
        gitCheckoutB(tag);

        // prepare to merge
        // git checkout master
        gitCheckout(master);

        // do merge with a propertly named branch
        // git merge --no-ff -m "Merge branch '$TAG'" $TAG
        gitMergeNFF("Merge branch '" + tag + "'", tag);

        // do tag last master commit
        // git tag $TAG
        gitTag(tag);

        // tag all other changed (depended) modules
        for (String t : tags)
            gitTag(t);
        tags.clear();

        // drop perpared branch
        // git branch -d $TAG
        gitBranchD(tag);

        // switch back to the dev
        // git checkout dev
        gitCheckout(dev);

        // update version with -SNAPSHOT postfix
        // git commit -m "Bump version $BRANCH $VERSION" -a
        SwitchSnapshotMojo snapshot = new SwitchSnapshotMojo();
        snapshot.projectBuilder = projectBuilder;
        snapshot.localRepository = localRepository;
        snapshot.setProject(project);
        snapshot.setGenerateBackupPoms(false);
        snapshot.setLog(getLog());
        snapshot.execute();
        git.commit().setAll(true).setMessage("Bump version " + branch + " " + version).call();

        if (push) {
            out("");
            out("All done, push repo");
            out("");
            // git push origin master || exit 1
            // git push --tags || exit 1
            // git push origin dev || exit 1
            gitPush(master);
            gitPush(dev);
        }
    } catch (GitAPIException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}