-
-
Save Kurukshetran/0f6ceb11161c492aec7338aba746a790 to your computer and use it in GitHub Desktop.
This small bash script migrates all the given bitbucket mercurial repositories to git (the remote repositories are created automatically).
Prerequisites: hg, http://hg-git.github.io and curl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# General settings | |
username="bitbucket username" | |
password="bitbucket password" | |
tmp_local_repo_path=/tmp/bb_migration | |
# Define repository mappings: repos["hg_repo_name"]="new_git_repo_name" | |
declare -A repos | |
#repos["hg_repo_1"]="new_git_repo_1" | |
#repos["hg_repo_2"]="new_git_repo_2" | |
#repos["hg_repo_3"]="new_git_repo_3" | |
# ------------------------------------------------------------------------- | |
# Script | |
echo "Migrate hg repositories to git" | |
for repo in "${!repos[@]}" | |
do | |
hg_repo=$repo | |
git_repo=${repos[$repo]} | |
local_hg_repo_path=$tmp_local_repo_path/$hg_repo | |
echo "Migration of $hg_repo => $git_repo (using temporary path $local_hg_repo_path for pull/push)" | |
hg clone ssh://[email protected]/$username/$hg_repo $local_hg_repo_path && cd $local_hg_repo_path | |
hg bookmark -r default master | |
curl --user $username:$password https://api.bitbucket.org/1.0/repositories/ -k --data "name=$git_repo&is_private=true&scm=git" | |
hg push git+ssh://[email protected]:$username/$git_repo.git | |
rm -rf $local_hg_repo_path | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment