Skip to content

Instantly share code, notes, and snippets.

@matiasgarciaisaia
Created October 9, 2013 15:49
Show Gist options
  • Select an option

  • Save matiasgarciaisaia/6903416 to your computer and use it in GitHub Desktop.

Select an option

Save matiasgarciaisaia/6903416 to your computer and use it in GitHub Desktop.

Revisions

  1. matiasgarciaisaia created this gist Oct 9, 2013.
    27 changes: 27 additions & 0 deletions hg-to-git.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/bin/bash
    function abort() {
    echo "ERROR: $1"
    echo ""
    echo "USAGE: $0 /path/to/hg/repo /path/to/new/repo"
    exit 1
    }

    [ $# -eq 2 ] || abort "Invalid parameters count"
    [ -d $1 ] || abort "$1 should be an existing hg repository"
    [ -d $1/.hg ] || abort "$1 should be an existing hg repository ($1/.hg must be a directory)"
    [ -d $2 ] && abort "$2 should not exist"

    SOURCE=$(cd "$1" && pwd)
    mkdir -p "$2" && cd "$2"
    TARGET=$(pwd)
    git clone git://repo.or.cz/fast-export.git "$TARGET"
    rm -rf .git .gitignore
    git init
    ./hg-fast-export.sh -r "$SOURCE"

    for branch in $(cd "$SOURCE" && hg branches --closed | grep \(closed\) | cut -f1 -d' ')
    do
    git checkout "$branch" && git tag "$branch" && git checkout master && git branch -D "$branch"
    done

    git reset . && git checkout . && git clean -f