代码之家  ›  专栏  ›  技术社区  ›  agiliq

Git桥到Mercurial

  •  4
  • agiliq  · 技术社区  · 16 年前

    Github在另一个方向上创建了一个项目(用于HG-repos-to-git),但是有没有一个适合我所寻找的方向。

    2 回复  |  直到 16 年前
        1
  •  4
  •   tghw megawac    16 年前

    如果您只是在镜像Git repo,那么可以设置cron作业来运行以下脚本:

    #!/bin/bash
    
    USER=bitbucketuser
    ERROR_FILE=clone_update_err
    CLONES=/path/to/clones
    
    cd $CLONES
    
    if [ $# -ne 1 ]; then
        for DIR in *; do
            if [ -d $DIR ]; then
                ./update.sh $DIR 2> $ERROR_FILE
                if [ -s $ERROR_FILE ]; then
                    echo $DIR >&2
                    cat -n $ERROR_FILE >&2
                fi
            fi
        done
    else
        DIR=$1
        echo $DIR
        cd $DIR
    
        if [ -a source ]; then
            cd source
            if [ -d .hg ]; then
                hg pull
            elif [ -d .git ]; then
                git pull
            elif [ -d .bzr ]; then
                bzr pull
            elif [ -d .svn ]; then
                svn up
            else
                echo "$DIR is not a known repository type."
                return 1
            fi
    
            cd ..
            hg convert source hg
    
            URL=ssh://hg@bitbucket.org/$USER/$DIR/
            cd hg
            hg pull $URL
            hg push $URL # You can add -f here if you don't mind multiple heads
            cd ..
        else
            # hg dir or hg-git
            cd hg
            hg pull
            hg push $URL
            cd ..
        fi
    
        cd ..
    
        sleep 5
    fi
    

    这假设您安装了SSH密钥。如您所见,它也将镜像其他VCS。它采用如下目录结构:

    clones/
      project1/
        source/  # Original Git/Bazaar/SVN/Mercurial repo
        hg/      # Mercurial repo
    

    显然,这只是单向的,但是如果您在Git中完成所有的工作,那么这就不重要了。

        2
  •  7
  •   tghw megawac    16 年前

    我本来想把这个加在我的另一个答案上的,但是有点长,所以我们将把它作为一个单独的答案来做。

    hg-git 得到一个 hg 您机器上的回购版本。您仍然可以在Git中完成所有工作,这意味着您将使用GitHub作为中介。

    $ cd src
    # do some work
    # push to GitHub
    $ cd ../hg
    $ hg pull
    $ hg push bitbucket
    

    但是,它的好处是,如果您想从Mercurial用户那里获取更改,您可以将它们拉入 汞

    $ cd hg
    $ hg pull someotherrepo
      # Probably merge
    $ hg push # Changes go to GitHub
    $ cd ../src
    $ git pull
      # Continue working in Git
    
    推荐文章