2016-02-05 47 views
2

我试图使用1.0版本的Bitbucket API的previously managed从gitolite到bitbucket的脚本迁移

我需要从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 [email protected]:$repo 

    echo "Waiting for clone completion" 
    sleep 45; 
    cd $repo.git 

    echo "Creating repo in Bitbucket" 
    curl -X POST -v -u [email protected]: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 [email protected]: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 

此时脚本成功创建一个空的回购协议,而是试图镜子推到位桶时失败。

为了避免副本花费一段时间,我投入了几次延长的睡眠,但我不相信它们会以这种方式产生效果。

这里是收到错误回:

$ git push --mirror [email protected]: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调用?那个电话会是什么样子?我有点迷失在这里。

谢谢!

回答

2

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

我做了没创建存储库的API请求,但是JSON休息,并没有看我传递的参数。

由于这个原因,到位桶创建回购其默认hg而不是git这导致了我在试图将镜像推向回购时看到的错误。

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

一旦完成这一步,我能够推 - 使用--mirror到存储库就好了。后续运行的脚本为我工作,因为它创建了默认(现在设置为git)的回购并能够正确推送。

+0

如果没有更好的答案,那么自学者就是这样。 [http://stackoverflow.com/help/badges/14/self-learner] –