I use documentation
to create my repo vi REST API 2.0.
Sent request and got new repo.
curl -X POST -H "Content-Type: application/json" -u 'user:password' -d '{"scm": "git", "project": {"key": "ABC"}, "fork_policy": "no_public_forks", "is_private": "true", "description": "blabla"}' https://api.bitbucket.org/2.0/repositories/teamname/reponame
But "mainbranch": null in this case. It need it to be "master" by default.
I also sent request, where I specified mainbranch, but still got "mainbranch": null in result.
curl -X POST -H "Content-Type: application/json" -u 'user:password' -d '{"scm": "git", "project": {"key": "ABC"}, "fork_policy": "no_public_forks", "is_private": "true", "mainbranch": {"type": "branch", "name": "master"}, "description": "blabla"}' https://api.bitbucket.org/2.0/repositories/teamname/reponame
What am I doing wrong? How can I specify main branch while creating repo?
I connect to the question, I need to periodically create new branches and change mainbranch
but I can not appoint mainbranch
this action is not mentioned in the documentation
SOLVED: Push the branch name you want to be default branch FIRST.
In my case (for scripting out creation of a gitflow repository), I init a local repo, programmatically and add initial files (.gitignore, .gitattributes, etc).
I then add the remote & push to develop first (git push origin master:develop).
THEN I push to master (git push -u origin master).
The develop branch becomes the default branch in this case because it was pushed first :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alright, I was approaching this the wrong way. The CORRECT process for me to follow was to take my 'master' repo that had the code that I wanted to duplicate, and simply fork it using the API. I used the following API page as a guide:
Forking a repo copies over all the attributes of the original, although you can override most attributes (including mainbranch) in the api call. The basic api call that I used was:
checkRepo() {
echo "Checking to see if ${WEB_NAME} exists on cloud......"
RESPONSE=$( curl -sS --user ${BIT_USER}:${BIT_PASS} https://api.bitbucket.org/2.0/repositories/${BIT_REPO}/${WEB_NAME} )
if [[ ${RESPONSE} == *'not found'* ]]; then
echo "No main-branch was found on BitBucket for repository ${WEB_NAME}. Creating Repo......"
if ( curl -X POST -u ${BIT_USER}:${BIT_PASS} "https://api.bitbucket.org/2.0/repositories/${BIT_REPO}/master/forks" -H 'Content-Type: application/json' -d '{"name"
: "'"${WEB_NAME}"'", "owner": {"username": "'"${BIT_REPO}"'"} }' >/dev/null 2>&1) ; then
echo "Repo ${WEB_NAME} forked on cloud."
else
echo "Repo ${WEB_NAME} failed to fork on cloud."
fi
else
echo "The repository, ${WEB_NAME}, exists on the cloud."
fi
echo ''
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I'm creating and managing repositories using API, I want to set the default branch to `develop`, I've tried with:
curl -X PUT \
'https://api.bitbucket.org/2.0/{username}/{repo_slug}' \
-H 'Authorization: Bearer mytoken' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"mainbranch": {
"type": "branch",
"name": "develop"
}
}'
With no luck.
There is no a way to set the main branch using API 2.0?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Has anyone found a solution to this? I am trying to use the clues at https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/properties/%7Bapp_key%7D/%7Bproperty_name%7D, but I keep getting "Resource not found" errors.
Part of it is that I am unsure what the app key is. I create a new empty repo with the api, then mirror-push an existing repo into it. I then try to correctly fix the mainbranch.
Is curl -X PUT -u ${BIT_USER}:${BIT_PASS} "https://api.bitbucket.org/2.0/repositories/{username}/{repo_slug}/properties/{app_key}/{property_name} not the solution?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've been battling with this as well, either a way to set main branch when creating it or changing it after creation would be fine by me. Haven't found a way yet...
Replying to this post to get it back in the list again, hoping for an answer. (while I dive into it myself)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.