2

我正在尝试的内容以前是使用 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 调用?那个电话会是什么样子?我在这里有点迷路了。

谢谢!

4

1 回答 1

2

我要回答我自己的问题![主原谅我]

我提出的 API 请求确实创建了存储库,但是 JSON 中断并且它没有读取我传入的参数。

因此,Bitbucket 使用默认的hg而不是git创建了 repo,这导致我在尝试将镜像推送到 repo 时看到的错误。

我最终手动删除了使用先前请求创建的第一个 repo,并在 Bitbucket UI 中手动将其重新创建为 git repo,它将我的帐户默认设置为 git(因为它自动默认为最后使用的 repo 类型)。

完成此操作后,我就可以使用 --mirror 推送到存储库了。该脚本的后续运行对我有用,因为它使用默认值(现在设置为 git)创建存储库并且能够正确推送。

于 2016-02-05T16:08:55.817 回答