String branch = Repository.shortenRefName(head.getTarget()
.getName());
// Commit index changes
CommitBuilder builder = createBuilder(headCommit);
builder.setTreeId(cache.writeTree(inserter));
builder.setMessage(MessageFormat.format(indexMessage, branch,
headCommit.abbreviate(7).name(),
headCommit.getShortMessage()));
ObjectId indexCommit = inserter.insert(builder);
// Commit working tree changes
if (!wtEdits.isEmpty() || !wtDeletes.isEmpty()) {
DirCacheEditor editor = cache.editor();
for (PathEdit edit : wtEdits)
editor.add(edit);
for (String path : wtDeletes)
editor.add(new DeletePath(path));
editor.finish();
}
builder.addParentId(indexCommit);
builder.setMessage(MessageFormat.format(
workingDirectoryMessage, branch,
headCommit.abbreviate(7).name(),
headCommit.getShortMessage()));
builder.setTreeId(cache.writeTree(inserter));
commitId = inserter.insert(builder);
inserter.flush();
updateStashRef(commitId, builder.getAuthor(),
builder.getMessage());
} finally {
inserter.release();
cache.unlock();
}