代码之家  ›  专栏  ›  技术社区  ›  Chris Giddings

从gitolite到bitbucket的脚本迁移

  •  2
  • Chris Giddings  · 技术社区  · 9 年前

    我正在尝试的是 previously managed 使用Bitbucket API的1.0版本。

    我需要从Gitolite迁移到Bitbucket,但Bitbudge API的2.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调用吗?那个电话会是什么样子?我在这里有点迷路。

    谢谢

    1 回复  |  直到 9 年前
        1
  •  2
  •   Chris Giddings    9 年前

    我要回答我自己的问题![上帝饶恕我]

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

    因此,Bitbucket创建了回购,其默认值为 而不是 吉特 这导致了我在尝试将镜像推到回购时看到的错误。

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

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