Example usage for org.eclipse.jgit.lib Constants HEAD

List of usage examples for org.eclipse.jgit.lib Constants HEAD

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants HEAD.

Prototype

String HEAD

To view the source code for org.eclipse.jgit.lib Constants HEAD.

Click Source Link

Document

Special name for the "HEAD" symbolic-ref.

Usage

From source file:com.hazelcast.common.AbstractGitClass.java

License:Open Source License

private void initRepositories(String branchName) throws Exception {
    gitOS = getGit(propertyReader, OS.getRepositoryName());
    gitEE = getGit(propertyReader, EE.getRepositoryName());

    cleanupBranch(null, gitOS);/*from   w ww .j av a  2 s.c  o m*/
    cleanupBranch(null, gitEE);

    repoOS = gitOS.getRepository();
    repoEE = gitEE.getRepository();

    walkOS = new RevWalk(repoOS);
    walkEE = new RevWalk(repoEE);

    Ref headOS = repoOS.exactRef(Constants.HEAD);
    Ref headEE = repoEE.exactRef(Constants.HEAD);

    currentCommitOS = walkOS.parseCommit(headOS.getObjectId());
    currentCommitEE = walkEE.parseCommit(headEE.getObjectId());

    lastCommitOS = currentCommitOS;

    createBranch(branchName, gitOS, currentCommitOS);
    createBranch(branchName, gitEE, currentCommitEE);

    resetCompileCounters();
}

From source file:com.hpe.application.automation.tools.octane.model.processors.scm.GitSCMProcessor.java

License:Open Source License

@Override
public CommonOriginRevision getCommonOriginRevision(final Run run) {
    //for phase 1 this is hard coded since its not possible to calculate it, and configuration from outside will complicate the feature
    //so for this phase we keep it hardcoded.
    CommonOriginRevision commonOriginRevision = new CommonOriginRevision();

    try {/*from   w w  w. j av  a  2  s  . c o m*/
        final AbstractBuild abstractBuild = (AbstractBuild) run;
        FilePath workspace = ((AbstractBuild) run).getWorkspace();
        if (workspace != null) {
            commonOriginRevision = workspace.act(new FilePath.FileCallable<CommonOriginRevision>() {
                @Override
                public CommonOriginRevision invoke(File file, VirtualChannel channel)
                        throws IOException, InterruptedException {
                    CommonOriginRevision result = new CommonOriginRevision();
                    File repoDir = new File(getRemoteString(abstractBuild) + File.separator + ".git");
                    Git git = Git.open(repoDir);
                    Repository repo = git.getRepository();
                    final RevWalk walk = new RevWalk(repo);

                    ObjectId resolveForCurrentBranch = repo.resolve(Constants.HEAD);
                    RevCommit currentBranchCommit = walk.parseCommit(resolveForCurrentBranch);
                    ObjectId resolveForMaster = repo.resolve(MASTER);
                    RevCommit masterCommit = walk.parseCommit(resolveForMaster);

                    walk.reset();
                    walk.setRevFilter(RevFilter.MERGE_BASE);
                    walk.markStart(currentBranchCommit);
                    walk.markStart(masterCommit);
                    final RevCommit base = walk.next();
                    if (base == null)
                        return result;
                    final RevCommit base2 = walk.next();
                    if (base2 != null) {
                        throw new NoMergeBaseException(
                                NoMergeBaseException.MergeBaseFailureReason.MULTIPLE_MERGE_BASES_NOT_SUPPORTED,
                                MessageFormat.format(JGitText.get().multipleMergeBasesFor,
                                        currentBranchCommit.name(), masterCommit.name(), base.name(),
                                        base2.name()));
                    }
                    result.revision = base.getId().getName();
                    result.branch = getBranchName(run);
                    return result;
                }

                @Override
                public void checkRoles(RoleChecker roleChecker) throws SecurityException {
                    if (roleChecker != null) {
                        logger.info("Note : roleChecker is not empty, but no action was taken");
                    }
                }
            });
        }
        logger.info("most recent common revision resolved to " + commonOriginRevision.revision + " (branch: "
                + commonOriginRevision.branch + ")");
    } catch (Exception e) {
        logger.error("failed to resolve most recent common revision", e);
        return commonOriginRevision;
    }
    return commonOriginRevision;
}

From source file:com.jaxio.celerio.output.GITStatusCrawler.java

License:Apache License

private static RevTree getTree(Repository repository) throws IOException {
    ObjectId lastCommitId = repository.resolve(Constants.HEAD);

    // a RevWalk allows to walk over commits based on some filtering
    RevWalk revWalk = new RevWalk(repository);
    RevCommit commit = revWalk.parseCommit(lastCommitId);

    // and using commit's tree find the path
    RevTree tree = commit.getTree();//from   ww  w  .j ava  2s. c  o  m
    return tree;
}

From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareCommitCommand.java

/**
 * Executes the {@code commit} command with all the options and parameters
 * collected by the setter methods of this class. Each instance of this
 * class should only be used for one invocation of the command (means: one
 * call to {@link #call()})//from   w w w .  ja v a 2s .co m
 *
 * @return a {@link RevCommit} object representing the successful commit.
 * @throws NoHeadException
 *             when called on a git repo without a HEAD reference
 * @throws NoMessageException
 *             when called without specifying a commit message
 * @throws UnmergedPathsException
 *             when the current index contained unmerged paths (conflicts)
 * @throws ConcurrentRefUpdateException
 *             when HEAD or branch ref is updated concurrently by someone
 *             else
 * @throws WrongRepositoryStateException
 *             when repository is not in the right state for committing
 * @throws AbortedByHookException
 *             if there are either pre-commit or commit-msg hooks present in
 *             the repository and one of them rejects the commit.
 */
public RevCommit call() throws GitAPIException, NoHeadException, NoMessageException, UnmergedPathsException,
        ConcurrentRefUpdateException, WrongRepositoryStateException, AbortedByHookException {
    checkCallable();
    Collections.sort(only);

    try (RevWalk rw = new RevWalk(repo)) {
        RepositoryState state = repo.getRepositoryState();

        if (!noVerify) {
            Hooks.preCommit(repo, hookOutRedirect).call();
        }

        processOptions(state, rw);

        if (all && !repo.isBare()) {
            try (Git git = new Git(repo)) {
                git.add().addFilepattern(".") //$NON-NLS-1$
                        .setUpdate(true).call();
            } catch (NoFilepatternException e) {
                // should really not happen
                throw new JGitInternalException(e.getMessage(), e);
            }
        }

        Ref head = repo.findRef(Constants.HEAD);
        if (head == null) {
            throw new NoHeadException(JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
        }

        // determine the current HEAD and the commit it is referring to
        ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}"); //$NON-NLS-1$
        if (headId == null && amend)
            throw new WrongRepositoryStateException(JGitText.get().commitAmendOnInitialNotPossible);

        if (headId != null) {
            if (amend) {
                RevCommit previousCommit = rw.parseCommit(headId);
                for (RevCommit p : previousCommit.getParents())
                    parents.add(p.getId());
                if (author == null)
                    author = previousCommit.getAuthorIdent();
            } else {
                parents.add(0, headId);
            }
        }
        if (!noVerify) {
            message = Hooks.commitMsg(repo, hookOutRedirect).setCommitMessage(message).call();
        }

        // lock the index
        //         DirCache index = repo.lockDirCache();
        index.lock();
        try (ObjectInserter odi = repo.newObjectInserter()) {
            if (!only.isEmpty())
                index = createTemporaryIndex(headId, index, rw);

            // Write the index as tree to the object database. This may
            // fail for example when the index contains unmerged paths
            // (unresolved conflicts)
            ObjectId indexTreeId = index.writeTree(odi);

            if (insertChangeId)
                insertChangeId(indexTreeId);

            // Check for empty commits
            if (headId != null && !allowEmpty.booleanValue()) {
                RevCommit headCommit = rw.parseCommit(headId);
                headCommit.getTree();
                if (indexTreeId.equals(headCommit.getTree())) {
                    return null;
                }
            }

            // Create a Commit object, populate it and write it
            CommitBuilder commit = new CommitBuilder();
            commit.setCommitter(committer);
            commit.setAuthor(author);
            commit.setMessage(message);

            commit.setParentIds(parents);
            commit.setTreeId(indexTreeId);
            ObjectId commitId = odi.insert(commit);
            odi.flush();

            RevCommit revCommit = rw.parseCommit(commitId);
            RefUpdate ru = repo.updateRef(Constants.HEAD);
            ru.setNewObjectId(commitId);
            if (reflogComment != null) {
                ru.setRefLogMessage(reflogComment, false);
            } else {
                String prefix = amend ? "commit (amend): " //$NON-NLS-1$
                        : parents.size() == 0 ? "commit (initial): " //$NON-NLS-1$
                                : "commit: "; //$NON-NLS-1$
                ru.setRefLogMessage(prefix + revCommit.getShortMessage(), false);
            }
            if (headId != null) {
                ru.setExpectedOldObjectId(headId);
            } else {
                ru.setExpectedOldObjectId(ObjectId.zeroId());
            }
            Result rc = ru.forceUpdate();
            switch (rc) {
            case NEW:
            case FORCED:
            case FAST_FORWARD: {
                setCallable(false);
                if (state == RepositoryState.MERGING_RESOLVED || isMergeDuringRebase(state)) {
                    // Commit was successful. Now delete the files
                    // used for merge commits
                    repo.writeMergeCommitMsg(null);
                    repo.writeMergeHeads(null);
                } else if (state == RepositoryState.CHERRY_PICKING_RESOLVED) {
                    repo.writeMergeCommitMsg(null);
                    repo.writeCherryPickHead(null);
                } else if (state == RepositoryState.REVERTING_RESOLVED) {
                    repo.writeMergeCommitMsg(null);
                    repo.writeRevertHead(null);
                }
                return revCommit;
            }
            case REJECTED:
            case LOCK_FAILURE:
                throw new ConcurrentRefUpdateException(JGitText.get().couldNotLockHEAD, ru.getRef(), rc);
            default:
                throw new JGitInternalException(MessageFormat.format(JGitText.get().updatingRefFailed,
                        Constants.HEAD, commitId.toString(), rc));
            }
        } finally {
            index.unlock();
        }
    } catch (UnmergedPathException e) {
        throw new UnmergedPathsException(e);
    } catch (IOException e) {
        throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfCommitCommand, e);
    }
}

From source file:com.microsoft.gittf.client.clc.commands.framework.Command.java

License:Open Source License

protected void verifyMasterBranch() throws Exception {
    final Repository repository = getRepository();

    if (!RepositoryUtil.isEmptyRepository(repository)) {
        Ref master = repository.getRef(Constants.R_HEADS + Constants.MASTER);
        Ref head = repository.getRef(Constants.HEAD);
        Ref masterHeadRef = master != null ? master.getLeaf() : null;
        Ref currentHeadRef = head != null ? head.getLeaf() : null;

        if (masterHeadRef == null || !masterHeadRef.getName().equals(currentHeadRef.getName())) {
            throw new Exception(Messages.getString("Command.MasterNotCurrentBranch")); //$NON-NLS-1$
        }/*ww  w.  j a  v a2s.c om*/
    }
}

From source file:com.microsoft.gittf.core.tasks.FetchTaskTest.java

License:Open Source License

@Test
public void testFetchShallow() throws Exception {
    URI projectCollectionURI = new URI("http://fakeCollection:8080/tfs/DefaultCollection"); //$NON-NLS-1$
    String tfsPath = "$/project"; //$NON-NLS-1$
    String gitRepositoryPath = Util.getRepositoryFile(getName()).getAbsolutePath();

    final MockVersionControlService mockVersionControlService = new MockVersionControlService();

    mockVersionControlService.AddFile("$/project/folder/file0.txt", 1); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file0.txt", 1); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file0.txt", 1); //$NON-NLS-1$

    mockVersionControlService.AddFile("$/project/folder/file1.txt", 2); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file1.txt", 2); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file1.txt", 2); //$NON-NLS-1$

    mockVersionControlService.AddFile("$/project/folder/file2.txt", 3); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file2.txt", 3); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file2.txt", 3); //$NON-NLS-1$

    Calendar date = Calendar.getInstance();
    date.set(2012, 11, 12, 18, 15);/*w w w  .jav a 2s  .c  om*/

    MockChangesetProperties changesetProperties = new MockChangesetProperties("ownerDisplayName", //$NON-NLS-1$
            "ownerName", //$NON-NLS-1$
            "committerDisplayName", //$NON-NLS-1$
            "committerName", //$NON-NLS-1$
            "comment", //$NON-NLS-1$
            date);
    mockVersionControlService.updateChangesetInformation(changesetProperties, 3);

    final Repository repository = RepositoryUtil.createNewRepository(gitRepositoryPath, false);

    CloneTask cloneTask = new CloneTask(projectCollectionURI, mockVersionControlService, tfsPath, repository);
    TaskStatus cloneTaskStatus = cloneTask.run(new NullTaskProgressMonitor());

    // Verify task completed without errors
    assertTrue(cloneTaskStatus.isOK());

    // Update some files
    mockVersionControlService.AddFile("$/project/folder/file1.txt", 4); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file1.txt", 4); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file1.txt", 4); //$NON-NLS-1$

    MockChangesetProperties changesetProperties2 = new MockChangesetProperties("ownerDisplayName4", //$NON-NLS-1$
            "ownerName4", //$NON-NLS-1$
            "committerDisplayName4", //$NON-NLS-1$
            "committerName4", //$NON-NLS-1$
            "comment4", //$NON-NLS-1$
            date);
    mockVersionControlService.updateChangesetInformation(changesetProperties2, 4);

    FetchTask fetchTask = new FetchTask(repository, mockVersionControlService);
    TaskStatus fetchTaskStatus = fetchTask.run(new NullTaskProgressMonitor());

    // Verify task completed without errors
    assertTrue(fetchTaskStatus.isOK());

    // Verify the commit fetched
    Ref fetchHeadRef = repository.getRef(Constants.FETCH_HEAD);
    Ref headRef = repository.getRef(Constants.HEAD);

    assertNotNull(fetchHeadRef);
    assertNotNull(headRef);

    ObjectId fetchHeadCommitID = fetchHeadRef.getObjectId();
    ObjectId headCommitID = headRef.getObjectId();

    RevWalk revWalk = new RevWalk(repository);
    RevCommit fetchedCommit = revWalk.parseCommit(fetchHeadCommitID);
    RevCommit headCommit = revWalk.parseCommit(headCommitID);

    assertEquals(fetchedCommit.getFullMessage(), "comment4"); //$NON-NLS-1$

    PersonIdent ownwer = fetchedCommit.getAuthorIdent();
    assertEquals(ownwer.getEmailAddress(), "ownerName4"); //$NON-NLS-1$
    assertEquals(ownwer.getName(), "ownerDisplayName4"); //$NON-NLS-1$

    PersonIdent committer = fetchedCommit.getCommitterIdent();
    assertEquals(committer.getEmailAddress(), "committerName4"); //$NON-NLS-1$
    assertEquals(committer.getName(), "committerDisplayName4"); //$NON-NLS-1$

    // Verify the file content
    TreeWalk treeWalk = new TreeWalk(repository);
    treeWalk.setRecursive(true);

    treeWalk.addTree(headCommit.getTree());
    treeWalk.addTree(fetchedCommit.getTree());

    treeWalk.setFilter(TreeFilter.ANY_DIFF);

    int count = 0;
    while (treeWalk.next()) {
        ObjectId fileObjectId = treeWalk.getObjectId(1);
        byte[] fileContent = repository.getObjectDatabase().open(fileObjectId, OBJ_BLOB).getBytes();

        switch (count) {
        case 0:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent, "$/project/folder/file1.txt", //$NON-NLS-1$
                    4));
            break;
        case 2:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent, "$/project/folder2/file1.txt", //$NON-NLS-1$
                    4));
            break;
        case 1:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent,
                    "$/project/folder/nestedFolder/file1.txt", //$NON-NLS-1$
                    4));
            break;
        }

        count++;
    }

    Git git = new Git(repository);

    // Verify the tags
    List<Ref> tags = git.tagList().call();
    assertEquals(2, tags.size());
}

From source file:com.microsoft.gittf.core.tasks.FetchTaskTest.java

License:Open Source License

@Test
public void testFetchDeep() throws Exception {
    URI projectCollectionURI = new URI("http://fakeCollection:8080/tfs/DefaultCollection"); //$NON-NLS-1$
    String tfsPath = "$/project"; //$NON-NLS-1$
    String gitRepositoryPath = Util.getRepositoryFile(getName()).getAbsolutePath();

    final MockVersionControlService mockVersionControlService = new MockVersionControlService();

    mockVersionControlService.AddFile("$/project/folder/file0.txt", 1); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file0.txt", 1); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file0.txt", 1); //$NON-NLS-1$

    mockVersionControlService.AddFile("$/project/folder/file1.txt", 2); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file1.txt", 2); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file1.txt", 2); //$NON-NLS-1$

    mockVersionControlService.AddFile("$/project/folder/file2.txt", 3); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file2.txt", 3); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file2.txt", 3); //$NON-NLS-1$

    Calendar date = Calendar.getInstance();
    date.set(2012, 11, 12, 18, 15);/* w  w  w.  j  ava 2 s .  com*/

    MockChangesetProperties changesetProperties = new MockChangesetProperties("ownerDisplayName", //$NON-NLS-1$
            "ownerName", //$NON-NLS-1$
            "committerDisplayName", //$NON-NLS-1$
            "committerName", //$NON-NLS-1$
            "comment", //$NON-NLS-1$
            date);
    mockVersionControlService.updateChangesetInformation(changesetProperties, 3);

    final Repository repository = RepositoryUtil.createNewRepository(gitRepositoryPath, false);

    CloneTask cloneTask = new CloneTask(projectCollectionURI, mockVersionControlService, tfsPath, repository);
    TaskStatus cloneTaskStatus = cloneTask.run(new NullTaskProgressMonitor());

    // Verify task completed without errors
    assertTrue(cloneTaskStatus.isOK());

    // Update some files
    mockVersionControlService.AddFile("$/project/folder/file1.txt", 4); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file1.txt", 4); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file1.txt", 4); //$NON-NLS-1$

    MockChangesetProperties changesetProperties2 = new MockChangesetProperties("ownerDisplayName4", //$NON-NLS-1$
            "ownerName4", //$NON-NLS-1$
            "committerDisplayName4", //$NON-NLS-1$
            "committerName4", //$NON-NLS-1$
            "comment4", //$NON-NLS-1$
            date);
    mockVersionControlService.updateChangesetInformation(changesetProperties2, 4);

    mockVersionControlService.AddFile("$/project/folder/file1.txt", 5); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file1.txt", 5); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file1.txt", 5); //$NON-NLS-1$

    MockChangesetProperties changesetProperties3 = new MockChangesetProperties("ownerDisplayName5", //$NON-NLS-1$
            "ownerName5", //$NON-NLS-1$
            "committerDisplayName5", //$NON-NLS-1$
            "committerName5", //$NON-NLS-1$
            "comment5", //$NON-NLS-1$
            date);
    mockVersionControlService.updateChangesetInformation(changesetProperties3, 5);

    FetchTask fetchTask = new FetchTask(repository, mockVersionControlService);
    fetchTask.setDeep(true);
    TaskStatus fetchTaskStatus = fetchTask.run(new NullTaskProgressMonitor());

    // Verify task completed without errors
    assertTrue(fetchTaskStatus.isOK());

    // Retrieve commits
    Ref fetchHeadRef = repository.getRef(Constants.FETCH_HEAD);
    Ref headRef = repository.getRef(Constants.HEAD);

    assertNotNull(fetchHeadRef);
    assertNotNull(headRef);

    ObjectId fetchHeadCommitID = fetchHeadRef.getObjectId();
    ObjectId headCommitID = headRef.getObjectId();

    RevWalk revWalk = new RevWalk(repository);
    RevCommit fetchedCommit = revWalk.parseCommit(fetchHeadCommitID);
    RevCommit headCommit = revWalk.parseCommit(headCommitID);

    assertEquals(fetchedCommit.getParentCount(), 1);

    RevCommit intermediateCommit = revWalk.parseCommit(fetchedCommit.getParent(0).getId());

    // Verify intermediateCommit
    assertEquals(intermediateCommit.getFullMessage(), "comment4"); //$NON-NLS-1$

    PersonIdent ownwer = intermediateCommit.getAuthorIdent();
    assertEquals(ownwer.getEmailAddress(), "ownerName4"); //$NON-NLS-1$
    assertEquals(ownwer.getName(), "ownerDisplayName4"); //$NON-NLS-1$

    PersonIdent committer = intermediateCommit.getCommitterIdent();
    assertEquals(committer.getEmailAddress(), "committerName4"); //$NON-NLS-1$
    assertEquals(committer.getName(), "committerDisplayName4"); //$NON-NLS-1$

    // Verify fetch_head commit
    assertEquals(fetchedCommit.getFullMessage(), "comment5"); //$NON-NLS-1$

    ownwer = fetchedCommit.getAuthorIdent();
    assertEquals(ownwer.getEmailAddress(), "ownerName5"); //$NON-NLS-1$
    assertEquals(ownwer.getName(), "ownerDisplayName5"); //$NON-NLS-1$

    committer = fetchedCommit.getCommitterIdent();
    assertEquals(committer.getEmailAddress(), "committerName5"); //$NON-NLS-1$
    assertEquals(committer.getName(), "committerDisplayName5"); //$NON-NLS-1$

    // Verify the file content
    TreeWalk treeWalk = new TreeWalk(repository);
    treeWalk.setRecursive(true);

    treeWalk.addTree(headCommit.getTree());
    treeWalk.addTree(intermediateCommit.getTree());

    treeWalk.setFilter(TreeFilter.ANY_DIFF);

    int count = 0;
    while (treeWalk.next()) {
        ObjectId fileObjectId = treeWalk.getObjectId(1);
        byte[] fileContent = repository.getObjectDatabase().open(fileObjectId, OBJ_BLOB).getBytes();

        switch (count) {
        case 0:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent, "$/project/folder/file1.txt", //$NON-NLS-1$
                    4));
            break;
        case 2:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent, "$/project/folder2/file1.txt", //$NON-NLS-1$
                    4));
            break;
        case 1:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent,
                    "$/project/folder/nestedFolder/file1.txt", //$NON-NLS-1$
                    4));
            break;
        }

        count++;
    }

    treeWalk.reset();
    treeWalk.setRecursive(true);

    treeWalk.addTree(headCommit.getTree());
    treeWalk.addTree(fetchedCommit.getTree());

    treeWalk.setFilter(TreeFilter.ANY_DIFF);

    count = 0;
    while (treeWalk.next()) {
        ObjectId fileObjectId = treeWalk.getObjectId(1);
        byte[] fileContent = repository.getObjectDatabase().open(fileObjectId, OBJ_BLOB).getBytes();

        switch (count) {
        case 0:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent, "$/project/folder/file1.txt", //$NON-NLS-1$
                    5));
            break;
        case 2:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent, "$/project/folder2/file1.txt", //$NON-NLS-1$
                    5));
            break;
        case 1:
            assertTrue(mockVersionControlService.verifyFileContent(fileContent,
                    "$/project/folder/nestedFolder/file1.txt", //$NON-NLS-1$
                    5));
            break;
        }

        count++;
    }

    Git git = new Git(repository);

    // Verify the tags
    List<Ref> tags = git.tagList().call();
    assertEquals(3, tags.size());
}

From source file:com.microsoft.gittf.core.tasks.PullTaskTest.java

License:Open Source License

private void runPullRebaseTask() throws IOException {
    // Run the pull task
    PullTask pullTask = new PullTask(repository, mockVersionControlService);
    pullTask.setRebase(true);//from w w w . j a v  a 2  s .  c om

    TaskStatus pullTaskStatus = pullTask.run(new NullTaskProgressMonitor());

    // Verify task completed without errors
    assertTrue(pullTaskStatus.isOK());

    // Verify that the repo is in a good state
    assertTrue(repository.getRepositoryState() == RepositoryState.SAFE);

    // Verify rebase happened
    ObjectId fetchedCommitId = pullTask.getCommitId();

    Ref head = repository.getRef(Constants.HEAD);
    RevWalk revWalk = new RevWalk(repository);
    RevCommit headCommit = revWalk.parseCommit(head.getObjectId());

    assertEquals(headCommit.getParentCount(), 1);

    RevCommit parent = headCommit.getParents()[0];

    assertTrue(parent.getId().equals(fetchedCommitId));
}

From source file:com.microsoft.gittf.core.tasks.PullTaskTest.java

License:Open Source License

private void runPullTask(MergeStrategy strategy) throws IOException {
    // Run the pull task
    PullTask pullTask = new PullTask(repository, mockVersionControlService);
    pullTask.setStrategy(strategy);/*  www .  j  av a  2 s.  c  o m*/

    TaskStatus pullTaskStatus = pullTask.run(new NullTaskProgressMonitor());

    // Verify task completed without errors
    assertTrue(pullTaskStatus.isOK());

    ObjectId fetchedCommitId = pullTask.getCommitId();

    // Verify the merge is completed successfully
    Ref head = repository.getRef(Constants.HEAD);

    RevWalk revWalk = new RevWalk(repository);
    RevCommit headCommit = revWalk.parseCommit(head.getObjectId());

    assertEquals(headCommit.getParentCount(), 2);

    RevCommit[] parents = headCommit.getParents();

    assertTrue((parents[0].getId().equals(fetchedCommitId) && parents[1].getId().equals(gitChangeCommitId))
            || (parents[0].getId().equals(gitChangeCommitId) && parents[1].getId().equals(fetchedCommitId)));
}

From source file:com.microsoft.gittf.core.util.CommitUtil.java

License:Open Source License

/**
 * Returns the commit id referenced by HEAD
 * /*from   w w w  . j a va2  s .  co m*/
 * @param repository
 *        the git repository
 * @return
 * @throws Exception
 */
public static ObjectId getCurrentBranchHeadCommitID(final Repository repository) throws Exception {
    return getCommitId(repository, Constants.HEAD);
}