Skip to content

Instantly share code, notes, and snippets.

@sbruggmann
Created March 11, 2017 14:25
Show Gist options
  • Save sbruggmann/ee0858b0ec55832f85e54ea9da577320 to your computer and use it in GitHub Desktop.
Save sbruggmann/ee0858b0ec55832f85e54ea9da577320 to your computer and use it in GitHub Desktop.
Transfer mercurial repository to git including productive tags
#!/bin/bash
if [ -z "$1" ]; then
echo "please add a target repository"
exit
fi;
rm -rf .git
hg checkout tip --clean
git init
while read line; do
# echo $line
version=$(echo $line| cut -d' ' -f 2)
echo $version
hg checkout $version --clean
# change some content..
sed -ie 's/Old Name/New Name/g' composer.json
rm composer.jsone
# add license information..
cp ../LICENSE ./
info_text="> ##### Package-Information\n* * *\nMore text\n"
license_text="* * *\n> ##### License Terms\nMore text\n"
readme_file="README.md"
if grep -Fxq "$info_text" $readme_file; then
echo "ignore readme modification.."
else
echo "$info_text" | cat - "$readme_file" > /tmp/out && mv /tmp/out "$readme_file"
echo "$license_text" >> $readme_file
fi
git add --all
git reset -- .flow
git reset -- .hg
git reset -- .hgflow
git reset -- .hgignore
git reset -- .hgtags
git reset -- helper.sh
pub_date=$(hg log -f -l1 --template "{date|localdate|shortdate}\n")
git commit -am "imported $version from $pub_date"
git tag -a $version -m "$version tag"
done <.hgtags
# git remote add origin git@bitbucket.org:vendor/package.git
git remote add origin $1
git push origin master
git push --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment