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:org.komodo.storage.git.TestGitStorageConnector.java

License:Open Source License

@Test
public void testWriteZipToRepositoryAsDirectory() throws Exception {
    localTmpDir = new File(tmpDir, "localTmpDir-" + timestamp);
    Properties parameters = new Properties();
    parameters.setProperty(GitStorageConnector.REPO_DEST_PROPERTY, localTmpDir.getAbsolutePath());
    parameters.setProperty(GitStorageConnector.REPO_PATH_PROPERTY, myGitDir.getAbsolutePath());

    connector = new GitStorageConnector(parameters);
    connector.refresh();/*from   w  ww.jav a 2 s .  c o  m*/

    String dsName = TestUtilities.US_STATES_VDB_NAME;

    UnitOfWork transaction = mock(UnitOfWork.class);
    when(transaction.getState()).thenReturn(State.NOT_STARTED);

    Exportable artifact = mock(Exportable.class);
    InputStream usStatesExample = TestUtilities.usStatesDataserviceExample();
    byte[] usStatesArr = FileUtils.streamToByteArray(usStatesExample);

    parameters = new Properties();
    parameters.setProperty(GitStorageConnector.FILE_PATH_PROPERTY, DocumentType.ZIP.fileName(dsName));

    when(artifact.export(transaction, parameters)).thenReturn(usStatesArr);
    when(artifact.getName(transaction)).thenReturn(dsName);
    when(artifact.getDocumentType(transaction)).thenReturn(DocumentType.ZIP);

    connector.write(artifact, transaction, parameters);

    //
    // Test the artifact was pushed by walking the origin repository
    //
    usStatesExample = TestUtilities.usStatesDataserviceExample();
    List<String> zipEntries = TestUtilities.zipEntries(dsName, usStatesExample);

    Repository repository = myGit.getRepository();
    ObjectId commitId = repository.resolve(Constants.HEAD);
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit commit = revWalk.parseCommit(commitId);
        RevTree tree = commit.getTree();

        try (TreeWalk treeWalk = new TreeWalk(repository)) {
            treeWalk.addTree(tree);
            treeWalk.setRecursive(false);
            while (treeWalk.next()) {
                zipEntries.remove(treeWalk.getPathString());

                if (treeWalk.isSubtree())
                    treeWalk.enterSubtree();
            }
        }

        //
        // All entries in the original zip have been extracted
        // and pushed to the git repository
        //
        assertTrue("Remaining entries: " + Arrays.toString(zipEntries.toArray(new String[0])),
                zipEntries.isEmpty());
    }
}

From source file:org.libx4j.maven.plugin.version.OriginalResolver.java

License:Open Source License

public OriginalResolver(final Repository repository)
        throws IncorrectObjectTypeException, IOException, MissingObjectException {
    // Resolve the revision specification
    final ObjectId id = repository.resolve(Constants.HEAD);

    this.reader = repository.newObjectReader();
    this.walk = new RevWalk(reader);
    this.commit = walk.parseCommit(id);
}

From source file:org.moxie.utils.JGitUtils.java

License:Apache License

public static String getCommitId(File folder) {
    // try specified folder or subfolder
    File gitDir = FileKey.resolve(folder, FS.DETECTED);

    if (gitDir == null || !gitDir.exists()) {
        // try parent folder
        gitDir = FileKey.resolve(folder.getParentFile(), FS.DETECTED);
    }/*from   w ww  .ja  v  a 2s.  c om*/
    if (gitDir == null || !gitDir.exists()) {
        throw new MoxieException("Can not find .git folder for " + folder);
    }

    String hashid = "";
    try {
        Repository repository = new FileRepository(gitDir);
        ObjectId objectId = repository.resolve(org.eclipse.jgit.lib.Constants.HEAD);
        hashid = objectId.getName().toString();
        repository.close();
    } catch (IOException io) {
        io.printStackTrace();
        throw new MoxieException("IOException accessing " + gitDir.getAbsolutePath(), io);
    }
    return hashid;
}

From source file:org.nbgit.client.CommitBuilder.java

License:Open Source License

/**
 * Write the commit to the repository./*from  ww w .j a va 2s  .c  o m*/
 *
 * @throws IOException if creation of the commit fails.
 */
public void write() throws IOException {
    index.write();
    final RefUpdate ru = repository.updateRef(Constants.HEAD);
    ObjectId[] parentIds;
    if (ru.getOldObjectId() != null)
        parentIds = new ObjectId[] { ru.getOldObjectId() };
    else
        parentIds = new ObjectId[0];

    ObjectId id = writeCommit(index.writeTree(), parentIds);
    if (!updateRef(ru, id))
        logger.output("Failed to update " + ru.getName() + " to commit " + id + ".");
}

From source file:org.nbgit.ui.browser.BrowserAction.java

License:Open Source License

public void performAction(ActionEvent e) {
    final String title = NbBundle.getMessage(BrowserAction.class, "MSG_Browser_TabTitle",
            Utils.getContextDisplayName(context));

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            if (context == null) {
                return;
            }//from  w  w  w. j  a v a2  s . c  om

            BrowserModel model = new BrowserModel(context.getRootFiles(), Constants.HEAD);
            BrowserTopComponent view = new BrowserTopComponent(model);
            view.setDisplayName(title);
            view.open();
            view.requestActive();

            BrowserController controller = new BrowserController(view, model);
            controller.show();
        }
    });
}

From source file:org.nbgit.ui.clone.CloneAction.java

License:Open Source License

private static RequestProcessor.Task performClone(final URIish source, final File target,
        final Boolean projIsRepos, final File projFile, final boolean isLocalClone,
        final boolean scanForProjects) {

    RequestProcessor rp = Git.getInstance().getRequestProcessor(source.toString());
    final GitProgressSupport support = new GitProgressSupport() {

        Repository repo = Git.getInstance().getRepository(target);

        @Override/*w ww  . ja  v a 2  s .  c o  m*/
        protected void perform() {
            String projName = (projFile != null) ? GitProjectUtils.getProjectName(projFile) : null;
            OutputLogger logger = getLogger();
            try {

                if (projName != null) {
                    logger.outputInRed(
                            NbBundle.getMessage(CloneAction.class, "MSG_CLONE_FROM", projName, source)); // NOI18N
                    logger.outputInRed(
                            NbBundle.getMessage(CloneAction.class, "MSG_CLONE_TO", projName, target)); // NOI18N
                } else {
                    logger.outputInRed(
                            NbBundle.getMessage(CloneAction.class, "MSG_EXTERNAL_CLONE_FROM", source)); // NOI18N
                    logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_EXTERNAL_CLONE_TO", target)); // NOI18N
                }
                logger.output(""); // NOI18N

                doInit(repo, source, logger);
                FetchResult r = doFetch(repo, logger);
                Ref branch = r.getAdvertisedRef(Constants.HEAD);
                if (branch == null) {
                    this.cancel();
                }
                doCheckout(repo, branch, logger);

                if (isLocalClone) {
                    Git git = Git.getInstance();
                    ProjectManager projectManager = ProjectManager.getDefault();
                    File normalizedCloneFolder = FileUtil.normalizeFile(target);
                    File cloneProjFile;
                    if (!projIsRepos) {
                        String name = (projFile != null)
                                ? projFile.getAbsolutePath().substring(source.getPath().length() + 1)
                                : target.getAbsolutePath();
                        cloneProjFile = new File(normalizedCloneFolder, name);
                    } else {
                        cloneProjFile = normalizedCloneFolder;
                    }
                    openProject(cloneProjFile, projectManager, git);
                } else if (scanForProjects) {
                    CloneCompleted cc = new CloneCompleted(target);
                    if (isCanceled()) {
                        return;
                    }
                    cc.scanForProjects(this);
                }

            } catch (URISyntaxException usex) {
                notifyLater(usex);
            } catch (IOException ex) {
                notifyLater(ex);
            } finally {
                if (!isLocalClone) {
                    logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_CLONE_DONE")); // NOI18N
                    logger.output(""); // NOI18N
                }
            }
        }

        private void openProject(final File cloneProjFile, final ProjectManager projectManager, final Git git) {
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    // Open and set focus on the cloned project if possible
                    OutputLogger logger = getLogger();
                    try {
                        FileObject cloneProj = FileUtil.toFileObject(cloneProjFile);
                        Project proj = null;
                        if (cloneProjFile != null && cloneProj != null) {
                            proj = projectManager.findProject(cloneProj);
                        }
                        if (proj != null) {
                            GitProjectUtils.openProject(proj, this, false);
                            // TODO: GitModuleConfig.getDefault().getSetMainProject()
                            git.versionedFilesChanged();
                            git.refreshAllAnnotations();
                        } else {
                            logger.outputInRed(NbBundle.getMessage(CloneAction.class,
                                    "MSG_EXTERNAL_CLONE_PRJ_NOT_FOUND_CANT_SETASMAIN")); // NOI18N
                        }
                    } catch (IOException ioe) {
                        notifyLater(ioe);
                    } finally {
                        logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_CLONE_DONE")); // NOI18N
                        logger.output(""); // NOI18N
                    }
                }
            });
        }
    };

    //support.setRepositoryRoot(source);

    return support.start(rp, source.toString(),
            org.openide.util.NbBundle.getMessage(CloneAction.class, "LBL_Clone_Progress", source)); // NO
}

From source file:org.nbgit.ui.clone.CloneAction.java

License:Open Source License

public static void doCheckout(Repository repo, Ref branch, OutputLogger logger) throws IOException {

    final GitIndex index = new GitIndex(repo);
    final Commit mapCommit = repo.mapCommit(branch.getObjectId());
    final Tree tree = mapCommit.getTree();
    final RefUpdate u;
    final WorkDirCheckout co;

    u = repo.updateRef(Constants.HEAD);
    u.setNewObjectId(mapCommit.getCommitId());
    u.forceUpdate();//from   w  w  w  .j  a v  a2  s. c  o  m

    // checking out files
    co = new WorkDirCheckout(repo, repo.getWorkDir(), index, tree);
    co.checkout();
    // writing index
    index.write();
}

From source file:org.nbgit.ui.log.SearchHistoryTopComponent.java

License:Open Source License

private void initComponents(File[] roots, String commitMessage, String username, String from, String to) {
    setLayout(new BorderLayout());
    scp = new SearchCriteriaPanel(roots);
    scp.setCommitMessage(commitMessage);
    scp.setUsername(username);//from  w ww  . j  a  v  a2  s.c  om
    if (from == null) {
        from = Constants.HEAD;
    }
    scp.setFrom(from);
    if (to == null) {
        to = "";
    }
    scp.setTo(to);
    shp = new SearchHistoryPanel(roots, scp);
    add(shp);
}

From source file:org.nbgit.util.GitCommand.java

License:Open Source License

public static RepositoryRevision.Walk getLogMessages(String rootPath, Set<File> files, String fromRevision,
        String toRevision, boolean showMerges, OutputLogger logger) {
    File root = new File(rootPath);
    Repository repo = Git.getInstance().getRepository(root);
    RepositoryRevision.Walk walk = new RepositoryRevision.Walk(repo);

    try {// w ww .  j a  v  a 2s. c  o  m
        if (fromRevision == null) {
            fromRevision = Constants.HEAD;
        }
        ObjectId from = repo.resolve(fromRevision);
        if (from == null) {
            return null;
        }
        walk.markStart(walk.parseCommit(from));
        ObjectId to = toRevision != null ? repo.resolve(toRevision) : null;
        if (to != null) {
            walk.markUninteresting(walk.parseCommit(to));
        }
        List<PathFilter> paths = new ArrayList<PathFilter>();
        for (File file : files) {
            String path = getRelative(root, file);

            if (!(path.length() == 0)) {
                paths.add(PathFilter.create(path));
            }
        }

        if (!paths.isEmpty()) {
            walk.setTreeFilter(PathFilterGroup.create(paths));
        }
        if (!showMerges) {
            walk.setRevFilter(RevFilter.NO_MERGES);
        }
    } catch (IOException ioe) {
        return null;
    }

    return walk;
}

From source file:org.nbgit.util.GitCommand.java

License:Open Source License

public static List<String[]> getRevisionsForFile(File root, File[] files, int limit) {
    Repository repo = Git.getInstance().getRepository(root);
    RevWalk walk = new RevWalk(repo);
    List<String[]> revs = new ArrayList<String[]>();

    try {/*from   ww  w .  j a  v a 2  s . com*/
        ObjectId from = repo.resolve(Constants.HEAD);
        if (from == null) {
            return null;
        }
        walk.markStart(walk.parseCommit(from));

        if (files != null) {
            List<PathFilter> paths = new ArrayList<PathFilter>();
            for (File file : files) {
                String path = getRelative(root, file);

                if (!(path.length() == 0)) {
                    paths.add(PathFilter.create(path));
                }
            }

            if (!paths.isEmpty()) {
                walk.setTreeFilter(PathFilterGroup.create(paths));
            }
        }

        for (RevCommit rev : walk) {
            revs.add(new String[] { rev.getShortMessage(), rev.getId().name() });
            if (--limit <= 0) {
                break;
            }
        }

    } catch (IOException ioe) {
    }

    return revs;
}