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?