org.netbeans.libs.git.GitRevisionInfo - java examples

Here are the examples of the java api org.netbeans.libs.git.GitRevisionInfo taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

142 Examples 7

19 View Complete Implementation : RevertTest.java
Copyright Apache License 2.0
Author : apache
public void testRevertNoCommit() throws Exception {
    File f = new File(workDir, "f");
    File[] files = new File[] { f };
    write(f, "init");
    add(f);
    commit(f);
    // modify and commit
    write(f, "change");
    add(f);
    GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    replacedertEquals("change", read(f));
    GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, false, NULL_PROGRESS_MONITOR);
    replacedertEquals("init", read(f));
    replacedertEquals(commit.getRevision(), getClient(workDir).getBranches(false, NULL_PROGRESS_MONITOR).get("master").getId());
    replacedertEquals(Arrays.asList(files), Arrays.asList(getClient(workDir).listModifiedIndexEntries(files, NULL_PROGRESS_MONITOR)));
    replacedertEquals(GitRevertResult.Status.REVERTED_IN_INDEX, result.getStatus());
}

19 View Complete Implementation : RevertTest.java
Copyright Apache License 2.0
Author : apache
public void testRevertCommitBeforeLast() throws Exception {
    File f = new File(workDir, "f");
    File[] files = new File[] { f };
    write(f, "a\nb\nc");
    add(f);
    commit(f);
    // modify and commit
    write(f, "z\nb\nc");
    add(f);
    GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    // second commit
    write(f, "z\nb\ny");
    add(f);
    commit(f);
    replacedertEquals("z\nb\ny", read(f));
    getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR);
    replacedertEquals("a\nb\ny", read(f));
}

19 View Complete Implementation : StashSaveCommand.java
Copyright Apache License 2.0
Author : apache
/**
 * @author Ondrej Vrabec
 */
public clreplaced StashSaveCommand extends GitCommand {

    private final boolean includeUntracked;

    private final String message;

    private GitRevisionInfo stash;

    public StashSaveCommand(Repository repository, GitClreplacedFactory accessor, String message, boolean includeUntracked, ProgressMonitor monitor) {
        super(repository, accessor, monitor);
        this.message = message;
        this.includeUntracked = includeUntracked;
    }

    @Override
    protected void run() throws GitException {
        Repository repository = getRepository();
        try {
            StashCreateCommand cmd = new Git(repository).stashCreate().setIncludeUntracked(includeUntracked).setWorkingDirectoryMessage(message);
            RevCommit commit = cmd.call();
            this.stash = getClreplacedFactory().createRevisionInfo(commit, repository);
        } catch (GitAPIException ex) {
            throw new GitException(ex);
        }
    }

    @Override
    protected String getCommandDescription() {
        // NOI18N
        StringBuilder sb = new StringBuilder("git stash save ");
        if (includeUntracked) {
            // NOI18N
            sb.append("--include-untracked ");
        }
        return sb.append(message).toString();
    }

    public GitRevisionInfo getStashedCommit() {
        return stash;
    }
}

19 View Complete Implementation : GitUtils.java
Copyright Apache License 2.0
Author : apache
public static void printInfo(StringBuilder sb, GitRevisionInfo info) {
    printInfo(sb, info, true);
}

19 View Complete Implementation : GitClassFactory.java
Copyright Apache License 2.0
Author : apache
public abstract GitRevertResult createRevertResult(GitRevertResult.Status status, GitRevisionInfo createRevisionInfo, List<File> conflicts, List<File> failures);

19 View Complete Implementation : FetchTest.java
Copyright Apache License 2.0
Author : apache
/**
 * @author ondra
 */
public clreplaced FetchTest extends AbstractGitTestCase {

    private Repository repository;

    private File workDir;

    private static final String BRANCH_NAME = "new_branch";

    private File otherWT;

    private File f;

    private GitRevisionInfo masterInfo;

    private GitBranch branch;

    public FetchTest(String testName) throws IOException {
        super(testName);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        workDir = getWorkingDirectory();
        repository = getRepository(getLocalGitRepository());
        otherWT = new File(workDir.getParentFile(), "repo2");
        GitClient client = getClient(otherWT);
        client.init(NULL_PROGRESS_MONITOR);
        f = new File(otherWT, "f");
        write(f, "init");
        client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
        masterInfo = client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
        branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
        RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
        cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
        cfg.update(repository.getConfig());
        repository.getConfig().save();
    }

    public void testFetchAllBranches() throws Exception {
        setupRemoteSpec("origin", "+refs/heads/*:refs/remotes/origin/*");
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        Map<String, GitTransportUpdate> updates = client.fetch("origin", NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, branches.size());
        replacedertTrue(branches.get("origin/master").isRemote());
        replacedertTrue(branches.get("origin/" + BRANCH_NAME).isRemote());
        replacedertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId());
        replacedertEquals(2, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
        replacedertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
    }

    public void testFetchAllBranchesUrl() throws Exception {
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        Map<String, GitTransportUpdate> updates = client.fetch(otherWT.toURI().toURL().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, branches.size());
        replacedertTrue(branches.get("origin/master").isRemote());
        replacedertTrue(branches.get("origin/" + BRANCH_NAME).isRemote());
        replacedertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId());
        replacedertEquals(2, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
        replacedertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
    }

    public void testFetchNamedBranches() throws Exception {
        setupRemoteSpec("origin", "+refs/heads/master:refs/remotes/origin/master");
        setupRemoteSpec("origin", "+refs/heads/" + BRANCH_NAME + ":refs/remotes/origin/" + BRANCH_NAME);
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        Map<String, GitTransportUpdate> updates = client.fetch("origin", NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, branches.size());
        replacedertTrue(branches.get("origin/master").isRemote());
        replacedertTrue(branches.get("origin/" + BRANCH_NAME).isRemote());
        replacedertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId());
        replacedertEquals(2, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
        replacedertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
    }

    public void testFetchMaster() throws Exception {
        setupRemoteSpec("origin", "+refs/heads/master:refs/remotes/origin/master");
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        Map<String, GitTransportUpdate> updates = client.fetch("origin", NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, branches.size());
        replacedertTrue(branches.get("origin/master").isRemote());
        replacedertEquals(masterInfo.getRevision(), branches.get("origin/master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
    }

    public void testFetchNothingToFetch() throws Exception {
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        try {
            client.fetch("origin", NULL_PROGRESS_MONITOR);
            fail("Should fail, no refspec given");
        } catch (GitException ex) {
            replacedertEquals("Nothing to fetch.", ex.getMessage());
        }
    }

    public void testFetchMasterExplicitely() throws Exception {
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        setupRemoteSpec("origin", "+refs/heads/*:refs/remotes/origin/*");
        Map<String, GitTransportUpdate> updates = client.fetch("origin", Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, branches.size());
        replacedertTrue(branches.get("origin/master").isRemote());
        replacedertEquals(masterInfo.getRevision(), branches.get("origin/master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
    }

    public void testFetchAllExplicitely() throws Exception {
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        Map<String, GitTransportUpdate> updates = client.fetch("origin", Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master", "+refs/heads/" + BRANCH_NAME + ":refs/remotes/origin/" + BRANCH_NAME }), NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, branches.size());
        replacedertTrue(branches.get("origin/master").isRemote());
        replacedertTrue(branches.get("origin/" + BRANCH_NAME).isRemote());
        replacedertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId());
        replacedertEquals(2, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
        replacedertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
    }

    // enable when the fixed in jgit - see the previous test
    // public void testFetchDeleteBranch () throws Exception {
    // GitClient client = getClient(workDir);
    // Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
    // replacedertEquals(0, branches.size());
    // setupRemoteSpec("origin", "+refs/heads/" + BRANCH_NAME + ":refs/remotes/origin/" + BRANCH_NAME);
    // Map<String, GitTransportUpdate> updates = client.fetch("origin", Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), NULL_PROGRESS_MONITOR);
    // branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
    // replacedertEquals(2, branches.size());
    // 
    // // delete the remote branch
    // File branchFile = new File(otherWT, ".git/refs/heads/" + BRANCH_NAME);
    // replacedertEquals(2, getClient(otherWT).getBranches(false, NULL_PROGRESS_MONITOR).size());
    // Thread.sleep(100);
    // branchFile.delete();
    // replacedertEquals(1, getClient(otherWT).getBranches(false, NULL_PROGRESS_MONITOR).size());
    // 
    // try {
    // client.fetch("origin", NULL_PROGRESS_MONITOR);
    // fail();
    // } catch (GitException ex) {
    // replacedertEquals("Remote does not have refs/heads/new_branch available for fetch.", ex.getMessage());
    // }
    // 
    // updates = client.fetch("origin", Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), NULL_PROGRESS_MONITOR);
    // branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
    // replacedertEquals(1, branches.size());
    // replacedertEquals(1, updates.size());
    // replacedertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, null, branch.getId(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FORCED);
    // }
    public void testFetchTags() throws Exception {
        setupRemoteSpec("origin", "+refs/heads/master:refs/remotes/origin/master");
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        client.fetch("origin", NULL_PROGRESS_MONITOR);
        Repository repo = new RepositoryBuilder().setGitDir(new File(otherWT, ".git")).build();
        TagCommand cmd = new Git(repo).tag();
        cmd.setMessage("new tag message");
        cmd.setName("new.tag");
        cmd.setObjectId(new RevWalk(repo).parseCommit(repo.resolve(masterInfo.getRevision())));
        Ref ref = cmd.call();
        RevTag tag = new RevWalk(repo).parseTag(ref.getObjectId());
        Map<String, GitTransportUpdate> updates = client.fetch("origin", NULL_PROGRESS_MONITOR);
        Map<String, Ref> tags = repository.getTags();
        replacedertEquals(tag.getId(), tags.get(tag.getTagName()).getTarget().getObjectId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get(tag.getTagName()), tag.getTagName(), tag.getTagName(), tag.getId().getName(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.TAG, GitRefUpdateResult.NEW);
    }

    public void testFetchProgress() throws Exception {
        setupRemoteSpec("origin", "+refs/heads/*:refs/remotes/origin/*");
        GitClient client = getClient(workDir);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        final StringBuilder sb = new StringBuilder();
        ProgressMonitor pm = new ProgressMonitor.DefaultProgressMonitor() {

            @Override
            public void beginTask(String taskName, int totalWorkUnits) {
                sb.append("START: ").append(taskName);
                if (totalWorkUnits > 0) {
                    sb.append(" - ").append(totalWorkUnits).append("\n");
                }
            }

            @Override
            public void updateTaskState(int completed) {
                sb.append("UPDATE: ").append(completed).append("\n");
            }

            @Override
            public void endTask() {
                sb.append("ENDED\n");
            }
        };
        client.fetch("origin", pm);
        String messages = sb.toString();
        replacedertTrue(messages, messages.contains("START: remote: Finding sources - "));
        replacedertTrue(messages, messages.contains("START: remote: Getting sizes - "));
        replacedertTrue(messages, messages.contains("START: remote: Compressing objects - "));
        replacedertTrue(messages, messages.contains("START: Receiving objects - "));
    }

    private void setupRemoteSpec(String remote, String fetchSpec) throws URISyntaxException, IOException {
        RemoteConfig cfg = new RemoteConfig(repository.getConfig(), remote);
        cfg.addFetchRefSpec(new RefSpec(fetchSpec));
        cfg.update(repository.getConfig());
        repository.getConfig().save();
    }

    private void replacedertUpdate(GitTransportUpdate update, String localName, String remoteName, String newObjectId, String oldObjectId, String remoteUri, Type type, GitRefUpdateResult result) {
        replacedertEquals(localName, update.getLocalName());
        replacedertEquals(remoteName, update.getRemoteName());
        replacedertEquals(newObjectId, update.getNewObjectId());
        replacedertEquals(oldObjectId, update.getOldObjectId());
        replacedertEquals(remoteUri, update.getRemoteUri());
        replacedertEquals(type, update.getType());
        replacedertEquals(result, update.getResult());
    }
}

19 View Complete Implementation : RevertTest.java
Copyright Apache License 2.0
Author : apache
public void testRevertLastCommitOneFile() throws Exception {
    File f = new File(workDir, "f");
    File[] files = new File[] { f };
    write(f, "init");
    add(f);
    commit(f);
    // modify and commit
    write(f, "change");
    add(f);
    GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    replacedertEquals("change", read(f));
    getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR);
    replacedertEquals("init", read(f));
    replacedertEquals("Revert \"modification\"\n\nThis reverts commit " + commit.getRevision() + ".", getClient(workDir).log("master", NULL_PROGRESS_MONITOR).getFullMessage());
}

19 View Complete Implementation : PullTest.java
Copyright Apache License 2.0
Author : apache
/**
 * @author ondra
 */
public clreplaced PullTest extends AbstractGitTestCase {

    private Repository repository;

    private File workDir;

    private static final String BRANCH_NAME = "new_branch";

    private File otherWT;

    private File f, f2;

    private GitRevisionInfo masterInfo;

    private GitBranch branch;

    public PullTest(String testName) throws IOException {
        super(testName);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        workDir = getWorkingDirectory();
        repository = getRepository(getLocalGitRepository());
        otherWT = new File(workDir.getParentFile(), "repo2");
        GitClient client = getClient(otherWT);
        client.init(NULL_PROGRESS_MONITOR);
        f = new File(otherWT, "f");
        write(f, "init");
        f2 = new File(otherWT, "f2");
        write(f2, "init");
        client.add(new File[] { f, f2 }, NULL_PROGRESS_MONITOR);
        masterInfo = client.commit(new File[] { f, f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR);
        branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
        RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
        cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
        cfg.update(repository.getConfig());
        repository.getConfig().save();
    }

    public void testPullNotExistingBranch() throws Exception {
        GitClient client = getClient(workDir);
        try {
            GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/idontexistbranch", NULL_PROGRESS_MONITOR);
            fail("Must fail");
        } catch (GitException.MissingObjectException ex) {
        // OK
        }
    }

    public void testPullNoLocalHead() throws Exception {
        GitClient client = getClient(workDir);
        File f = new File(workDir, "local");
        write(f, "aaa");
        add(f);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(0, branches.size());
        replacedertTrue(f.exists());
        GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(3, branches.size());
        replacedertTrue(branches.get("origin/master").isRemote());
        replacedertTrue(branches.get("origin/" + BRANCH_NAME).isRemote());
        replacedertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId());
        Map<String, GitTransportUpdate> updates = result.getFetchResult();
        replacedertEquals(2, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
        replacedertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
        replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeResult().getMergeStatus());
        // we should be on master branch
        replacedertTrue(branches.get("master").isActive());
        // the old file should be deleted
        replacedertFalse(f.exists());
        // and replaced with a new file
        replacedertTrue(new File(workDir, this.f.getName()).exists());
    }

    public void testPullIntoDetached() throws Exception {
        GitClient client = getClient(workDir);
        client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        File f = new File(workDir, this.f.getName());
        write(f, "blabla");
        add(f);
        commit(f);
        client.checkoutRevision("origin/master", true, NULL_PROGRESS_MONITOR);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertTrue(branches.get(GitBranch.NO_BRANCH).isActive());
        String commitId = makeRemoteChange("master");
        GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(4, branches.size());
        replacedertTrue(branches.get("origin/master").isRemote());
        replacedertEquals(commitId, branches.get("origin/master").getId());
        replacedertTrue(branches.get(GitBranch.NO_BRANCH).isActive());
        replacedertEquals(commitId, branches.get(GitBranch.NO_BRANCH).getId());
        Map<String, GitTransportUpdate> updates = result.getFetchResult();
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD);
        replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeResult().getMergeStatus());
        replacedertEquals(commitId, result.getMergeResult().getNewHead());
    }

    public void testPullChangesInSameBranch() throws Exception {
        GitClient client = getClient(workDir);
        client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        String commitId = makeRemoteChange("master");
        GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertTrue(branches.get("master").isActive());
        replacedertEquals(commitId, branches.get("origin/master").getId());
        replacedertEquals(commitId, branches.get("master").getId());
        Map<String, GitTransportUpdate> updates = result.getFetchResult();
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD);
        replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeResult().getMergeStatus());
        replacedertEquals(commitId, result.getMergeResult().getNewHead());
    }

    public void testPullChangesInSameBranchPlusMerge() throws Exception {
        GitClient client = getClient(workDir);
        client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        File f = new File(workDir, this.f.getName());
        File f2 = new File(workDir, "f2");
        write(f2, "hi, i am new");
        add(f2);
        String localCommitId = client.commit(new File[] { f2 }, "local change", null, null, NULL_PROGRESS_MONITOR).getRevision();
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        String commitId = makeRemoteChange("master");
        GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertTrue(branches.get("master").isActive());
        replacedertEquals(commitId, branches.get("origin/master").getId());
        replacedertFalse(commitId.equals(branches.get("master").getId()));
        Map<String, GitTransportUpdate> updates = result.getFetchResult();
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD);
        replacedertEquals(MergeStatus.MERGED, result.getMergeResult().getMergeStatus());
        replacedertEquals(new HashSet<String>(Arrays.asList(commitId, localCommitId)), new HashSet<String>(Arrays.asList(result.getMergeResult().getMergedCommits())));
        replacedertTrue(f.exists());
        replacedertTrue(f2.exists());
    }

    public void testPullChangesMergeConflict() throws Exception {
        GitClient client = getClient(workDir);
        client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        File f = new File(workDir, this.f.getName());
        write(f, "hi, i am new");
        add(f);
        client.commit(new File[] { f }, "local change", null, null, NULL_PROGRESS_MONITOR).getRevision();
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        String commitId = makeRemoteChange("master");
        GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertTrue(branches.get("master").isActive());
        replacedertEquals(commitId, branches.get("origin/master").getId());
        replacedertFalse(commitId.equals(branches.get("master").getId()));
        Map<String, GitTransportUpdate> updates = result.getFetchResult();
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD);
        replacedertEquals(MergeStatus.CONFLICTING, result.getMergeResult().getMergeStatus());
        replacedertEquals(new HashSet<File>(Arrays.asList(f)), new HashSet<File>(result.getMergeResult().getConflicts()));
        // this should be fixed in JGit
        replacedertEquals("<<<<<<< HEAD\nhi, i am new\n=======\nremote change\n>>>>>>> branch 'master' of " + new URIish(otherWT.toURI().toString()).toString(), read(f));
    }

    public void testPullChangesInOtherBranchPlusMerge() throws Exception {
        GitClient client = getClient(workDir);
        client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        File f = new File(workDir, this.f.getName());
        File f2 = new File(workDir, "f2");
        write(f2, "hi, i am new");
        add(f2);
        String localCommitId = client.commit(new File[] { f2 }, "local change", null, null, NULL_PROGRESS_MONITOR).getRevision();
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        String commitId = makeRemoteChange(BRANCH_NAME);
        GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/" + BRANCH_NAME, NULL_PROGRESS_MONITOR);
        branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertTrue(branches.get("master").isActive());
        replacedertEquals(commitId, branches.get("origin/" + BRANCH_NAME).getId());
        replacedertFalse(commitId.equals(branches.get("master").getId()));
        replacedertFalse(localCommitId.equals(branches.get("master").getId()));
        Map<String, GitTransportUpdate> updates = result.getFetchResult();
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, commitId, branch.getId(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD);
        replacedertEquals(MergeStatus.MERGED, result.getMergeResult().getMergeStatus());
        replacedertEquals(new HashSet<String>(Arrays.asList(commitId, localCommitId)), new HashSet<String>(Arrays.asList(result.getMergeResult().getMergedCommits())));
        replacedertTrue(f.exists());
        replacedertTrue(f2.exists());
    }

    public void testPullFailOnLocalChanges() throws Exception {
        GitClient client = getClient(workDir);
        client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        File f = new File(workDir, this.f.getName());
        write(f, "local change");
        add(f);
        Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
        makeRemoteChange("master");
        try {
            GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
            fail("Should fail");
        } catch (GitException.CheckoutConflictException ex) {
        // OK
        }
        client.reset("master", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR);
        File f2 = new File(workDir, "f2");
        write(f2, "hi, i am new");
        add(f2);
        GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeResult().getMergeStatus());
        replacedertStatus(client.getStatus(new File[] { f2 }, NULL_PROGRESS_MONITOR), workDir, f2, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false);
    }

    public void testPullCommitMessages() throws Exception {
        GitClient client = getClient(workDir);
        client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        File f = new File(workDir, "localFile");
        makeLocalChange(f, "1");
        makeRemoteChange("master");
        GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        replacedertEquals(GitMergeResult.MergeStatus.MERGED, result.getMergeResult().getMergeStatus());
        replacedertEquals("Merge branch 'master' of " + new URIish(otherWT.toURI().toString()).toString(), client.log(result.getMergeResult().getNewHead(), NULL_PROGRESS_MONITOR).getFullMessage());
        makeLocalChange(f, "2");
        makeRemoteChange("master", "2");
        result = client.pull("origin", Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
        replacedertEquals(GitMergeResult.MergeStatus.MERGED, result.getMergeResult().getMergeStatus());
        replacedertEquals("Merge branch 'master' of " + new URIish(otherWT.toURI().toString()).toString(), client.log(result.getMergeResult().getNewHead(), NULL_PROGRESS_MONITOR).getFullMessage());
    }

    private void setupRemoteSpec(String remote, String fetchSpec) throws URISyntaxException, IOException {
        RemoteConfig cfg = new RemoteConfig(repository.getConfig(), remote);
        cfg.addFetchRefSpec(new RefSpec(fetchSpec));
        cfg.update(repository.getConfig());
        repository.getConfig().save();
    }

    private void replacedertUpdate(GitTransportUpdate update, String localName, String remoteName, String newObjectId, String oldObjectId, String remoteUri, Type type, GitRefUpdateResult result) {
        replacedertEquals(localName, update.getLocalName());
        replacedertEquals(remoteName, update.getRemoteName());
        replacedertEquals(newObjectId, update.getNewObjectId());
        replacedertEquals(oldObjectId, update.getOldObjectId());
        replacedertEquals(remoteUri, update.getRemoteUri());
        replacedertEquals(type, update.getType());
        replacedertEquals(result, update.getResult());
    }

    private String makeRemoteChange(String branch) throws Exception {
        return makeRemoteChange(branch, "remote change");
    }

    private String makeRemoteChange(String branch, String content) throws Exception {
        GitClient client = getClient(otherWT);
        client.checkoutRevision(branch, true, NULL_PROGRESS_MONITOR);
        write(f, content);
        File[] roots = new File[] { f };
        client.add(roots, NULL_PROGRESS_MONITOR);
        return client.commit(roots, "remote change", null, null, NULL_PROGRESS_MONITOR).getRevision();
    }

    private String makeLocalChange(File f, String content) throws Exception {
        GitClient client = getClient(workDir);
        write(f, content);
        File[] roots = new File[] { f };
        client.add(roots, NULL_PROGRESS_MONITOR);
        return client.commit(roots, "local change: " + content, null, null, NULL_PROGRESS_MONITOR).getRevision();
    }
}

19 View Complete Implementation : RevertTest.java
Copyright Apache License 2.0
Author : apache
public void testRevertMessage() throws Exception {
    File f = new File(workDir, "f");
    File[] files = new File[] { f };
    write(f, "init");
    add(f);
    commit(f);
    // modify and commit
    write(f, "change");
    add(f);
    GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    replacedertEquals("change", read(f));
    getClient(workDir).revert(commit.getRevision(), "blablabla message", true, NULL_PROGRESS_MONITOR);
    replacedertEquals("init", read(f));
    replacedertEquals("blablabla message", getClient(workDir).log("master", NULL_PROGRESS_MONITOR).getFullMessage());
}

19 View Complete Implementation : StashListCommand.java
Copyright Apache License 2.0
Author : apache
private void addRevision(GitRevisionInfo info) {
    revisions.add(info);
    listener.notifyRevisionInfo(info);
}

19 View Complete Implementation : GetCommonAncestorCommand.java
Copyright Apache License 2.0
Author : apache
/**
 * @author ondra
 */
public clreplaced GetCommonAncestorCommand extends GitCommand {

    private final String[] revisions;

    private GitRevisionInfo revision;

    public GetCommonAncestorCommand(Repository repository, GitClreplacedFactory gitFactory, String[] revisions, ProgressMonitor monitor) {
        super(repository, gitFactory, monitor);
        this.revisions = revisions;
    }

    @Override
    protected void run() throws GitException {
        Repository repository = getRepository();
        try {
            if (revisions.length == 0) {
                revision = null;
            } else {
                try (RevWalk walk = new RevWalk(repository)) {
                    List<RevCommit> commits = new ArrayList<>(revisions.length);
                    for (String rev : revisions) {
                        commits.add(Utils.findCommit(repository, rev, walk));
                    }
                    revision = getSingleBaseCommit(walk, commits);
                }
            }
        } catch (MissingObjectException ex) {
            throw new GitException.MissingObjectException(ex.getObjectId().toString(), GitObjectType.COMMIT);
        } catch (IOException ex) {
            throw new GitException(ex);
        }
    }

    @Override
    protected String getCommandDescription() {
        // NOI18N
        StringBuilder sb = new StringBuilder("git merge-base ");
        for (String s : revisions) {
            sb.append(s).append(' ');
        }
        return sb.toString();
    }

    public GitRevisionInfo getRevision() {
        return revision;
    }

    private GitRevisionInfo getSingleBaseCommit(RevWalk walk, List<RevCommit> commits) throws IOException {
        while (commits.size() > 1) {
            walk.reset();
            for (RevCommit c : commits) {
                walk.markStart(walk.parseCommit(c));
            }
            walk.setRevFilter(RevFilter.MERGE_BASE);
            commits.clear();
            for (RevCommit commit = walk.next(); commit != null; commit = walk.next()) {
                commits.add(commit);
            }
        }
        if (commits.isEmpty()) {
            return null;
        } else {
            return getClreplacedFactory().createRevisionInfo(commits.get(0), getRepository());
        }
    }
}

19 View Complete Implementation : GitClassFactory.java
Copyright Apache License 2.0
Author : apache
public abstract GitCherryPickResult createCherryPickResult(GitCherryPickResult.CherryPickStatus status, List<File> conflicts, List<File> failures, GitRevisionInfo head, List<GitRevisionInfo> cherryPickedCommits);

19 View Complete Implementation : AnnotateLine.java
Copyright Apache License 2.0
Author : apache
/**
 * One line of annotation, this is copied from CVS so that other support clreplacedes stay the same.
 *
 * @author Maros Sandor
 */
public clreplaced AnnotateLine {

    private final GitUser author;

    private final String authorShort;

    private final GitUser committer;

    private final GitRevisionInfo revision;

    private final File file;

    private final String content;

    private final int lineNum;

    private final int sourceLine;

    /**
     * The default is true to enable rollback even if we were unable to determine the correct value.
     */
    private boolean canBeRolledBack = true;

    // NOI18N
    private static final String fakeItem = NbBundle.getMessage(AnnotateLine.clreplaced, "MSG_AnnotateAction.lineDetail.unknown");

    AnnotateLine(GitLineDetails lineDetails, int lineNumber) {
        if (lineDetails == null) {
            revision = null;
            author = null;
            authorShort = fakeItem;
            committer = null;
            content = fakeItem;
            file = null;
            sourceLine = -1;
        } else {
            revision = lineDetails.getRevisionInfo();
            author = lineDetails.getAuthor() == null ? lineDetails.getCommitter() : lineDetails.getAuthor();
            authorShort = getAuthorShort(author);
            committer = lineDetails.getCommitter();
            // NOI18N
            String cont = lineDetails.getContent().replace("\r", "").replace("\n", "");
            if (cont.length() != lineDetails.getContent().length()) {
                // NOI18N
                AnnotationBar.LOG.log(Level.FINE, "AnnotateLine: line content contains '\\r' or '\\n': {0}:{1}", new Object[] { lineDetails.getSourceFile(), lineNumber });
            }
            content = cont;
            file = lineDetails.getSourceFile();
            sourceLine = lineDetails.getSourceLine();
        }
        lineNum = lineNumber;
    }

    /**
     * Returns the author of this line.
     */
    public GitUser getAuthor() {
        return author;
    }

    /**
     * Returns the file of this line.
     */
    public File getFile() {
        return file;
    }

    /**
     * Returns the revision of this line.
     */
    public GitRevisionInfo getRevisionInfo() {
        return revision;
    }

    /**
     * Return the line's content.
     */
    public String getContent() {
        return content;
    }

    /**
     * Returns the line's number. It's 1 based.
     */
    public int getLineNum() {
        return lineNum;
    }

    /**
     * Returns the line's number in the previous source file. It's 0 based.
     */
    public int getSourceLineNum() {
        return sourceLine;
    }

    /**
     * @return false if the file was added to repository (created) in this revision, true otherwise
     */
    public boolean canBeRolledBack() {
        return this.canBeRolledBack;
    }

    public void setCanBeRolledBack(boolean canBeRolledBack) {
        this.canBeRolledBack = canBeRolledBack;
    }

    public String getAuthorShort() {
        return authorShort;
    }

    private String getAuthorShort(GitUser author) {
        if (author == null) {
            return fakeItem;
        } else {
            String shortened = null;
            String email = author.getEmailAddress();
            int pos;
            if (email != null && (pos = email.indexOf("@")) > -1) {
                shortened = email.substring(0, pos);
            }
            if (shortened == null) {
                shortened = author.toString();
                if (shortened.length() > 10) {
                    pos = shortened.indexOf(' ', 7);
                    if (pos > 0 && pos <= 10) {
                        shortened = shortened.substring(0, pos);
                    }
                }
            }
            if (shortened.length() > 10) {
                // NOI18N
                shortened = shortened.substring(0, 7) + "...";
            }
            return shortened;
        }
    }
}

19 View Complete Implementation : GetPreviousCommitCommand.java
Copyright Apache License 2.0
Author : apache
/**
 * @author ondra
 */
public clreplaced GetPreviousCommitCommand extends GitCommand {

    private final String revision;

    private GitRevisionInfo previousRevision;

    private final File file;

    private final ProgressMonitor monitor;

    public GetPreviousCommitCommand(Repository repository, GitClreplacedFactory gitFactory, File file, String revision, ProgressMonitor monitor) {
        super(repository, gitFactory, monitor);
        this.file = file;
        this.revision = revision;
        this.monitor = monitor;
    }

    @Override
    protected void run() throws GitException {
        Repository repository = getRepository();
        try {
            RevCommit rev = Utils.findCommit(repository, revision);
            if (rev.getParentCount() == 1) {
                try (RevWalk walk = new RevWalk(repository)) {
                    walk.markStart(walk.parseCommit(rev.getParent(0)));
                    String path = Utils.getRelativePath(repository.getWorkTree(), file);
                    if (path != null && !path.isEmpty()) {
                        walk.setTreeFilter(FollowFilter.create(path, repository.getConfig().get(DiffConfig.KEY)));
                    }
                    walk.setRevFilter(AndRevFilter.create(new RevFilter[] { new CancelRevFilter(monitor), MaxCountRevFilter.create(1) }));
                    Iterator<RevCommit> it = walk.iterator();
                    if (it.hasNext()) {
                        previousRevision = getClreplacedFactory().createRevisionInfo(new RevWalk(repository).parseCommit(it.next()), repository);
                    }
                }
            }
        } catch (MissingObjectException ex) {
            throw new GitException.MissingObjectException(ex.getObjectId().toString(), GitObjectType.COMMIT);
        } catch (IOException ex) {
            throw new GitException(ex);
        }
    }

    @Override
    protected String getCommandDescription() {
        // NOI18N
        StringBuilder sb = new StringBuilder("git log ");
        sb.append(revision).append(' ');
        sb.append("-- ").append(file.getPath());
        return sb.toString();
    }

    public GitRevisionInfo getRevision() {
        return previousRevision;
    }
}

19 View Complete Implementation : CommitCommand.java
Copyright Apache License 2.0
Author : apache
/**
 * @author ondra
 */
public clreplaced CommitCommand extends GitCommand {

    private final File[] roots;

    private final ProgressMonitor monitor;

    private final String message;

    private final GitUser author;

    private final GitUser commiter;

    public GitRevisionInfo revision;

    private final boolean amend;

    public CommitCommand(Repository repository, GitClreplacedFactory gitFactory, File[] roots, String message, GitUser author, GitUser commiter, boolean amend, ProgressMonitor monitor) {
        super(repository, gitFactory, monitor);
        this.roots = roots;
        this.message = message;
        this.monitor = monitor;
        this.author = author;
        this.commiter = commiter;
        this.amend = amend;
    }

    @Override
    protected boolean prepareCommand() throws GitException {
        boolean retval = super.prepareCommand();
        if (retval) {
            RepositoryState state = getRepository().getRepositoryState();
            if (amend && !state.canAmend()) {
                // NOI18N
                String errorMessage = Utils.getBundle(CommitCommand.clreplaced).getString("MSG_Error_Commit_CannotAmend");
                monitor.preparationsFailed(errorMessage);
                throw new GitException(errorMessage);
            }
            if (RepositoryState.MERGING.equals(state) || RepositoryState.CHERRY_PICKING.equals(state)) {
                // NOI18N
                String errorMessage = Utils.getBundle(CommitCommand.clreplaced).getString("MSG_Error_Commit_ConflictsInIndex");
                monitor.preparationsFailed(errorMessage);
                throw new GitException(errorMessage);
            } else if ((RepositoryState.MERGING_RESOLVED.equals(state) || RepositoryState.CHERRY_PICKING_RESOLVED.equals(state)) && roots.length > 0) {
                boolean fullWorkingTree = false;
                File repositoryRoot = getRepository().getWorkTree();
                for (File root : roots) {
                    if (root.equals(repositoryRoot)) {
                        fullWorkingTree = true;
                        break;
                    }
                }
                if (!fullWorkingTree) {
                    // NOI18N
                    String errorMessage = Utils.getBundle(CommitCommand.clreplaced).getString("MSG_Error_Commit_PartialCommitAfterMerge");
                    monitor.preparationsFailed(errorMessage);
                    throw new GitException(errorMessage);
                }
            } else if (!state.canCommit()) {
                // NOI18N
                String errorMessage = Utils.getBundle(CommitCommand.clreplaced).getString("MSG_Error_Commit_NotAllowedInCurrentState");
                monitor.preparationsFailed(errorMessage);
                throw new GitException(errorMessage);
            }
        }
        return retval;
    }

    @Override
    protected void run() throws GitException {
        Repository repository = getRepository();
        try {
            DirCache backup = repository.readDirCache();
            try {
                prepareIndex();
                org.eclipse.jgit.api.CommitCommand commit = new Git(repository).commit();
                if (author != null) {
                    commit.setAuthor(author.getName(), author.getEmailAddress());
                } else {
                    commit.setAuthor(new PersonIdent(repository));
                }
                if (commiter != null) {
                    commit.setCommitter(commiter.getName(), commiter.getEmailAddress());
                }
                setAuthorshipIfNeeded(repository, commit);
                commit.setMessage(message);
                commit.setAmend(amend);
                RevCommit rev = commit.call();
                revision = getClreplacedFactory().createRevisionInfo(rev, repository);
            } finally {
                if (backup.lock()) {
                    try {
                        backup.write();
                        backup.commit();
                    } catch (IOException ex) {
                        Logger.getLogger(CommitCommand.clreplaced.getName()).log(Level.INFO, null, ex);
                    } finally {
                        backup.unlock();
                    }
                }
            }
        } catch (GitAPIException | JGitInternalException | NoWorkTreeException | IOException ex) {
            throw new GitException(ex);
        }
    }

    private void setAuthorshipIfNeeded(Repository repository, org.eclipse.jgit.api.CommitCommand cmd) throws GitException, NoWorkTreeException, IOException {
        if (amend) {
            RevCommit lastCommit = Utils.findCommit(repository, "HEAD^{commit}");
            transferTimestamp(cmd, lastCommit);
        }
        if (repository.getRepositoryState() == RepositoryState.CHERRY_PICKING_RESOLVED) {
            RevCommit lastCommit = Utils.findCommit(repository, repository.readCherryPickHead(), null);
            transferTimestamp(cmd, lastCommit);
        }
    }

    private void transferTimestamp(org.eclipse.jgit.api.CommitCommand commit, RevCommit lastCommit) {
        PersonIdent lastAuthor = lastCommit.getAuthorIdent();
        if (lastAuthor != null) {
            PersonIdent author = commit.getAuthor();
            commit.setAuthor(lastAuthor.getTimeZone() == null ? new PersonIdent(author, lastAuthor.getWhen()) : new PersonIdent(author, lastAuthor.getWhen(), lastAuthor.getTimeZone()));
        }
    }

    private void prepareIndex() throws NoWorkTreeException, CorruptObjectException, IOException {
        Repository repository = getRepository();
        DirCache cache = repository.lockDirCache();
        try {
            TreeWalk treeWalk = new TreeWalk(repository);
            TreeFilter filter = Utils.getExcludeExactPathsFilter(repository.getWorkTree(), roots);
            if (filter != null) {
                DirCacheEditor edit = cache.editor();
                treeWalk.setFilter(filter);
                treeWalk.setRecursive(true);
                treeWalk.reset();
                ObjectId headId = repository.resolve(Constants.HEAD);
                if (headId != null) {
                    treeWalk.addTree(new RevWalk(repository).parseTree(headId));
                } else {
                    treeWalk.addTree(new EmptyTreeIterator());
                }
                // Index
                treeWalk.addTree(new DirCacheIterator(cache));
                final int T_HEAD = 0;
                final int T_INDEX = 1;
                List<DirCacheEntry> toAdd = new LinkedList<DirCacheEntry>();
                while (treeWalk.next() && !monitor.isCanceled()) {
                    String path = treeWalk.getPathString();
                    int mHead = treeWalk.getRawMode(T_HEAD);
                    int mIndex = treeWalk.getRawMode(T_INDEX);
                    if (mHead == FileMode.MISSING.getBits() && mIndex != FileMode.MISSING.getBits()) {
                        edit.add(new DirCacheEditor.DeletePath(path));
                    } else if (mIndex == FileMode.MISSING.getBits() && mHead != FileMode.MISSING.getBits() || mHead != mIndex || (mIndex != FileMode.TREE.getBits() && !treeWalk.idEqual(T_HEAD, T_INDEX))) {
                        edit.add(new DirCacheEditor.DeletePath(path));
                        DirCacheEntry e = new DirCacheEntry(path);
                        e.setFileMode(treeWalk.getFileMode(T_HEAD));
                        e.setObjectId(treeWalk.getObjectId(T_HEAD));
                        e.smudgeRacilyClean();
                        toAdd.add(e);
                    }
                }
                if (!monitor.isCanceled()) {
                    edit.finish();
                    DirCacheBuilder builder = cache.builder();
                    if (cache.getEntryCount() > 0) {
                        builder.keep(0, cache.getEntryCount());
                    }
                    for (DirCacheEntry e : toAdd) {
                        builder.add(e);
                    }
                    builder.finish();
                    builder.commit();
                }
            }
        } finally {
            cache.unlock();
        }
    }

    @Override
    protected String getCommandDescription() {
        // NOI18N
        StringBuilder sb = new StringBuilder("git commit -m ").append(message);
        if (amend) {
            // NOI18N
            sb.append(" --amend");
        }
        for (File root : roots) {
            // NOI18N
            sb.append(" ").append(root);
        }
        return sb.toString();
    }
}

19 View Complete Implementation : RebaseCommand.java
Copyright Apache License 2.0
Author : apache
private List<File> getConflicts(RevCommit currentCommit) {
    List<File> conflicts;
    try {
        Repository repository = getRepository();
        GitRevisionInfo info = getClreplacedFactory().createRevisionInfo(currentCommit, repository);
        Map<File, GitRevisionInfo.GitFileInfo> modifiedFiles = info.getModifiedFiles();
        ConflictCommand cmd = new ConflictCommand(repository, getClreplacedFactory(), modifiedFiles.keySet().toArray(new File[modifiedFiles.keySet().size()]), new DelegatingGitProgressMonitor(monitor), new StatusListener() {

            @Override
            public void notifyStatus(GitStatus status) {
            }
        });
        cmd.execute();
        Map<File, GitStatus> statuses = cmd.getStatuses();
        conflicts = new ArrayList<>(statuses.size());
        for (Map.Entry<File, GitStatus> e : statuses.entrySet()) {
            if (e.getValue().isConflict()) {
                conflicts.add(e.getKey());
            }
        }
    } catch (GitException ex) {
        Logger.getLogger(RebaseCommand.clreplaced.getName()).log(Level.INFO, null, ex);
        conflicts = Collections.<File>emptyList();
    }
    return conflicts;
}

19 View Complete Implementation : PushTest.java
Copyright Apache License 2.0
Author : apache
/**
 * @author ondra
 */
public clreplaced PushTest extends AbstractGitTestCase {

    private Repository repository;

    private File workDir;

    private File otherWT;

    private File f;

    private GitRevisionInfo masterInfo;

    private GitBranch branch;

    public PushTest(String testName) throws IOException {
        super(testName);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        workDir = getWorkingDirectory();
        repository = getRepository(getLocalGitRepository());
    }

    public void testPushNewBranch() throws Exception {
        String remoteUri = getRemoteRepository().getWorkTree().toURI().toString();
        replacedertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size());
        File f = new File(workDir, "f");
        add(f);
        String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        Map<String, GitTransportUpdate> updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        Map<String, GitBranch> remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(id, remoteBranches.get("master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        // adding another branch
        write(f, "huhu");
        add(f);
        String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/anotherBranch" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, remoteBranches.size());
        replacedertEquals(id, remoteBranches.get("master").getId());
        replacedertEquals(newid, remoteBranches.get("anotherBranch").getId());
        replacedertUpdate(updates.get("anotherBranch"), "master", "anotherBranch", newid, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
    }

    public void testPushDeleteBranch() throws Exception {
        String remoteUri = getRemoteRepository().getWorkTree().toURI().toString();
        replacedertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size());
        File f = new File(workDir, "f");
        add(f);
        String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        Map<String, GitTransportUpdate> updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master", "refs/heads/master:refs/heads/newbranch" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        Map<String, GitBranch> remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, remoteBranches.size());
        replacedertEquals(id, remoteBranches.get("master").getId());
        replacedertEquals(2, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        replacedertUpdate(updates.get("newbranch"), "master", "newbranch", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        // deleting branch
        updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { ":refs/heads/newbranch" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(id, remoteBranches.get("master").getId());
        replacedertUpdate(updates.get("newbranch"), null, "newbranch", null, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
    }

    public void testPushChange() throws Exception {
        String remoteUri = getRemoteRepository().getWorkTree().toURI().toString();
        replacedertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size());
        File f = new File(workDir, "f");
        add(f);
        String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        Map<String, GitTransportUpdate> updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        Map<String, GitBranch> remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(id, remoteBranches.get("master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        // modification
        write(f, "huhu");
        add(f);
        String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(newid, remoteBranches.get("master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
    }

    public void testPushUpdateInRemotes() throws Exception {
        String remoteUri = getRemoteRepository().getWorkTree().toURI().toString();
        replacedertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size());
        File f = new File(workDir, "f");
        add(f);
        String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        Map<String, GitTransportUpdate> updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        Map<String, GitBranch> remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(id, remoteBranches.get("master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        getClient(workDir).pull(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/remotes/origin/master" }), "master", NULL_PROGRESS_MONITOR);
        Map<String, GitBranch> branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, branches.size());
        replacedertEquals(id, branches.get("origin/master").getId());
        // modification
        write(f, "huhu");
        add(f);
        String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        GitPushResult result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR);
        updates = result.getRemoteRepositoryUpdates();
        Map<String, GitTransportUpdate> localUpdates = result.getLocalRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, branches.size());
        // not yet updated, tracking branches has not been set
        replacedertEquals(0, localUpdates.size());
        replacedertEquals(id, branches.get("origin/master").getId());
        // another modification
        write(f, "huhu2");
        add(f);
        newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Arrays.asList(new String[] { "refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR);
        updates = result.getRemoteRepositoryUpdates();
        localUpdates = result.getLocalRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, branches.size());
        replacedertEquals(1, localUpdates.size());
        replacedertUpdate(localUpdates.get("master"), "origin/master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, EnumSet.of(GitRefUpdateResult.FAST_FORWARD, GitRefUpdateResult.FORCED));
        replacedertEquals(newid, branches.get("origin/master").getId());
        // let's set tracking branch
        StoredConfig cfg = repository.getConfig();
        cfg.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", ConfigConstants.CONFIG_KEY_URL, new URIish(remoteUri).toString());
        cfg.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch", "+refs/heads/master:refs/remotes/origin/master");
        cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE, "origin");
        cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/master");
        cfg.save();
        // what about now???
        write(f, "huhu3");
        add(f);
        id = newid;
        newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        result = getClient(workDir).push("origin", Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR);
        updates = result.getRemoteRepositoryUpdates();
        localUpdates = result.getLocalRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, branches.size());
        replacedertEquals(1, localUpdates.size());
        replacedertUpdate(localUpdates.get("master"), "origin/master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, EnumSet.of(GitRefUpdateResult.FAST_FORWARD, GitRefUpdateResult.FORCED));
        replacedertEquals(newid, branches.get("origin/master").getId());
        // and what about adding a new branch, does it show among remotes?
        result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/newbranch" }), Arrays.asList(new String[] { "refs/heads/newbranch:refs/remotes/origin/newbranch" }), NULL_PROGRESS_MONITOR);
        updates = result.getRemoteRepositoryUpdates();
        localUpdates = result.getLocalRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(2, remoteBranches.size());
        branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR);
        replacedertEquals(3, branches.size());
        replacedertEquals(1, localUpdates.size());
        replacedertUpdate(localUpdates.get("newbranch"), "origin/newbranch", "newbranch", newid, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.NEW);
        replacedertEquals(newid, branches.get("origin/newbranch").getId());
    }

    public void testPushRejectNonFastForward() throws Exception {
        String remoteUri = getRemoteRepository().getWorkTree().toURI().toString();
        replacedertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size());
        File f = new File(workDir, "f");
        add(f);
        String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        Map<String, GitTransportUpdate> updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        Map<String, GitBranch> remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(id, remoteBranches.get("master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        // modification
        write(f, "huhu");
        add(f);
        String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(newid, remoteBranches.get("master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        getClient(workDir).createBranch("localbranch", id, NULL_PROGRESS_MONITOR);
        getClient(workDir).checkoutRevision("localbranch", true, NULL_PROGRESS_MONITOR);
        write(f, "huhu2");
        add(f);
        id = getClient(workDir).commit(new File[] { f }, "some change before merge", null, null, NULL_PROGRESS_MONITOR).getRevision();
        updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "+refs/heads/localbranch:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(newid, remoteBranches.get("master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("master"), "localbranch", "master", id, newid, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.REJECTED_NONFASTFORWARD);
        updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/localbranch:refs/heads/master" }), Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteBranches.size());
        replacedertEquals(newid, remoteBranches.get("master").getId());
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("master"), "localbranch", "master", id, newid, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.REJECTED_NONFASTFORWARD);
        // if starts failing, the WA at GitTransportUpdate.(URIish uri, TrackingRefUpdate update) should be removed
        // this.result = GitRefUpdateResult.valueOf((update.getResult() == null ? RefUpdate.Result.NOT_ATTEMPTED : update.getResult()).name());
        Transport transport = Transport.open(getRepository(getClient(workDir)), new URIish(remoteUri));
        transport.setDryRun(false);
        transport.setPushThin(true);
        PushResult pushResult = transport.push(new DelegatingProgressMonitor(NULL_PROGRESS_MONITOR), Transport.findRemoteRefUpdatesFor(getRepository(getClient(workDir)), Collections.singletonList(new RefSpec("refs/heads/localbranch:refs/heads/master")), Collections.singletonList(new RefSpec("refs/heads/master:refs/remotes/origin/master"))));
        replacedertEquals(1, pushResult.getTrackingRefUpdates().size());
        for (TrackingRefUpdate update : pushResult.getTrackingRefUpdates()) {
            // null but not NOT_ATTEMPTED, probably a bug
            // remove the WA if it starts failing here
            replacedertNull(update.getResult());
        }
    }

    public void testPushTag() throws Exception {
        String remoteUri = getRemoteRepository().getWorkTree().toURI().toString();
        replacedertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size());
        File f = new File(workDir, "f");
        add(f);
        String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        GitTag tag = getClient(workDir).createTag("my-tag", id, "tag message", false, false, NULL_PROGRESS_MONITOR);
        Map<String, GitTransportUpdate> updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master", "refs/tags/my-tag:refs/tags/my-tag" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        Map<String, String> remoteTags = getClient(workDir).listRemoteTags(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(1, remoteTags.size());
        replacedertEquals(tag.getTagId(), remoteTags.get("my-tag"));
        replacedertEquals(2, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        replacedertUpdate(updates.get("my-tag"), "my-tag", "my-tag", tag.getTagId(), null, new URIish(remoteUri).toString(), Type.TAG, GitRefUpdateResult.OK);
        // modification, updating tag fails when not force update
        write(f, "huhu");
        add(f);
        String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision();
        GitTag newTag = getClient(workDir).createTag("my-tag", newid, "tag message", false, true, NULL_PROGRESS_MONITOR);
        updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master", "refs/tags/my-tag:refs/tags/my-tag" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        remoteTags = getClient(workDir).listRemoteTags(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(tag.getTagId(), remoteTags.get("my-tag"));
        replacedertEquals(2, updates.size());
        replacedertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK);
        replacedertUpdate(updates.get("my-tag"), "my-tag", "my-tag", newTag.getTagId(), null, new URIish(remoteUri).toString(), Type.TAG, GitRefUpdateResult.REJECTED_NONFASTFORWARD);
        // modification, updating tag now works
        write(f, "huhu");
        add(f);
        updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "+refs/tags/my-tag:refs/tags/my-tag" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates();
        remoteTags = getClient(workDir).listRemoteTags(remoteUri, NULL_PROGRESS_MONITOR);
        replacedertEquals(newTag.getTagId(), remoteTags.get("my-tag"));
        replacedertEquals(1, updates.size());
        replacedertUpdate(updates.get("my-tag"), "my-tag", "my-tag", newTag.getTagId(), null, new URIish(remoteUri).toString(), Type.TAG, GitRefUpdateResult.OK);
    }

    private void replacedertUpdate(GitTransportUpdate update, String localName, String remoteName, String newObjectId, String oldObjectId, String remoteUri, Type type, GitRefUpdateResult result) {
        replacedertUpdate(update, localName, remoteName, newObjectId, oldObjectId, remoteUri, type, EnumSet.of(result));
    }

    private void replacedertUpdate(GitTransportUpdate update, String localName, String remoteName, String newObjectId, String oldObjectId, String remoteUri, Type type, EnumSet<GitRefUpdateResult> allowedResults) {
        replacedertEquals(localName, update.getLocalName());
        replacedertEquals(remoteName, update.getRemoteName());
        replacedertEquals(newObjectId, update.getNewObjectId());
        replacedertEquals(oldObjectId, update.getOldObjectId());
        replacedertEquals(remoteUri, update.getRemoteUri());
        replacedertEquals(type, update.getType());
        replacedertTrue("Result: " + update.getResult() + " not allowed: " + allowedResults, allowedResults.contains(update.getResult()));
    }
}

19 View Complete Implementation : RevertTest.java
Copyright Apache License 2.0
Author : apache
public void testRevertLastTwoCommits() throws Exception {
    File f = new File(workDir, "f");
    File[] files = new File[] { f };
    write(f, "a\nb\nc");
    add(f);
    commit(f);
    // modify and commit
    write(f, "z\nb\nc");
    add(f);
    GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    // second commit
    write(f, "z\nb\ny");
    add(f);
    GitRevisionInfo commit2 = getClient(workDir).commit(files, "modification 2", null, null, NULL_PROGRESS_MONITOR);
    replacedertEquals("z\nb\ny", read(f));
    getClient(workDir).revert(commit2.getRevision(), null, true, NULL_PROGRESS_MONITOR);
    replacedertEquals("z\nb\nc", read(f));
    getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR);
    replacedertEquals("a\nb\nc", read(f));
}

19 View Complete Implementation : RevertTest.java
Copyright Apache License 2.0
Author : apache
public void testRevertLastCommitTwoFiles() throws Exception {
    File f1 = new File(workDir, "f");
    File f2 = new File(workDir, "f2");
    File[] files = new File[] { f1, f2 };
    write(f1, "init1");
    write(f2, "init2");
    add(files);
    commit(files);
    // modify and commit
    write(f1, "change1");
    write(f2, "change2");
    add(files);
    GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    replacedertEquals("change1", read(f1));
    replacedertEquals("change2", read(f2));
    getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR);
    replacedertEquals("init1", read(f1));
    replacedertEquals("init2", read(f2));
}

19 View Complete Implementation : RevertTest.java
Copyright Apache License 2.0
Author : apache
public void testRevertNotIncluded() throws Exception {
    File f = new File(workDir, "f");
    File[] files = new File[] { f };
    write(f, "init");
    add(f);
    commit(f);
    getClient(workDir).createBranch("branch", "master", NULL_PROGRESS_MONITOR);
    // modify and commit
    write(f, "change");
    add(f);
    GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    getClient(workDir).checkoutRevision("branch", true, NULL_PROGRESS_MONITOR);
    GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR);
    replacedertEquals(GitRevertResult.Status.NO_CHANGE, result.getStatus());
}

19 View Complete Implementation : GitClassFactory.java
Copyright Apache License 2.0
Author : apache
public abstract GitTag createTag(String tagName, GitRevisionInfo revCommit);

19 View Complete Implementation : HistoryProvider.java
Copyright Apache License 2.0
Author : apache
@Override
public synchronized HistoryEntry[] getHistory(File[] files, Date fromDate) {
    replacedert !SwingUtilities.isEventDispatchThread() : "Accessing remote repository. Do not call in awt!";
    Set<File> repositories = getRepositoryRoots(files);
    if (repositories == null) {
        return null;
    }
    List<HistoryEntry> ret = new LinkedList<HistoryEntry>();
    Map<String, Set<File>> rev2FileMap = new HashMap<String, Set<File>>();
    Map<String, GitRevisionInfo> rev2LMMap = new LinkedHashMap<String, GitRevisionInfo>();
    File repositoryRoot = repositories.iterator().next();
    for (File file : files) {
        FileInformation info = Git.getInstance().getFileStatusCache().getStatus(file);
        if (!info.containsStatus(FileInformation.STATUS_MANAGED)) {
            continue;
        }
        GitRevisionInfo[] history;
        try {
            history = HistoryRegistry.getInstance().getLogs(repositoryRoot, files, fromDate, null, GitUtils.NULL_PROGRESS_MONITOR);
            for (GitRevisionInfo h : history) {
                String r = h.getRevision();
                rev2LMMap.put(r, h);
                Set<File> s = rev2FileMap.get(r);
                if (s == null) {
                    s = new HashSet<File>();
                    rev2FileMap.put(r, s);
                }
                s.add(file);
            }
        } catch (GitException ex) {
            LOG.log(Level.INFO, null, ex);
        }
    }
    for (GitRevisionInfo h : rev2LMMap.values()) {
        Set<File> s = rev2FileMap.get(h.getRevision());
        File[] involvedFiles = s.toArray(new File[s.size()]);
        HistoryEntry e = createHistoryEntry(h, involvedFiles, repositoryRoot);
        ret.add(e);
    }
    return ret.toArray(new HistoryEntry[ret.size()]);
}

19 View Complete Implementation : CherryPickCommand.java
Copyright Apache License 2.0
Author : apache
private GitRevisionInfo getCurrentHead() {
    GitRevisionInfo currHead;
    Repository repository = getRepository();
    try {
        currHead = getClreplacedFactory().createRevisionInfo(Utils.findCommit(repository, Constants.HEAD), repository);
    } catch (GitException ex) {
        currHead = null;
    }
    return currHead;
}

19 View Complete Implementation : RepositoryRevision.java
Copyright Apache License 2.0
Author : apache
public clreplaced RepositoryRevision {

    private GitRevisionInfo message;

    /**
     * List of events replacedociated with the revision.
     */
    private final List<Event> events = new ArrayList<Event>(5);

    private final List<Event> dummyEvents;

    private final Map<File, String> commonAncestors = new HashMap<File, String>();

    private final Set<GitTag> tags;

    private final Set<GitBranch> branches;

    private boolean eventsInitialized;

    private Search currentSearch;

    private final PropertyChangeSupport support;

    // NOI18N
    public static final String PROP_EVENTS_CHANGED = "eventsChanged";

    private final File repositoryRoot;

    private final File[] selectionRoots;

    private String preferredRevision;

    private final SearchExecutor.Mode mode;

    RepositoryRevision(GitRevisionInfo message, File repositoryRoot, File[] selectionRoots, Set<GitTag> tags, Set<GitBranch> branches, File dummyFile, String dummyFileRelativePath, SearchExecutor.Mode mode) {
        this.message = message;
        this.repositoryRoot = repositoryRoot;
        this.selectionRoots = selectionRoots;
        this.tags = tags;
        this.branches = branches;
        support = new PropertyChangeSupport(this);
        dummyEvents = new ArrayList<Event>(1);
        if (dummyFile != null && dummyFileRelativePath != null) {
            dummyEvents.add(new Event(dummyFile, dummyFileRelativePath));
        }
        this.mode = mode;
    }

    public Event[] getEvents() {
        return events.toArray(new Event[events.size()]);
    }

    Event[] getDummyEvents() {
        return dummyEvents.toArray(new Event[dummyEvents.size()]);
    }

    public GitRevisionInfo getLog() {
        return message;
    }

    @Override
    public String toString() {
        StringBuilder text = new StringBuilder();
        text.append(getLog().getRevision());
        // NOI18N
        text.append("\t");
        text.append(DateFormat.getDateTimeInstance().format(new Date(getLog().getCommitTime())));
        // NOI18N
        text.append("\t");
        // NOI18N
        text.append(getLog().getAuthor());
        // NOI18N
        text.append("\n");
        text.append(getLog().getFullMessage());
        return text.toString();
    }

    String getAncestorCommit(File file, GitClient client, ProgressMonitor pm) throws GitException {
        String ancestorCommit = commonAncestors.get(file);
        if (ancestorCommit == null && !commonAncestors.containsKey(file)) {
            GitRevisionInfo info = null;
            if (getLog().getParents().length == 1) {
                info = client.getPreviousRevision(file, getLog().getRevision(), pm);
            } else if (getLog().getParents().length > 1) {
                info = client.getCommonAncestor(getLog().getParents(), pm);
            }
            ancestorCommit = info == null ? null : info.getRevision();
            commonAncestors.put(file, ancestorCommit);
        }
        return ancestorCommit;
    }

    public GitBranch[] getBranches() {
        return branches == null ? new GitBranch[0] : branches.toArray(new GitBranch[branches.size()]);
    }

    public GitTag[] getTags() {
        return tags == null ? new GitTag[0] : tags.toArray(new GitTag[tags.size()]);
    }

    boolean expandEvents() {
        Search s = currentSearch;
        if (s == null && !eventsInitialized) {
            currentSearch = new Search();
            currentSearch.start(Git.getInstance().getRequestProcessor(repositoryRoot), repositoryRoot);
            return true;
        }
        return !eventsInitialized;
    }

    void cancelExpand() {
        Search s = currentSearch;
        if (s != null) {
            s.cancel();
            currentSearch = null;
        }
    }

    boolean isEventsInitialized() {
        return eventsInitialized;
    }

    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        support.addPropertyChangeListener(propertyName, listener);
    }

    public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        support.removePropertyChangeListener(propertyName, listener);
    }

    File getRepositoryRoot() {
        return repositoryRoot;
    }

    String getShortRevision() {
        String revision = getLog().getRevision();
        if (revision.length() > 7) {
            revision = revision.substring(0, 7);
        }
        return revision;
    }

    @NbBundle.Messages({ "# {0} - revision", "LBL_Action.CheckoutRevision=Checkout {0}", "# {0} - revision", "MSG_CheckoutRevision.progress=Checking out {0}" })
    Action[] getActions() {
        if (RepositoryInfo.getInstance(repositoryRoot) == null) {
            // repository deleted? Then return no actions, nothing makes sense any more.
            return new Action[0];
        }
        List<Action> actions = new ArrayList<Action>();
        final String revision = getPreferredRevision();
        actions.add(new AbstractAction(Bundle.LBL_Action_CheckoutRevision(revision)) {

            @Override
            public void actionPerformed(ActionEvent e) {
                CheckoutRevisionAction action = SystemAction.get(CheckoutRevisionAction.clreplaced);
                action.checkoutRevision(repositoryRoot, revision, null, Bundle.MSG_CheckoutRevision_progress(revision));
            }
        });
        actions.add(new // NOI18N
        AbstractAction(// NOI18N
        NbBundle.getMessage(RepositoryRevision.clreplaced, "CTL_SummaryView_TagCommit")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                CreateTagAction action = SystemAction.get(CreateTagAction.clreplaced);
                action.createTag(repositoryRoot, getLog().getRevision());
            }
        });
        if (getLog().getParents().length < 2) {
            if (!isInCurrentBranch()) {
                actions.add(new // NOI18N
                AbstractAction(// NOI18N
                NbBundle.getMessage(CherryPickAction.clreplaced, "LBL_CherryPickAction_PopupName")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final String revision = getLog().getRevision();
                        Utils.post(new Runnable() {

                            @Override
                            public void run() {
                                SystemAction.get(CherryPickAction.clreplaced).cherryPick(repositoryRoot, revision);
                            }
                        });
                    }
                });
            }
            actions.add(new // NOI18N
            AbstractAction(// NOI18N
            NbBundle.getMessage(ExportCommitAction.clreplaced, "LBL_ExportCommitAction_PopupName")) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    ExportCommitAction action = SystemAction.get(ExportCommitAction.clreplaced);
                    action.exportCommit(repositoryRoot, getLog().getRevision());
                }
            });
            if (mode != SearchExecutor.Mode.REMOTE_IN) {
                actions.add(new // NOI18N
                AbstractAction(// NOI18N
                NbBundle.getMessage(RevertCommitAction.clreplaced, "LBL_RevertCommitAction_PopupName")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        RevertCommitAction action = SystemAction.get(RevertCommitAction.clreplaced);
                        action.revert(repositoryRoot, selectionRoots, getLog().getRevision());
                    }
                });
            }
        }
        return actions.toArray(new Action[actions.size()]);
    }

    private String getPreferredRevision() {
        if (preferredRevision == null) {
            for (GitBranch branch : getBranches()) {
                if (branch.getName() != GitBranch.NO_BRANCH) {
                    if (!branch.isRemote()) {
                        preferredRevision = branch.getName();
                        break;
                    } else if (preferredRevision == null) {
                        preferredRevision = branch.getName();
                    }
                }
            }
        }
        if (preferredRevision == null) {
            for (GitTag tag : getTags()) {
                preferredRevision = tag.getTagName();
                break;
            }
        }
        if (preferredRevision == null) {
            preferredRevision = getLog().getRevision();
            preferredRevision = preferredRevision.length() > 7 ? preferredRevision.substring(0, 7) : preferredRevision;
        }
        return preferredRevision;
    }

    private boolean isInCurrentBranch() {
        GitBranch activeBranch = RepositoryInfo.getInstance(repositoryRoot).getActiveBranch();
        for (GitBranch b : getLog().getBranches().values()) {
            if (activeBranch.getName().equals(b.getName()) || activeBranch.getId().equals(b.getId())) {
                return true;
            }
        }
        return false;
    }

    public clreplaced Event implements Comparable<Event> {

        /**
         * The file or folder that this event is about. It may be null if the File cannot be computed.
         */
        private final File file;

        private final String path;

        private final Status status;

        private boolean underRoots;

        private final File originalFile;

        private final String originalPath;

        public Event(GitFileInfo changedPath, boolean underRoots) {
            path = changedPath.getRelativePath();
            file = changedPath.getFile();
            originalPath = changedPath.getOriginalPath() == null ? path : changedPath.getOriginalPath();
            originalFile = changedPath.getOriginalFile() == null ? file : changedPath.getOriginalFile();
            status = changedPath.getStatus();
            this.underRoots = underRoots;
        }

        private Event(File dummyFile, String dummyPath) {
            this.path = dummyPath;
            this.file = dummyFile;
            this.originalPath = dummyPath;
            this.originalFile = dummyFile;
            this.status = Status.UNKNOWN;
            underRoots = true;
        }

        public RepositoryRevision getLogInfoHeader() {
            return RepositoryRevision.this;
        }

        public File getFile() {
            return file;
        }

        public File getOriginalFile() {
            return originalFile;
        }

        public String getName() {
            return getFile().getName();
        }

        public String getPath() {
            return path;
        }

        public char getAction() {
            switch(status) {
                case ADDED:
                    return 'A';
                case MODIFIED:
                    return 'M';
                case RENAMED:
                    return 'R';
                case COPIED:
                    return 'C';
                case REMOVED:
                    return 'D';
                default:
                    return '?';
            }
        }

        @Override
        public String toString() {
            return path;
        }

        @Override
        public int compareTo(Event other) {
            int retval = status.compareTo(other.status);
            if (retval == 0) {
                retval = path.compareTo(other.path);
            }
            return retval;
        }

        boolean isUnderRoots() {
            return underRoots;
        }

        String getOriginalPath() {
            return originalPath;
        }

        Action[] getActions(boolean forNodes) {
            List<Action> actions = new ArrayList<Action>();
            if (isViewEnabled()) {
                actions.add(getViewAction(forNodes ? null : this));
                actions.add(getAnnotateAction(forNodes ? null : this));
                actions.add(getRevertAction(forNodes ? null : this));
                actions.add(getViewCurrentAction(forNodes ? null : this));
            }
            return actions.toArray(new Action[actions.size()]);
        }

        void openFile(boolean showAnnotations, ProgressMonitor pm) {
            try {
                String revision = getLogInfoHeader().getLog().getRevision();
                GitUtils.openInRevision(getFile(), -1, revision, showAnnotations, pm);
            } catch (IOException ex) {
                Logger.getLogger(RepositoryRevision.clreplaced.getName()).log(Level.FINE, null, ex);
            }
        }

        private Action getViewAction(Event event) {
            if (event == null) {
                return viewAction;
            } else {
                return new ViewAction(repositoryRoot, event);
            }
        }

        private Action getViewCurrentAction(Event event) {
            if (event == null) {
                return viewCurrentAction;
            } else {
                return new ViewCurrentAction(event.getFile());
            }
        }

        private Action getAnnotateAction(Event event) {
            if (event == null) {
                return annotateAction;
            } else {
                return new AnnotateAction(repositoryRoot, event);
            }
        }

        RevertAction getRevertAction(Event event) {
            if (event == null) {
                return revertAction;
            } else {
                return new RevertAction(repositoryRoot, new File[] { event.getFile() }, event.getLogInfoHeader().getShortRevision());
            }
        }

        private boolean isViewEnabled() {
            return getFile() != null && getAction() != 'D';
        }
    }

    private static abstract clreplaced HistoryEventAction extends AbstractAction implements ContextAwareAction {

        public HistoryEventAction(String name) {
            super(name);
        }

        @Override
        public Action createContextAwareInstance(Lookup actionContext) {
            return createAction(actionContext.lookupAll(RevisionNode.clreplaced));
        }

        private Action createAction(Collection<? extends RevisionNode> nodes) {
            List<Event> events = new ArrayList<Event>(nodes.size());
            File root = null;
            for (RevisionNode n : nodes) {
                root = n.getEvent().getLogInfoHeader().getRepositoryRoot();
                if (n.getEvent().isViewEnabled()) {
                    events.add(n.getEvent());
                }
            }
            return createAction(root, events.toArray(new Event[events.size()]));
        }

        protected abstract Action createAction(File repositoryRoot, Event... events);
    }

    private static ViewAction viewAction = new ViewAction();

    private static ViewCurrentAction viewCurrentAction = new ViewCurrentAction();

    private static AnnotateAction annotateAction = new AnnotateAction();

    private static RevertAction revertAction = new RevertAction(0);

    private static clreplaced ViewAction extends HistoryEventAction {

        Event[] events;

        private File repositoryRoot;

        private ViewAction() {
            // NOI18N
            super(NbBundle.getMessage(SummaryView.clreplaced, "CTL_SummaryView_View"));
        }

        private ViewAction(File repositoryRoot, Event... events) {
            this();
            this.events = events;
            this.repositoryRoot = repositoryRoot;
        }

        @Override
        public boolean isEnabled() {
            return events.length > 0;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            new GitProgressSupport() {

                @Override
                protected void perform() {
                    for (Event ev : events) {
                        if (ev.isViewEnabled()) {
                            ev.openFile(false, getProgressMonitor());
                        }
                    }
                }
            }.start(Git.getInstance().getRequestProcessor(), repositoryRoot, // NOI18N
            NbBundle.getMessage(SummaryView.clreplaced, "MSG_SummaryView.openingFilesFromHistory"));
        }

        @Override
        protected Action createAction(File repositoryRoot, Event... events) {
            return new ViewAction(repositoryRoot, events);
        }
    }

    @NbBundle.Messages({ "CTL_Action.ViewCurrent.name=View Current" })
    private static clreplaced ViewCurrentAction extends HistoryEventAction {

        File[] files;

        private ViewCurrentAction() {
            super(Bundle.CTL_Action_ViewCurrent_name());
        }

        private ViewCurrentAction(File... files) {
            this();
            this.files = files;
        }

        @Override
        public boolean isEnabled() {
            return files.length > 0;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            Utils.post(new Runnable() {

                @Override
                public void run() {
                    for (File f : files) {
                        Utils.openFile(FileUtil.normalizeFile(f));
                    }
                }
            });
        }

        @Override
        protected Action createAction(File repositoryRoot, Event... events) {
            Set<File> fileSet = new HashSet<File>(events.length);
            for (Event e : events) {
                if (e.isViewEnabled()) {
                    fileSet.add(e.getFile());
                }
            }
            return new ViewCurrentAction(fileSet.toArray(new File[fileSet.size()]));
        }
    }

    private static clreplaced AnnotateAction extends HistoryEventAction {

        Event[] events;

        private File repositoryRoot;

        private AnnotateAction() {
            // NOI18N
            super(NbBundle.getMessage(SummaryView.clreplaced, "CTL_SummaryView_ShowAnnotations"));
        }

        private AnnotateAction(File repositoryRoot, Event... events) {
            this();
            this.events = events;
            this.repositoryRoot = repositoryRoot;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            new GitProgressSupport() {

                @Override
                protected void perform() {
                    for (Event ev : events) {
                        ev.openFile(true, getProgressMonitor());
                    }
                }
            }.start(Git.getInstance().getRequestProcessor(), repositoryRoot, // NOI18N
            NbBundle.getMessage(SummaryView.clreplaced, "MSG_SummaryView.openingFilesFromHistory"));
        }

        @Override
        protected Action createAction(File repositoryRoot, Event... events) {
            return new AnnotateAction(repositoryRoot, events);
        }
    }

    @NbBundle.Messages({ "RepositoryRevision.action.RevertTo.single=Revert File", "RepositoryRevision.action.RevertTo=Revert Files", "RepositoryRevision.action.RevertTo.progress=Reverting Files" })
    static clreplaced RevertAction extends HistoryEventAction {

        private File[] files;

        private String revision;

        private File repositoryRoot;

        private RevertAction(int fileSize) {
            super(fileSize == 1 ? Bundle.RepositoryRevision_action_RevertTo_single() : Bundle.RepositoryRevision_action_RevertTo());
        }

        private RevertAction(File repositoryRoot, File[] files, String revision) {
            this(files.length);
            this.revision = revision;
            this.files = files;
            this.repositoryRoot = repositoryRoot;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            SystemAction.get(RevertChangesAction.clreplaced).revertFiles(repositoryRoot, files, revision, Bundle.RepositoryRevision_action_RevertTo_progress());
        }

        @Override
        protected Action createAction(File repositoryRoot, Event... events) {
            String rev = null;
            List<File> fileList = new ArrayList<File>(events.length);
            for (Event e : events) {
                String eventRevision = e.getLogInfoHeader().getShortRevision();
                if (rev == null) {
                    rev = eventRevision;
                } else if (!rev.equals(eventRevision)) {
                    // action disabled for multiple revision
                    rev = null;
                    break;
                }
                if (e.isViewEnabled()) {
                    fileList.add(e.getFile());
                }
            }
            final boolean enbl = rev != null;
            return new RevertAction(repositoryRoot, fileList.toArray(new File[fileList.size()]), rev) {

                @Override
                public boolean isEnabled() {
                    return enbl;
                }
            };
        }
    }

    private clreplaced Search extends GitProgressSupport {

        @Override
        protected void perform() {
            Map<File, GitFileInfo> files;
            try {
                files = getLog().getModifiedFiles();
            } catch (GitException ex) {
                GitClientExceptionHandler.notifyException(ex, true);
                files = Collections.<File, GitFileInfo>emptyMap();
            }
            final List<Event> logEvents = prepareEvents(files);
            if (!isCanceled()) {
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        if (!isCanceled()) {
                            events.clear();
                            dummyEvents.clear();
                            events.addAll(logEvents);
                            eventsInitialized = true;
                            currentSearch = null;
                            support.firePropertyChange(RepositoryRevision.PROP_EVENTS_CHANGED, null, new ArrayList<Event>(events));
                        }
                    }
                });
            }
        }

        @Override
        protected void finishProgress() {
        }

        @Override
        protected void startProgress() {
        }

        @Override
        protected ProgressHandle getProgressHandle() {
            return null;
        }

        private void start(RequestProcessor requestProcessor, File repositoryRoot) {
            start(requestProcessor, repositoryRoot, null);
        }

        private List<Event> prepareEvents(Map<File, GitFileInfo> files) {
            final List<Event> logEvents = new ArrayList<Event>(files.size());
            Set<File> renamedFilesOriginals = new HashSet<File>(files.size());
            for (Map.Entry<File, GitFileInfo> e : files.entrySet()) {
                if (e.getValue().getStatus() == Status.RENAMED) {
                    renamedFilesOriginals.add(e.getValue().getOriginalFile());
                }
            }
            for (Map.Entry<File, GitFileInfo> e : files.entrySet()) {
                File f = e.getKey();
                if (renamedFilesOriginals.contains(f)) {
                    // lets not track delete part of a rename and display only the rename itself
                    continue;
                }
                GitFileInfo info = e.getValue();
                boolean underRoots = false;
                for (File selectionRoot : selectionRoots) {
                    if (VersioningSupport.isFlat(selectionRoot)) {
                        underRoots = selectionRoot.equals(f.getParentFile());
                    } else {
                        underRoots = Utils.isAncestorOrEqual(selectionRoot, f);
                    }
                    if (underRoots) {
                        break;
                    }
                }
                logEvents.add(new Event(info, underRoots));
            }
            Collections.sort(logEvents);
            return logEvents;
        }
    }
}

19 View Complete Implementation : ExportCommitTest.java
Copyright Apache License 2.0
Author : apache
private void replacedertPatchFile(GitRevisionInfo commit, File goldenFile, File patchFile) throws Exception {
    String expectedContent = read(goldenFile);
    expectedContent = MessageFormat.format(expectedContent, new Object[] { commit.getRevision(), commit.getAuthor(), DateFormat.getDateTimeInstance().format(new Date(commit.getCommitTime())), commit.getFullMessage() });
    replacedertEquals(expectedContent, read(patchFile));
}

18 View Complete Implementation : ExportCommitTest.java
Copyright Apache License 2.0
Author : apache
public void testExportMergeFail() throws Exception {
    File patchFile = new File(workDir.getParentFile(), "diff.patch");
    File file = new File(workDir, "file");
    File[] files = new File[] { file };
    write(file, "a\nb\nc\n");
    add(files);
    commit(files);
    GitClient client = getClient(workDir);
    client.createBranch("branch", "master", NULL_PROGRESS_MONITOR);
    client.checkoutRevision("branch", true, NULL_PROGRESS_MONITOR);
    write(file, "modification on branch\nb\nc\n");
    add(files);
    GitRevisionInfo branchCommit = client.commit(files, "branch modified", null, null, NULL_PROGRESS_MONITOR);
    client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR);
    write(file, "a\nb\nmodification on master\n");
    add(files);
    GitRevisionInfo commit = client.commit(files, "master modified", null, null, NULL_PROGRESS_MONITOR);
    replacedertEquals(GitMergeResult.MergeStatus.MERGED, client.merge("branch", NULL_PROGRESS_MONITOR).getMergeStatus());
    try {
        exportDiff("master", patchFile);
        fail();
    } catch (GitException ex) {
        replacedertEquals("Unable to export a merge commit", ex.getMessage());
    }
}

18 View Complete Implementation : ExportCommitTest.java
Copyright Apache License 2.0
Author : apache
public void testExportInitialCommit() throws Exception {
    File patchFile = new File(workDir.getParentFile(), "diff.patch");
    File file = new File(workDir, "file");
    File[] files = new File[] { file };
    write(file, "init\n");
    add(files);
    GitClient client = getClient(workDir);
    GitRevisionInfo commit = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR);
    exportDiff("master", patchFile);
    replacedertPatchFile(commit, getGoldenFile("exportInitialCommit.patch"), patchFile);
}

18 View Complete Implementation : ExportCommitTest.java
Copyright Apache License 2.0
Author : apache
public void testExportCommit() throws Exception {
    File patchFile = new File(workDir.getParentFile(), "diff.patch");
    File file = new File(workDir, "file");
    File[] files = new File[] { file };
    write(file, "init\n");
    add(files);
    commit(files);
    GitClient client = getClient(workDir);
    write(file, "modification\n");
    add(files);
    GitRevisionInfo commit = client.commit(files, "my commit message", null, null, NULL_PROGRESS_MONITOR);
    exportDiff(commit.getRevision(), patchFile);
    replacedertPatchFile(commit, getGoldenFile("exportCommit.patch"), patchFile);
}

18 View Complete Implementation : ExportCommitTest.java
Copyright Apache License 2.0
Author : apache
public void testExportCommitMultiLine() throws Exception {
    File patchFile = new File(workDir.getParentFile(), "diff.patch");
    File file = new File(workDir, "file");
    File file2 = new File(workDir, "file2");
    File[] files = new File[] { file, file2 };
    write(file, "init\n");
    write(file2, "init\n");
    add(files);
    commit(files);
    GitClient client = getClient(workDir);
    write(file, "modification 1\n");
    write(file2, "modification 2\n");
    add(files);
    GitRevisionInfo commit = client.commit(files, "first\nsecond\nthird", null, null, NULL_PROGRESS_MONITOR);
    exportDiff(commit.getRevision(), patchFile);
    replacedertPatchFile(commit, getGoldenFile("exportCommitMultiLine.patch"), patchFile);
}

18 View Complete Implementation : GetCommonAncestorTest.java
Copyright Apache License 2.0
Author : apache
public void testGetBaseRevisionCommitsInRow() throws Exception {
    File f = new File(workDir, "f");
    write(f, "init");
    File[] files = new File[] { f };
    add(files);
    commit(files);
    GitClient client = getClient(workDir);
    write(f, "modification 1");
    add(files);
    GitRevisionInfo commit1 = client.commit(files, "modification 1", null, null, NULL_PROGRESS_MONITOR);
    write(f, "modification 2");
    add(files);
    GitRevisionInfo commit2 = client.commit(files, "modification 2", null, null, NULL_PROGRESS_MONITOR);
    write(f, "modification 3");
    add(files);
    GitRevisionInfo commit3 = client.commit(files, "modification 3", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo revision = client.getCommonAncestor(new String[] { commit1.getRevision(), commit2.getRevision(), commit3.getRevision() }, NULL_PROGRESS_MONITOR);
    replacedertRevisions(commit1, revision);
}

18 View Complete Implementation : GetCommonAncestorTest.java
Copyright Apache License 2.0
Author : apache
public void testGetBaseRevisionMerge() throws Exception {
    File f = new File(workDir, "f");
    write(f, "a\nb\nc");
    File[] files = new File[] { f };
    add(files);
    commit(files);
    GitClient client = getClient(workDir);
    write(f, "a\nb\nc\n");
    add(files);
    GitRevisionInfo revisionBase = client.commit(files, "base revision", null, null, NULL_PROGRESS_MONITOR);
    client.createBranch("b", "master", NULL_PROGRESS_MONITOR);
    client.checkoutRevision("b", true, NULL_PROGRESS_MONITOR);
    write(f, "modification on branch\nb\nc\n");
    add(files);
    client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR);
    write(f, "a\nb\nmodification on master\n");
    add(files);
    client.commit(files, "modification on master", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo revisionMerge = client.log(client.merge("b", NULL_PROGRESS_MONITOR).getNewHead(), NULL_PROGRESS_MONITOR);
    GitRevisionInfo revision = client.getCommonAncestor(revisionMerge.getParents(), NULL_PROGRESS_MONITOR);
    replacedertRevisions(revisionBase, revision);
}

18 View Complete Implementation : GetPreviousRevisionTest.java
Copyright Apache License 2.0
Author : apache
public void testGetPreviousRevision() throws Exception {
    File f = new File(workDir, "f");
    write(f, "init");
    File[] files = new File[] { f };
    add(files);
    commit(files);
    GitClient client = getClient(workDir);
    write(f, "modification");
    add(files);
    GitRevisionInfo commit1 = client.commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    write(f, "modification2");
    add(files);
    GitRevisionInfo commit2 = client.commit(files, "modification2", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo revision = client.getPreviousRevision(f, commit2.getRevision(), NULL_PROGRESS_MONITOR);
    replacedertRevisions(commit1, revision);
}

18 View Complete Implementation : GetCommonAncestorTest.java
Copyright Apache License 2.0
Author : apache
public void testGetBaseRevisionSimpleCommit() throws Exception {
    File f = new File(workDir, "f");
    write(f, "init");
    File[] files = new File[] { f };
    add(files);
    commit(files);
    GitClient client = getClient(workDir);
    write(f, "modification");
    add(files);
    GitRevisionInfo commit = client.commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo revision = client.getCommonAncestor(new String[] { commit.getRevision() }, NULL_PROGRESS_MONITOR);
    replacedertRevisions(commit, revision);
}

18 View Complete Implementation : RevertTest.java
Copyright Apache License 2.0
Author : apache
public void testRevertFailure() throws Exception {
    File f = new File(workDir, "f");
    File[] files = new File[] { f };
    write(f, "init");
    add(f);
    commit(f);
    // modify and commit
    write(f, "change");
    add(f);
    GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR);
    write(f, "local change");
    GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR);
    replacedertEquals("local change", read(f));
    replacedertEquals(Arrays.asList(f), result.getFailures());
    replacedertEquals(GitRevertResult.Status.FAILED, result.getStatus());
    replacedertNull(repository.readMergeCommitMsg());
}

18 View Complete Implementation : StashTest.java
Copyright Apache License 2.0
Author : apache
public void testStashDrop() throws Exception {
    File file = new File(workDir, "file");
    write(file, "file");
    add();
    commit();
    write(file, "modification");
    add();
    GitClient client = getClient(workDir);
    client.stashSave("stash", false, NULL_PROGRESS_MONITOR);
    write(file, "modification 2");
    add();
    write(file, "modification 3");
    client.stashSave("stash", false, NULL_PROGRESS_MONITOR);
    GitRevisionInfo[] stashList = client.stashList(NULL_PROGRESS_MONITOR);
    replacedertEquals(2, stashList.length);
    client.stashDrop(1, NULL_PROGRESS_MONITOR);
    GitRevisionInfo[] stashList2 = client.stashList(NULL_PROGRESS_MONITOR);
    replacedertEquals(1, stashList2.length);
    replacedertEquals(stashList[0].getRevision(), stashList2[0].getRevision());
}

18 View Complete Implementation : UpdateRefTest.java
Copyright Apache License 2.0
Author : apache
public void testNotAttempted() throws Exception {
    File f = new File(workDir, "f");
    write(f, "init");
    add(f);
    commit(f);
    write(f, "modi");
    add(f);
    commit(f);
    GitClient client = getClient(workDir);
    GitRevisionInfo info = client.log("HEAD", NULL_PROGRESS_MONITOR);
    client.reset("HEAD~1", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR);
    GitRefUpdateResult res = client.updateReference("HEAD", info.getRevision(), NULL_PROGRESS_MONITOR);
    replacedertEquals(GitRefUpdateResult.NOT_ATTEMPTED, res);
}

18 View Complete Implementation : UpdateRefTest.java
Copyright Apache License 2.0
Author : apache
public void testMoveMergeCommit() throws Exception {
    File f = new File(workDir, "f");
    write(f, "init");
    add(f);
    commit(f);
    write(f, "modif");
    add(f);
    commit(f);
    GitClient client = getClient(workDir);
    GitRevisionInfo info = client.log("HEAD", NULL_PROGRESS_MONITOR);
    client.reset("HEAD~1", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR);
    GitRefUpdateResult res = client.updateReference("master", info.getRevision(), NULL_PROGRESS_MONITOR);
    replacedertEquals(GitRefUpdateResult.FAST_FORWARD, res);
    ReflogReader reflogReader = repository.getReflogReader("master");
    replacedertEquals("merge " + info.getRevision() + ": Fast-forward", reflogReader.getLastEntry().getComment());
}

18 View Complete Implementation : GetPreviousRevisionTest.java
Copyright Apache License 2.0
Author : apache
public void testGetPreviousRevisionSkipUntouched() throws Exception {
    File f = new File(workDir, "f");
    File f2 = new File(workDir, "f2");
    write(f, "init");
    write(f2, "init");
    File[] files = new File[] { f, f2 };
    add(files);
    GitClient client = getClient(workDir);
    GitRevisionInfo init = client.commit(files, "init", null, null, NULL_PROGRESS_MONITOR);
    write(f, "modification 1");
    add(files);
    GitRevisionInfo commit1 = client.commit(files, "modification 1", null, null, NULL_PROGRESS_MONITOR);
    // commit 2 does not touch "f"
    write(f2, "modification 2");
    add(files);
    GitRevisionInfo commit2 = client.commit(files, "modification 2", null, null, NULL_PROGRESS_MONITOR);
    write(f, "modification 3");
    add(files);
    GitRevisionInfo commit3 = client.commit(files, "modification 3", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo revision = client.getPreviousRevision(f, commit3.getRevision(), NULL_PROGRESS_MONITOR);
    replacedertRevisions(commit1, revision);
    revision = client.getPreviousRevision(f2, commit2.getRevision(), NULL_PROGRESS_MONITOR);
    replacedertRevisions(init, revision);
    revision = client.getCommonAncestor(new String[] { commit2.getParents()[0] }, NULL_PROGRESS_MONITOR);
    replacedertRevisions(commit1, revision);
    revision = client.getPreviousRevision(f2, commit3.getRevision(), NULL_PROGRESS_MONITOR);
    replacedertRevisions(commit2, revision);
}

18 View Complete Implementation : RepositoryRevision.java
Copyright Apache License 2.0
Author : apache
String getAncestorCommit(File file, GitClient client, ProgressMonitor pm) throws GitException {
    String ancestorCommit = commonAncestors.get(file);
    if (ancestorCommit == null && !commonAncestors.containsKey(file)) {
        GitRevisionInfo info = null;
        if (getLog().getParents().length == 1) {
            info = client.getPreviousRevision(file, getLog().getRevision(), pm);
        } else if (getLog().getParents().length > 1) {
            info = client.getCommonAncestor(getLog().getParents(), pm);
        }
        ancestorCommit = info == null ? null : info.getRevision();
        commonAncestors.put(file, ancestorCommit);
    }
    return ancestorCommit;
}

18 View Complete Implementation : SearchExecutor.java
Copyright Apache License 2.0
Author : apache
private List<RepositoryRevision> appendResults(GitRevisionInfo[] logMessages, Collection<GitBranch> allBranches, Collection<GitTag> allTags, ProgressMonitor monitor) {
    List<RepositoryRevision> results = new ArrayList<RepositoryRevision>();
    File dummyFile = null;
    String dummyFileRelativePath = null;
    if (master.getRoots().length == 1) {
        // dummy event must be implemented
        dummyFile = master.getRoots()[0];
        dummyFileRelativePath = GitUtils.getRelativePath(getRepositoryRoot(), dummyFile);
    }
    for (int i = 0; i < logMessages.length && !monitor.isCanceled(); ++i) {
        GitRevisionInfo logMessage = logMessages[i];
        if (logMessage.getRevision().equals(excludedCommitId)) {
            continue;
        }
        RepositoryRevision rev;
        Set<GitBranch> branches = new HashSet<GitBranch>();
        Set<GitTag> tags = new HashSet<GitTag>();
        for (GitBranch b : allBranches) {
            if (b.getId().equals(logMessage.getRevision())) {
                branches.add(b);
            }
        }
        for (GitTag t : allTags) {
            if (t.getTaggedObjectId().equals(logMessage.getRevision())) {
                tags.add(t);
            }
        }
        rev = new RepositoryRevision(logMessage, master.getRepository(), master.getRoots(), tags, branches, dummyFile, dummyFileRelativePath, mode);
        results.add(rev);
    }
    return results;
}

18 View Complete Implementation : RepositoryInfo.java
Copyright Apache License 2.0
Author : apache
private static boolean equals(List<GitRevisionInfo> oldList, List<GitRevisionInfo> newList) {
    boolean retval = oldList.size() == newList.size();
    if (retval) {
        for (Lisreplacederator<GitRevisionInfo> itOld = oldList.lisreplacederator(), itNew = newList.lisreplacederator(); itOld.hasNext(); ) {
            GitRevisionInfo oldInfo = itOld.next();
            GitRevisionInfo newInfo = itNew.next();
            if (!oldInfo.getRevision().equals(newInfo.getRevision())) {
                retval = false;
                break;
            }
        }
    }
    return retval;
}

18 View Complete Implementation : Stash.java
Copyright Apache License 2.0
Author : apache
public static List<Stash> create(File repository, List<GitRevisionInfo> stash) {
    int i = 0;
    List<Stash> items = new ArrayList<>(stash.size());
    for (GitRevisionInfo info : stash) {
        items.add(new Stash(repository, info, i++));
    }
    return items;
}

18 View Complete Implementation : Stash.java
Copyright Apache License 2.0
Author : apache
/**
 * @author Ondrej Vrabec
 */
@NbBundle.Messages({ "MSG_ApplyStashAction.progressName=Applying stash", "LBL_ApplyStashAction.outOfSync=Stashes Outdated", "MSG_ApplyStashAction.outOfSync=Cached stashes are outdated, please refresh the stashes." })
public final clreplaced Stash {

    private final GitRevisionInfo info;

    private final int index;

    private final String name;

    private final File repository;

    private Stash(File repository, GitRevisionInfo info, int index) {
        this.repository = repository;
        this.info = info;
        this.index = index;
        // NOI18N
        this.name = "stash@{" + index + "}";
    }

    public static List<Stash> create(File repository, List<GitRevisionInfo> stash) {
        int i = 0;
        List<Stash> items = new ArrayList<>(stash.size());
        for (GitRevisionInfo info : stash) {
            items.add(new Stash(repository, info, i++));
        }
        return items;
    }

    public int getIndex() {
        return index;
    }

    public GitRevisionInfo getInfo() {
        return info;
    }

    public String getName() {
        return name;
    }

    public Action getApplyAction() {
        return new // NOI18N
        AbstractAction(// NOI18N
        NbBundle.getMessage(ApplyStashAction.clreplaced, "LBL_ApplyStashAction_PopupName")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                Stash.this.apply(false);
            }
        };
    }

    public void apply(final boolean drop) {
        Utils.postParallel(new Runnable() {

            @Override
            public void run() {
                GitProgressSupport supp = new GitProgressSupport() {

                    @Override
                    protected void perform() {
                        try {
                            final GitClient client = getClient();
                            RepositoryInfo info = RepositoryInfo.getInstance(repository);
                            List<GitRevisionInfo> stashes = info.refreshStashes();
                            GitRevisionInfo currStash = stashes.get(index);
                            // check if the stash index is up to date and we're applying the correct stash
                            if (!currStash.getRevision().equals(getInfo().getRevision())) {
                                GitUtils.notifyError(Bundle.LBL_ApplyStashAction_outOfSync(), Bundle.MSG_ApplyStashAction_outOfSync());
                                return;
                            }
                            GitUtils.runWithoutIndexing(new Callable<Void>() {

                                @Override
                                public Void call() throws Exception {
                                    client.stashApply(index, drop, getProgressMonitor());
                                    return null;
                                }
                            }, new File[] { repository });
                            if (drop) {
                                RepositoryInfo.getInstance(repository).refreshStashes();
                            }
                        } catch (GitException ex) {
                            GitClientExceptionHandler.notifyException(ex, true);
                        } finally {
                            // NOI18N
                            setDisplayName(NbBundle.getMessage(GitAction.clreplaced, "LBL_Progress.RefreshingStatuses"));
                            Git.getInstance().getFileStatusCache().refreshAllRoots(Collections.<File, Collection<File>>singletonMap(repository, Git.getInstance().getSeenRoots(repository)));
                        }
                    }
                };
                supp.start(Git.getInstance().getRequestProcessor(repository), repository, Bundle.MSG_ApplyStashAction_progressName());
            }
        }, 0);
    }
}

18 View Complete Implementation : ExportCommitTest.java
Copyright Apache License 2.0
Author : apache
public void testExportCommitRename() throws Exception {
    File patchFile = new File(workDir.getParentFile(), "diff.patch");
    File file = new File(workDir, "file");
    File renamed = new File(workDir, "renamed");
    File[] files = new File[] { file, renamed };
    write(file, "first\nsecond\nthrirrd\n");
    add(files);
    commit(files);
    GitClient client = getClient(workDir);
    client.rename(file, renamed, false, NULL_PROGRESS_MONITOR);
    write(renamed, "first\nsecond\nthird\n");
    add(renamed);
    GitRevisionInfo commit = client.commit(files, "file renamed", null, null, NULL_PROGRESS_MONITOR);
    exportDiff(commit.getRevision(), patchFile);
    replacedertPatchFile(commit, getGoldenFile("exportCommitRename.patch"), patchFile);
}

17 View Complete Implementation : HistoryProvider.java
Copyright Apache License 2.0
Author : apache
private HistoryEntry createHistoryEntry(GitRevisionInfo h, File[] involvedFiles, File repositoryRoot) {
    GitUser user = h.getAuthor();
    if (user == null) {
        user = h.getCommitter();
    }
    String username = user.getName();
    String author = user.toString();
    String message = h.getFullMessage();
    replacedert message != null;
    HistoryEntry e = new HistoryEntry(involvedFiles, new Date(h.getCommitTime()), // NOI18N
    message == null ? "" : message, author, username, h.getRevision(), h.getRevision().length() > 7 ? h.getRevision().substring(0, 7) : h.getRevision(), getActions(), new RevisionProviderImpl(h.getRevision()), null, new ParentProviderImpl(h, involvedFiles, repositoryRoot));
    return e;
}

17 View Complete Implementation : RebaseAction.java
Copyright Apache License 2.0
Author : apache
private static GitHookContext.LogEntry[] getEntries(GitClient client, String revisionFrom, String revisionTo, ProgressMonitor pm) throws GitException {
    SearchCriteria crit = new SearchCriteria();
    crit.setRevisionFrom(revisionFrom);
    crit.setRevisionTo(revisionTo);
    GitRevisionInfo[] log = client.log(crit, false, pm);
    return convertToEntries(log);
}

17 View Complete Implementation : RebaseAction.java
Copyright Apache License 2.0
Author : apache
private static GitHookContext.LogEntry[] convertToEntries(GitRevisionInfo[] messages) {
    List<GitHookContext.LogEntry> entries = new ArrayList<GitHookContext.LogEntry>(messages.length);
    for (GitRevisionInfo msg : messages) {
        entries.add(new GitHookContext.LogEntry(msg.getFullMessage(), msg.getAuthor().toString(), msg.getRevision(), new Date(msg.getCommitTime())));
    }
    return entries.toArray(new GitHookContext.LogEntry[entries.size()]);
}

17 View Complete Implementation : GitUtils.java
Copyright Apache License 2.0
Author : apache
public static void printInfo(StringBuilder sb, GitRevisionInfo info, boolean endWithNewLine) {
    // NOI18N
    String lbrevision = NbBundle.getMessage(CommitAction.clreplaced, "MSG_CommitAction.logCommit.revision");
    // NOI18N
    String lbauthor = NbBundle.getMessage(CommitAction.clreplaced, "MSG_CommitAction.logCommit.author");
    // NOI18N
    String lbcommitter = NbBundle.getMessage(CommitAction.clreplaced, "MSG_CommitAction.logCommit.committer");
    // NOI18N
    String lbdate = NbBundle.getMessage(CommitAction.clreplaced, "MSG_CommitAction.logCommit.date");
    // NOI18N
    String lbsummary = NbBundle.getMessage(CommitAction.clreplaced, "MSG_CommitAction.logCommit.summary");
    String author = info.getAuthor().toString();
    String committer = info.getCommitter().toString();
    // NOI18N
    sb.append(NbBundle.getMessage(CommitAction.clreplaced, "MSG_CommitAction.logCommit.replacedle")).append("\n");
    sb.append(lbrevision);
    sb.append(info.getRevision());
    // NOI18N
    sb.append('\n');
    sb.append(lbauthor);
    sb.append(author);
    // NOI18N
    sb.append('\n');
    if (!author.equals(committer)) {
        sb.append(lbcommitter);
        sb.append(committer);
        // NOI18N
        sb.append('\n');
    }
    sb.append(lbdate);
    sb.append(DateFormat.getDateTimeInstance().format(new Date(info.getCommitTime())));
    // NOI18N
    sb.append('\n');
    sb.append(lbsummary);
    int prefixLen = lbsummary.length();
    sb.append(formatMultiLine(prefixLen, info.getFullMessage()));
    if (endWithNewLine) {
        sb.append('\n');
    }
}

17 View Complete Implementation : GetCommonAncestorTest.java
Copyright Apache License 2.0
Author : apache
public void testGetBaseCrissCrossConflict_244222() throws Exception {
    File f1 = new File(workDir, "f1");
    File f2 = new File(workDir, "f2");
    File f3 = new File(workDir, "f3");
    write(f1, "initial content");
    GitClient client = getClient(workDir);
    File[] files = new File[] { f1, f2, f3 };
    client.add(files, NULL_PROGRESS_MONITOR);
    GitRevisionInfo initial = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR);
    client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR);
    // change on master
    write(f1, Constants.MASTER);
    client.add(files, NULL_PROGRESS_MONITOR);
    client.commit(files, "master commit", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo masterCommit = client.log("master", NULL_PROGRESS_MONITOR);
    // change on branch
    client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
    write(f1, BRANCH_NAME);
    client.add(files, NULL_PROGRESS_MONITOR);
    client.commit(files, "branch commit", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo branchCommit = client.log(BRANCH_NAME, NULL_PROGRESS_MONITOR);
    // merge last master commit (not merge) into branch
    GitMergeResult res = client.merge(masterCommit.getRevision(), NULL_PROGRESS_MONITOR);
    replacedertEquals(GitMergeResult.MergeStatus.CONFLICTING, res.getMergeStatus());
    write(f1, BRANCH_NAME);
    client.add(files, NULL_PROGRESS_MONITOR);
    client.commit(new File[0], "Merge master into branch", null, null, NULL_PROGRESS_MONITOR);
    // merge last branch commit (not merge) into master
    client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
    res = client.merge(branchCommit.getRevision(), NULL_PROGRESS_MONITOR);
    replacedertEquals(GitMergeResult.MergeStatus.CONFLICTING, res.getMergeStatus());
    write(f1, Constants.MASTER);
    client.add(files, NULL_PROGRESS_MONITOR);
    client.commit(new File[0], "Merge branch into master", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo ancestor = client.getCommonAncestor(new String[] { Constants.MASTER, BRANCH_NAME }, NULL_PROGRESS_MONITOR);
    replacedertEquals(initial.getRevision(), ancestor.getRevision());
}

17 View Complete Implementation : GetCommonAncestorTest.java
Copyright Apache License 2.0
Author : apache
public void testGetBaseCrissCross_232904() throws Exception {
    File f1 = new File(workDir, "f1");
    File f2 = new File(workDir, "f2");
    File f3 = new File(workDir, "f3");
    write(f1, "initial content");
    GitClient client = getClient(workDir);
    File[] files = new File[] { f1, f2, f3 };
    client.add(files, NULL_PROGRESS_MONITOR);
    GitRevisionInfo initial = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR);
    client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR);
    // change on master
    write(f1, Constants.MASTER);
    client.add(files, NULL_PROGRESS_MONITOR);
    client.commit(files, "master commit", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo masterCommit = client.log("master", NULL_PROGRESS_MONITOR);
    // change on branch
    client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
    write(f2, BRANCH_NAME);
    client.add(files, NULL_PROGRESS_MONITOR);
    client.commit(files, "branch commit", null, null, NULL_PROGRESS_MONITOR);
    GitRevisionInfo branchCommit = client.log(BRANCH_NAME, NULL_PROGRESS_MONITOR);
    // merge last master commit (not merge) into branch
    client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
    client.merge(masterCommit.getRevision(), NULL_PROGRESS_MONITOR);
    // merge last branch commit (not merge) into master
    client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
    client.merge(branchCommit.getRevision(), NULL_PROGRESS_MONITOR);
    GitRevisionInfo ancestor = client.getCommonAncestor(new String[] { Constants.MASTER, BRANCH_NAME }, NULL_PROGRESS_MONITOR);
    replacedertEquals(initial.getRevision(), ancestor.getRevision());
}