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