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.centurylink.mdw.dataaccess.file.VersionControlGit.java

License:Apache License

public boolean isTracked(String path) throws IOException {
    ObjectId objectId = localRepo.resolve(Constants.HEAD);
    RevTree tree;/*from ww  w . j  a  va2 s. c  o  m*/
    RevWalk walk = null;
    if (objectId != null) {
        walk = new RevWalk(localRepo);
        tree = walk.parseTree(objectId);
    } else {
        tree = null;
    }

    try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
        treeWalk.setRecursive(true);
        if (tree != null)
            treeWalk.addTree(tree);
        else
            treeWalk.addTree(new EmptyTreeIterator());

        treeWalk.addTree(new DirCacheIterator(localRepo.readDirCache()));
        treeWalk.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
        return treeWalk.next();
    } finally {
        if (walk != null)
            walk.close();
    }
}

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

License:Apache License

public byte[] readFromHead(String filePath) throws Exception {
    return readFromCommit(ObjectId.toString(localRepo.resolve(Constants.HEAD)), filePath);
}

From source file:com.cloudata.git.jgit.CloudGitRepositoryStore.java

License:Apache License

Repository openUncached(GitRepository repo, boolean mustExist) throws IOException {
    String objectPath = repo.getObjectPath();

    // ByteString suffix = ZERO.concat(ByteString.copyFromUtf8(absolutePath)).concat(ZERO);
    // KeyValuePath refsPath = refsBase.child(suffix);

    DfsRepositoryDescription description = new DfsRepositoryDescription(objectPath);
    ObjectStorePath repoPath = new ObjectStorePath(objectStore, objectPath);
    CloudDfsRepository dfs = new CloudDfsRepository(repo.getData(), description, repoPath, dataStore, tempDir);

    try {//w w  w  .  j  a v a 2  s. c  o m
        if (!dfs.exists()) {
            if (mustExist) {
                throw new RepositoryNotFoundException(repo.getData().getName());
            }
            dfs.create(true);
            dfs.updateRef(Constants.HEAD).link("refs/heads/master");
        }
    } catch (IOException e) {
        throw new IllegalStateException("Error creating repository", e);
    }

    dfs.getConfig().setBoolean("http", null, "receivepack", true);

    return dfs;
}

From source file:com.creactiviti.piper.core.git.JGitTemplate.java

License:Apache License

private List<IdentifiableResource> getHeadFiles(Repository aRepository, String... aSearchPaths) {
    List<String> searchPaths = Arrays.asList(aSearchPaths);
    List<IdentifiableResource> resources = new ArrayList<>();
    try (ObjectReader reader = aRepository.newObjectReader();
            RevWalk walk = new RevWalk(reader);
            TreeWalk treeWalk = new TreeWalk(aRepository, reader);) {
        final ObjectId id = aRepository.resolve(Constants.HEAD);
        RevCommit commit = walk.parseCommit(id);
        RevTree tree = commit.getTree();
        treeWalk.addTree(tree);//from  w  w w . ja va2 s  . c  o  m
        treeWalk.setRecursive(true);
        while (treeWalk.next()) {
            String path = treeWalk.getPathString();
            if (searchPaths.stream().anyMatch((sp) -> path.startsWith(sp))) {
                ObjectId objectId = treeWalk.getObjectId(0);
                logger.debug("Loading {} [{}]", path, objectId.name());
                resources.add(readBlob(aRepository, path.substring(0, path.indexOf('.')), objectId.name()));
            }
        }
        return resources;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.fbranches.commands.MergeStableIntoCurrentBranchCommand.java

License:Open Source License

private boolean canMerge(final Repository repository) {
    String message = null;/* www .j a v  a 2  s. c om*/
    Exception ex = null;
    try {
        Ref head = repository.getRef(Constants.HEAD);
        if (head == null || !head.isSymbolic())
            message = UIText.MergeAction_HeadIsNoBranch;
        else if (!repository.getRepositoryState().equals(RepositoryState.SAFE))
            message = NLS.bind(UIText.MergeAction_WrongRepositoryState, repository.getRepositoryState());
        else if (!head.getLeaf().getName().startsWith("refs/heads/features")) { //$NON-NLS-1$
            message = "Current branch is not a feature branch.";
        }
    } catch (IOException e) {
        message = e.getMessage();
        ex = e;
    }

    if (message != null)
        org.eclipse.egit.ui.Activator.handleError(message, ex, true);
    return (message == null);
}

From source file:com.genuitec.org.eclipse.egit.ui.internal.branch.CleanupUncomittedChangesDialog.java

License:Open Source License

@Override
protected void buttonPressed(int buttonId) {
    switch (buttonId) {
    case IDialogConstants.PROCEED_ID:
        CommitUI commitUI = new CommitUI(getShell(), repository, new IResource[0], true);
        shouldContinue = commitUI.commit();
        break;//from  w  w w .j a  v a2 s  .  c o m
    case IDialogConstants.ABORT_ID:
        final ResetOperation operation = new ResetOperation(repository, Constants.HEAD, ResetType.HARD);
        String jobname = NLS.bind(UIText.ResetAction_reset, Constants.HEAD);
        JobUtil.scheduleUserWorkspaceJob(operation, jobname, JobFamilies.RESET);
        shouldContinue = true;
        break;
    case IDialogConstants.SKIP_ID:
        StashCreateUI stashCreateUI = new StashCreateUI(repository);
        shouldContinue = stashCreateUI.createStash(getShell());
        break;
    case IDialogConstants.CANCEL_ID:
    }
    super.buttonPressed(buttonId);
}

From source file:com.gitblit.client.MessageRenderer.java

License:Apache License

private void showRef(String ref, JLabel label) {
    String name = ref;//from   ww w. j  a va 2 s  .com
    Color bg = getBackground();
    Border border = null;
    if (name.startsWith(Constants.R_HEADS)) {
        // local branch
        bg = Color.decode("#CCFFCC");
        name = name.substring(Constants.R_HEADS.length());
        border = new LineBorder(Color.decode("#00CC33"), 1);
    } else if (name.startsWith(Constants.R_REMOTES)) {
        // remote branch
        bg = Color.decode("#CAC2F5");
        name = name.substring(Constants.R_REMOTES.length());
        border = new LineBorder(Color.decode("#6C6CBF"), 1);
    } else if (name.startsWith(Constants.R_TAGS)) {
        // tag
        bg = Color.decode("#FFFFAA");
        name = name.substring(Constants.R_TAGS.length());
        border = new LineBorder(Color.decode("#FFCC00"), 1);
    } else if (name.equals(Constants.HEAD)) {
        // HEAD
        bg = Color.decode("#FFAAFF");
        border = new LineBorder(Color.decode("#FF00EE"), 1);
    } else {
    }
    label.setText(name);
    label.setBackground(bg);
    label.setBorder(border);
    label.setVisible(true);
}

From source file:com.gitblit.client.MessageRenderer.java

License:Apache License

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected)
        setBackground(table.getSelectionBackground());
    else//from www.  j ava  2 s  . c  om
        setBackground(table.getBackground());
    messageLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
    if (value == null) {
        return this;
    }
    FeedEntryModel entry = (FeedEntryModel) value;

    if (gitblit == null) {
        // no gitblit client, just display message
        messageLabel.setText(entry.title);
    } else {
        // show message in BOLD if its a new entry
        if (entry.published.after(gitblit.getLastFeedRefresh(entry.repository, entry.branch))) {
            messageLabel.setText("<html><body><b>" + entry.title);
        } else {
            messageLabel.setText(entry.title);
        }
    }

    // reset ref label
    resetRef(headLabel);
    resetRef(branchLabel);
    resetRef(remoteLabel);
    resetRef(tagLabel);

    int parentCount = 0;
    if (entry.tags != null) {
        for (String tag : entry.tags) {
            if (tag.startsWith("ref:")) {
                // strip ref:
                tag = tag.substring("ref:".length());
            } else {
                // count parents
                if (tag.startsWith("parent:")) {
                    parentCount++;
                }
            }
            if (tag.equals(entry.branch)) {
                // skip current branch label
                continue;
            }
            if (tag.startsWith(Constants.R_HEADS)) {
                // local branch
                showRef(tag, branchLabel);
            } else if (tag.startsWith(Constants.R_REMOTES)) {
                // remote branch
                showRef(tag, remoteLabel);
            } else if (tag.startsWith(Constants.R_TAGS)) {
                // tag
                showRef(tag, tagLabel);
            } else if (tag.equals(Constants.HEAD)) {
                // HEAD
                showRef(tag, headLabel);
            }
        }
    }

    if (parentCount > 1) {
        // multiple parents, show merge icon
        messageLabel.setIcon(mergeIcon);
    } else {
        messageLabel.setIcon(blankIcon);
    }
    return this;
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testStringContent() throws Exception {
    Repository repository = GitBlitSuite.getHelloworldRepository();
    String contentA = JGitUtils.getStringContent(repository, (RevTree) null, "java.java");
    RevCommit commit = JGitUtils.getCommit(repository, Constants.HEAD);
    String contentB = JGitUtils.getStringContent(repository, commit.getTree(), "java.java");

    assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);
    assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);
    assertTrue(contentA.equals(contentB));

    String contentC = JGitUtils.getStringContent(repository, commit.getTree(), "missing.txt");

    // manually construct a blob, calculate the hash, lookup the hash in git
    StringBuilder sb = new StringBuilder();
    sb.append("blob ").append(contentA.length()).append('\0');
    sb.append(contentA);// w w w .  j  a va 2 s .  c  o  m
    String sha1 = StringUtils.getSHA1(sb.toString());
    String contentD = JGitUtils.getStringContent(repository, sha1);
    repository.close();
    assertNull(contentC);
    assertTrue(contentA.equals(contentD));
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testZip() throws Exception {
    assertFalse(CompressionUtils.zip(null, null, null, null, null));
    Repository repository = GitBlitSuite.getHelloworldRepository();
    File zipFileA = new File(GitBlitSuite.REPOSITORIES, "helloworld.zip");
    FileOutputStream fosA = new FileOutputStream(zipFileA);
    boolean successA = CompressionUtils.zip(repository, null, null, Constants.HEAD, fosA);
    fosA.close();//www .  ja va2 s.  c o  m

    File zipFileB = new File(GitBlitSuite.REPOSITORIES, "helloworld-java.zip");
    FileOutputStream fosB = new FileOutputStream(zipFileB);
    boolean successB = CompressionUtils.zip(repository, null, "java.java", Constants.HEAD, fosB);
    fosB.close();

    repository.close();
    assertTrue("Failed to generate zip file!", successA);
    assertTrue(zipFileA.length() > 0);
    zipFileA.delete();

    assertTrue("Failed to generate zip file!", successB);
    assertTrue(zipFileB.length() > 0);
    zipFileB.delete();
}