The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to push to cloned empty repository using Java API (GitCommandBuilderFactory)

Severin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 16, 2020

I'm not able to push files using the Java API of bitbucket. The following code shows my attempt to add commits to a new and empty repository:

GitCommandBuilderFactory builderFactory; // imported with component-import

// create working directory (outside repository)
Path workTree = createWorkTree(repository);

// cloning repository to working directory
builderFactory.builder(repository)
.clone()
.normal()
.directory(workTree)
.origin(repository)
.build()
.call();

// create the file in the working directory
createFile(file, content);

// add the file
builderFactory.builder(repository)
.add()
.all(true)
.workDir(workTree)
.build()
.call();

// commit
builderFactory.builder(repository)
.commit()
.workDir(workTree)
.message(String.format("Added file %s", filename))
.author(Objects.requireNonNull(authenticationContext.getCurrentUser()))
.build()
.call();

// push - here is where the error occurs
builderFactory.builder(repository)
.push()
.workDir(workTree)
.build(new SingleLineOutputHandler())
.call();

After executing the above code snippet, I get the following error:

[INFO] com.atlassian.bitbucket.scm.CommandFailedException: 'C:\Program Files\Git\cmd\git.exe push' exited with code 1 saying: remote: hooks/pre-receive: line 9: /c/Users/$username/Code/$projectname/target/bitbucket/home/shared/data/repositories/14/hooks/pre-receive.d: Is a directory 
[INFO] remote: hooks/pre-receive: line 9: exec: /c/Users/$username/Code/$projectname/target/bitbucket/home/shared/data/repositories/14/hooks/pre-receive.d: cannot execute: Is a directory
[INFO] To C:\Users\$username\Code\$projectname\target\bitbucket\home\shared\data\repositories\14
[INFO] ! [remote rejected] master -> master (pre-receive hook declined)
[INFO] error: failed to push some refs to 'C:\Users\$username\Code\$projectname\target\bitbucket\home\shared\data\repositories\14'

I'm able to commit some files using the 'EditFileCommand,' but this does not fit my needs, as I need to modify some environment variables in the commit. Does anybody have an idea?

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events