What I am attempting had been previously managed using the 1.0 version of the Bitbucket API.
I need to migrate from Gitolite to Bitbucket and am having issues with v2.0 of the Bitbucket API.
Here is my script code:
#!/bin/bash
# Usage: ./bitbucket-migrate.sh repos.txt
#
# repos.txt should have one repository per line.
echo "Reading $1"
while read line
do
repo=$line
echo "###"
echo "Cloning a bare copy of $repo"
git clone --bare git@git.company.com:$repo
echo "Waiting for clone completion"
sleep 45;
cd $repo.git
echo "Creating repo in Bitbucket"
curl -X POST -v -u username@company.com:password -H "Content-Type: application/json" \ https://api.bitbucket.org/2.0/repositories/teamname/$repo \ -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks"}'
echo "Pushing local mirror to bitbucket"
git push --mirror git@bitbucket.org:teamname/$repo.git
echo "Waiting for push completion"
sleep 45;
cd ..
echo "Removing $repo.git"
rm -rf "$repo.git"
echo "Waiting 10 seconds"
echo "###"
sleep 10;
done < $1
exit
At this time the script successfully creates an empty repo, but fails when attempting to push the mirror to BitBucket.
I threw in a couple extended sleeps in case copies were taking a while, but I don't believe they're having an effect in that way.
Here is the error received back:
$ git push --mirror git@bitbucket.org:teamname/$repo.git
conq: not a git repository.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Do I need to make the mirror push as a second API call? What would that call look like? I'm a little lost here.
Thanks!
I'm going to answer my own question! [lord forgive me]
The API request I made did create the repository, but the JSON breaks and it didn't read the parameters I passed in.
Due to this, Bitbucket created the repo with its default of hg instead of git which lead to the error I was seeing when attempting to push the mirror to the repo.
I ended up manually deleting the first repo created with the earlier request, and manually recreating it within the Bitbucket UI as a git repo which set my account default to git (since it automagically defaults to the last repo type used).
Once this was done I was able to push using --mirror to the repository just fine. Subsequent runs of the script worked for me since it creates the repo with the default (now set to git) and is able to push properly.