create commit from plugin

DavLes April 10, 2017

How can one create a commit from within a plugin?

We would like to add an empty commit immediately after creating a branch. Branches are only created through the BitBucket GUI.

An event listener is in place, and the necessary components are succesfully autowired. But the creation of the commit fails with "Caused by: com.atlassian.bitbucket.scm.CommandFailedException: '/usr/bin/git commit -m ebo-bitbuckit-commit --' exited with code 128 saying: fatal: This operation must be run in a work tree"

 

What are we missing? Or should we try a different route?

 

Code:

@EventListener
public void onRefsChanged(AbstractRepositoryRefsChangedEvent event) {
Repository repo = event.getRepository();
File repoDir = gitScmConfig.getRepositoryDir(repo);

final GitCommitBuilder builder = builderFactory.builder(repo).commit() // create a commit builder
.workingDirectory(repoDir) // run on the correct path
.author(event.getUser()).committer(event.getUser()).message("ebo-bitbuckit-commit");
final String sha = builder.build(new SomeOutputHandler()).call();

 

1 answer

1 vote
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 1, 2017

Hi David! For this kind of questions, my recommendation would be to post it at community.developer.atlassian.com, that's where our developer community hangs out :)

Regards,

Ana

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events