create commit from plugin

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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 10, 2018 in Bitbucket

What is your #1 piece of advice to new users getting started using Bitbucket?

Hello Community! My name is Claire Maynard, and I’m a Product Marketing Manager on the Bitbucket team. I’m interested in hearing what advice or tips you have for new users getting started on ...

245 views 14 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you