Tom Stellard | d789989 | 2018-06-13 05:14:10 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #===-- merge-git.sh - Merge commit to the stable branch --------------------===# |
| 3 | # |
| 4 | # The LLVM Compiler Infrastructure |
| 5 | # |
| 6 | # This file is distributed under the University of Illinois Open Source |
| 7 | # License. |
| 8 | # |
| 9 | #===------------------------------------------------------------------------===# |
| 10 | # |
| 11 | # This script will merge an svn revision to a git repo using git-svn while |
| 12 | # preserving the svn commit message. |
| 13 | # |
| 14 | # NOTE: This script has only been tested with the per-project git repositories |
| 15 | # and not with the monorepo. |
| 16 | # |
| 17 | # In order to use this script, you must: |
| 18 | # 1) Checkout the stable branch you would like to merge the revision into. |
| 19 | # 2) Correctly configure the branch as an svn-remote by adding the following to |
| 20 | # your .git/config file for your git repo (replace xy with the major/minor |
| 21 | # version of the release branch. e.g. release_50 or release_60): |
| 22 | # |
| 23 | #[svn-remote "release_xy"] |
| 24 | #url = https://llvm.org/svn/llvm-project/llvm/branches/release_xy |
| 25 | #fetch = :refs/remotes/origin/release_xy |
| 26 | # |
| 27 | # Once the script completes successfully, you can push your changes with |
| 28 | # git-svn dcommit |
| 29 | # |
| 30 | #===------------------------------------------------------------------------===# |
| 31 | |
| 32 | |
| 33 | usage() { |
| 34 | echo "usage: `basename $0` [OPTIONS]" |
| 35 | echo " -rev NUM The revision to merge into the project" |
| 36 | } |
| 37 | |
| 38 | while [ $# -gt 0 ]; do |
| 39 | case $1 in |
| 40 | -rev | --rev | -r ) |
| 41 | shift |
| 42 | rev=$1 |
| 43 | ;; |
| 44 | -h | -help | --help ) |
| 45 | usage |
| 46 | ;; |
| 47 | * ) |
| 48 | echo "unknown option: $1" |
| 49 | echo "" |
| 50 | usage |
| 51 | exit 1 |
| 52 | ;; |
| 53 | esac |
| 54 | shift |
| 55 | done |
| 56 | |
| 57 | if [ -z "$rev" ]; then |
| 58 | echo "error: need to specify a revision" |
| 59 | echo |
| 60 | usage |
| 61 | exit 1 |
| 62 | fi |
| 63 | |
| 64 | # Rebuild revision map |
| 65 | git svn find-rev r$rev origin/master &>/dev/null |
| 66 | |
| 67 | git_hash=`git svn find-rev r$rev origin/master` |
| 68 | |
| 69 | if [ -z "$git_hash" ]; then |
| 70 | echo "error: could not determine git commit for r$rev" |
| 71 | exit 1 |
| 72 | fi |
| 73 | |
| 74 | commit_msg=`svn log -r $rev https://llvm.org/svn/llvm-project/` |
| 75 | ammend="--amend" |
| 76 | |
| 77 | git cherry-pick $git_hash |
| 78 | if [ $? -ne 0 ]; then |
| 79 | echo "" |
| 80 | echo "** cherry-pick failed enter 'e' to exit or 'c' when you have finished resolving the conflicts:" |
| 81 | read option |
| 82 | case $option in |
| 83 | c) |
| 84 | ammend="" |
| 85 | ;; |
| 86 | *) |
| 87 | exit 1 |
| 88 | ;; |
| 89 | esac |
| 90 | fi |
| 91 | |
| 92 | git commit $ammend -m "Merging r$rev:" -m "$commit_msg" |