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

1 vote

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Confluence

Color tables for a shiny Confluence page

...; ## Developed by: Alana Fernando ## Shared with love ## @param style:title=style type|type=enum|required=true|desc=Choose a style.|enumValues=Style1,Style2,Style3,Style4,Style5 ## @param alignment:title...

144 views 8 11
Read article

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