From 6283bad98ad5b5de92c1461d7e14733ab6137932 Mon Sep 17 00:00:00 2001 From: jochan Date: Tue, 20 Jun 2017 10:50:47 -0700 Subject: [PATCH] Added full workflow for migration. --- README.md | 27 +++++++++++++++++++++++++++ hg2git.sh | 2 ++ hg2git_clean.sh | 16 ++++------------ hg2git_ignore.sh | 32 ++++++++++++++++++++++++++++++++ hg2git_update.sh | 2 ++ 5 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 README.md create mode 100755 hg2git_ignore.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c899ed --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Mercurial to Git Migration + +## Notes +* If any .sh scripts cannot be executed, replace `./` with `bash ` or execute `chmod u+x <.sh script>`. +* The scripts require some of the following arguments: + * ``: The Mercurial repository that you are migrating **FROM**. + * ``: The Git repository that you are mirating **TO**. + * ``: The directory to which authors.py and users.csv will be copied. + * ``: The directory to which https://github.com/frej/fast-export will be cloned. All files in this directory will be overwritten. + * ``: The directory to which the BFG Repo-Cleaner .jar file will be downloaded. + +## Instructions +0. Copy all hg2git\*.sh, authors.py, and users.csv files to the same directory. +1. Run `./hg2git.sh `. This may take a while. Do **NOT** delete the reformatted-authors.txt file. +2. If you have new changes in your Mercurial repository and you wish to update your Git repository, ensure the changes have been pulled (`hg pull`) and run `./hg2git_update.sh `. +3. Before moving on, make sure that you are **absolutely sure** you no longer need to update your Git repository from your Mercurial repository. Once you perform the next steps, you **cannot** update again. +4. To strip out large files from history and delete closed branches, run `./hg2git_clean.sh `. Files larger than 40M will be stripped. This may take a while. +5. To copy .hgignore files to .gitignore, convert _some_ of the regex to globs, and commit these files for every branch, run `./hg2git_ignore.sh `. Note that this will convert the repository from bare to non-bare and check out files. +6. Set an upstream (`git remote add origin `) and push the repository (`git push -u origin master`). This may take a while. + +## TL;DR +1. `./hg2git.sh ` +2. `./hg2git_update.sh ` +3. Read [Instructions](#instructions) > Step 3. +4. `./hg2git_clean.sh ` +5. `./hg2git_ignore.sh ` +6. `git remote add origin && git push -u origin master` diff --git a/hg2git.sh b/hg2git.sh index db9f5fc..50a2637 100755 --- a/hg2git.sh +++ b/hg2git.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + unset source unset target unset authors diff --git a/hg2git_clean.sh b/hg2git_clean.sh index 3c21b11..596f287 100755 --- a/hg2git_clean.sh +++ b/hg2git_clean.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + unset source unset target unset bfg_cleaner @@ -28,15 +30,5 @@ cd $target comm -2 -3 all.log open.log > closed.log for branch in `cat closed.log`; do git tag "closed/$branch" $branch; git branch -df $branch; done -# TODO: Loop this for each open branch -echo "Creating .gitignore files from .hgignore files..." -find . -name ".hgignore" > hgignore-files.log -touch gitignore-files.log -for file in `cat hgignore-files.log`; do - newfile=${file/hgignore/gitignore}; - echo $newfile >> gitignore-files.log - cp $file $newfile; - sed -i.bak "s/syntax:/#syntax:/; s/^\^//; s/\$$//; s/\\\w\+/*/; s/\\\\\//\//g" $newfile; -done - -echo "All done! This Git repository is now ready to be pushed after the .gitignore files have been committed to the desired branches." +echo "All done! This Git repository is now ready to be pushed." +echo "If you'd like to create and commit some .gitignore files, run hg2git_ignore.sh." diff --git a/hg2git_ignore.sh b/hg2git_ignore.sh new file mode 100755 index 0000000..c19bfbd --- /dev/null +++ b/hg2git_ignore.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +unset $target +target=$1 + +if [[ -z $target ]]; then + echo "Please provide the path to the desired Git repository!" + exit 1 +fi + +echo "Creating and committing .gitignore files for each branch..." +cd $target +git config --bool core.bare false +for branch in `git branch | sed "s/*/ /g"`; do + git checkout $branch -f + find . -name ".hgignore" > hgignore-files.log + > gitignore-files.log + for file in `cat hgignore-files.log`; do + newfile=${file/hgignore/gitignore} + echo $newfile >> gitignore-files.log + cp $file $newfile + sed -i.bak "s/syntax:/#syntax:/; s/^\^//; s/\$$//; s/\\\w\+/*/; s/\\\\\//\//g" $newfile + done + cat gitignore-files.log | xargs git add + if [[ -s gitignore-files.log ]]; then + git commit -m "Added .gitignore files." + fi +done + +echo "All done! This Git repo is now ready to be pushed." diff --git a/hg2git_update.sh b/hg2git_update.sh index 9257acc..c7930d1 100755 --- a/hg2git_update.sh +++ b/hg2git_update.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + unset source unset target source=$1