我正在尝试的内容以前是使用 1.0 版本的 Bitbucket API 进行管理的。
我需要从 Gitolite 迁移到 Bitbucket,并且遇到了 Bitbucket API v2.0 的问题。
这是我的脚本代码:
#!/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
此时脚本成功创建了一个空仓库,但在尝试将镜像推送到 BitBucket 时失败。
我延长了几次睡眠以防复制需要一段时间,但我不相信它们会以这种方式产生影响。
这是收到的错误:
$ 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.
我是否需要将镜像推送作为第二个 API 调用?那个电话会是什么样子?我在这里有点迷路了。
谢谢!