File repoDir = new File("test-git/.git"); // open the repository Repository repo = new Repository(repoDir); // find the HEAD Commit head = repo.mapCommit(Constants.HEAD); // retrieve the tree in HEAD Tree tree = head.getTree(); // 1.2.0 api version here // find a file (as a TreeEntry, which contains the blob object id) TreeWalk treewalk = TreeWalk.forPath(repo, "b/test.txt", tree); // use the blob id to read the file's data byte[] data = repo.open(treewalk.getObjectId(0)).getBytes();
private Commit createCommit() { Commit commit = new Commit(); commit.setMessage(this.commitMessage); CommitUser author = createUser(); commit.setAuthor(author); commit.setCommitter(author); return commit; }
if (merge && ref != null) { Tree currentTree = service.getCommit(repository, ref.getObject().getSha()).getTree(); if (currentTree != null) baseTree = currentTree.getSha(); Commit commit = new Commit(); commit.setMessage(message); commit.setTree(tree); commit.setAuthor(author); commit.setCommitter(author); } catch (IOException e) { throw new MojoExecutionException("Error retrieving user info: " commit.setParents(Collections.singletonList(new Commit().setSha(ref .getObject().getSha()))); created = service.createCommit(repository, commit); else created = new Commit(); info(MessageFormat.format("Creating commit with SHA-1: {0}", created.getSha())); } catch (IOException e) { throw new MojoExecutionException("Error creating commit: " object.setType(TYPE_COMMIT).setSha(created.getSha()); if (ref != null) {
uri.append(SEGMENT_COMMITS); Map<String, Object> params = new HashMap<String, Object>(); params.put("author", commit.getAuthor()); //$NON-NLS-1$ params.put("committer", commit.getCommitter()); //$NON-NLS-1$ params.put("message", commit.getMessage()); //$NON-NLS-1$ List<Commit> parents = commit.getParents(); if (parents != null && parents.size() > 0) { List<String> parentIds = new ArrayList<String>(); for (Commit parent : parents) parentIds.add(parent.getSha()); params.put("parents", parentIds); //$NON-NLS-1$ Tree tree = commit.getTree(); if (tree != null) params.put("tree", tree.getSha()); //$NON-NLS-1$
/** * Saves a commit object into the data * * there are some critical elements of information that are no longer * saved in the v3 api vs v2. Namely the date of the commit and the * parents of the commit. * * @param commit * @return */ public Vertex saveCommit(final Commit commit) { log.trace("saveCommit: enter"); Vertex node = getOrCreateCommit(commit.getSha()); if (commit.getAuthor() != null) { Vertex author = saveUser(commit.getAuthor()); createEdgeIfNotExist(node, author, EdgeType.COMMITAUTHOR); setProperty(node, PropertyName.AUTHORED_DATE, commit.getAuthor().getDate()); } if (commit.getCommitter() != null) { Vertex committer = saveUser(commit.getCommitter()); createEdgeIfNotExist(node, committer, EdgeType.COMMITTER); setProperty(node, PropertyName.COMMITTED_DATE, commit.getCommitter().getDate()); } setProperty(node, PropertyName.COMMIT_ID, commit.getSha()); setProperty(node, PropertyName.MESSAGE, commit.getMessage()); setProperty(node, PropertyName.TREE, commit.getTree()); setProperty(node, PropertyName.URL, commit.getUrl()); log.trace("saveCommit: exit"); return node; }
Tree currentTree = ref != null ? service.getCommit(repository, ref.getObject().getSha()).getTree() : null; String baseTree = null; if (currentTree != null) tree.setTree(tree2); Commit commit = createCommit(); commit.setTree(tree); Commit created = service.createCommit(repository, commit); TypedResource object = new TypedResource(); object.setType(TypedResource.TYPE_COMMIT).setSha(created.getSha()); if (ref != null) {
if (merge && ref != null) { Tree currentTree = service.getCommit(repository, ref.getObject().getSha()).getTree(); if (currentTree != null) baseTree = currentTree.getSha(); Commit commit = new Commit(); commit.setMessage(message); commit.setTree(tree); commit.setAuthor(author); commit.setCommitter(author); } catch (IOException e) { throw new MojoExecutionException("Error retrieving user info: " commit.setParents(Collections.singletonList(new Commit().setSha(ref .getObject().getSha()))); created = service.createCommit(repository, commit); else created = new Commit(); info(MessageFormat.format("Creating commit with SHA-1: {0}", created.getSha())); } catch (IOException e) { throw new MojoExecutionException("Error creating commit: " object.setType(TYPE_COMMIT).setSha(created.getSha()); if (ref != null) {
File repoDir = new File("test-git/.git"); // open the repository Repository repo = new Repository(repoDir); // find the HEAD Commit head = repo.mapCommit(Constants.HEAD); // retrieve the tree in HEAD Tree tree = head.getTree(); // find a file (as a TreeEntry, which contains the blob object id) TreeEntry entry = tree.findBlobMember("b/test.txt"); // use the blob id to read the file's data byte[] data = repo.openBlob(entry.getId()).getBytes();