Java Code Examples for org.eclipse.jgit.api.CommitCommand#setAuthor()

The following examples show how to use org.eclipse.jgit.api.CommitCommand#setAuthor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractGitTest.java    From onedev with MIT License 5 votes vote down vote up
protected String commit(String comment) {
	CommitCommand ci = git.commit();
	ci.setMessage(comment);
	ci.setAuthor(user);
	ci.setCommitter(user);
	try {
		return ci.call().name();
	} catch (GitAPIException e) {
		throw new RuntimeException(e);
	}
}
 
Example 2
Source File: GitContentRepositoryHelper.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
private void makeRepoOrphan(Repository repository, String site) throws IOException, GitAPIException,
        ServiceLayerException, UserNotFoundException {
    logger.debug("Make repository orphan fir site " + site);
    String sandboxBranchName = repository.getBranch();
    if (StringUtils.isEmpty(sandboxBranchName)) {
        sandboxBranchName = studioConfiguration.getProperty(REPO_SANDBOX_BRANCH);
    }
    String sandboxBranchOrphanName = sandboxBranchName + "_orphan";

    logger.debug("Shallow clone is not implemented in JGit. Instead we are creating new orphan branch after " +
            "cloning and renaming it to sandbox branch to replace fully cloned branch");
    try (Git git = new Git(repository)) {
        logger.debug("Create temporary orphan branch " + sandboxBranchOrphanName);
        git.checkout()
                .setName(sandboxBranchOrphanName)
                .setStartPoint(sandboxBranchName)
                .setOrphan(true)
                .call();

        // Reset everything to simulate first commit as created empty repo
        logger.debug("Soft reset to commit empty repo");
        git.reset().call();

        logger.debug("Commit empty repo, because we need to have HEAD to delete old and rename new branch");
        CommitCommand commitCommand = git.commit()
                .setMessage(getCommitMessage(REPO_CREATE_AS_ORPHAN_COMMIT_MESSAGE));
        String username = securityService.getCurrentUser();
        if (StringUtils.isNotEmpty(username)) {
            commitCommand = commitCommand.setAuthor(getAuthorIdent(username));
        }
        commitCommand.call();

        logger.debug("Delete cloned branch " + sandboxBranchName);
        git.branchDelete().setBranchNames(sandboxBranchName).setForce(true).call();

        logger.debug("Rename temporary orphan branch to sandbox branch");
        git.branchRename().setNewName(sandboxBranchName).setOldName(sandboxBranchOrphanName).call();
    }
}