Created
November 23, 2018 08:52
-
-
Save shawn0915/ebfa964a5121161118268c24823c7985 to your computer and use it in GitHub Desktop.
Convert Bazaar repository to Git repository
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 | |
set -e | |
if [ $# != 1 ]; then | |
echo "Usage: ./bzr-to-git.sh bzr_repo/" | |
exit -1 | |
fi | |
# 切换进 bzr 仓库 | |
cd "$1" | |
# 如果 Git 仓库已经存在则为了安全起见自动退出 | |
if [ -d ".git" ]; then | |
echo "There is already a Git Repository!" | |
echo "Please remove it manually for safety." | |
exit -1 | |
fi | |
# 初始化 Git 仓库 | |
git init -q | |
git commit --allow-empty -m "An Empty Commit" -q | |
# 添加 Git 仓库配置文件 | |
cat > .gitignore << EOL | |
.bzr/ | |
.bzrignore | |
EOL | |
git add .gitignore | |
git commit -m "Add .gitignore file" -q | |
echo "Git Repository is initialized successfully." | |
# 解析 bzr 仓库的提交历史 | |
commit_count=$(bzr log | grep -E "^revno:\s[0-9]{0,3}" -c) | |
echo "Commit Count: $commit_count" | |
# 开始迁移 | |
echo "Migration Started..." | |
for (( revno=1; revno<="$commit_count"; revno++ )) | |
do | |
sleep 1s | |
bzr_rev_msg=$(bzr log -r $revno | sed '1d') # 获取当前 revno 对应的提交信息 | |
bzr revert -r "$revno" -q # 将 bzr 工作目录切换到 revno 版本 | |
git add . # Git 添加工作区到 Index | |
git commit -m "$bzr_rev_msg" -q | |
echo "Commit revno=$revno successfully." | |
done | |
echo "Migration Finished Successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment