[email protected] | 3bb0d6f | 2010-11-15 17:01:52 | [diff] [blame] | 1 | #!/usr/bin/env -S bash -e |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | # |
| 7 | # create-chromium-git-src |
| 8 | # |
| 9 | # Create and configure a local Chromium git repository. |
| 10 | # |
| 11 | |
| 12 | GITSERVER="${GITSERVER:-git.chromium.org}" |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 13 | SVNSERVER="${SVNSERVER:-svn://svn.chromium.org/chrome}" |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 14 | TMP=".create_chromium_git_src.$$" |
| 15 | |
| 16 | function cleanup { |
| 17 | rm -rf "${TMP}" |
| 18 | } |
| 19 | |
| 20 | trap 'cleanup; echo Failure!; tput bel; exit 1' TERM QUIT HUP INT EXIT |
| 21 | |
| 22 | function get_email { |
| 23 | # Get user email address. |
| 24 | EMAIL="" |
| 25 | while [ "x${EMAIL}" = "x" ]; do |
| 26 | echo -n "Email address git should configure in your checkout: " |
| 27 | read EMAIL |
| 28 | if [ "x${EMAIL}" = "x${EMAIL%@*}" ]; then |
| 29 | echo "Invalid email address (must contain @)!" |
| 30 | EMAIL="" |
| 31 | fi |
| 32 | done |
| 33 | echo -n "Using ${EMAIL} for email address... " |
| 34 | sleep 1 |
| 35 | echo OK |
| 36 | } |
| 37 | |
| 38 | # Verify we can write to particular directories. |
| 39 | function check_dirs { |
| 40 | if [ -d src ]; then |
| 41 | echo "Found a src directory, do you already have a Chromium checkout?" |
| 42 | exit 1 |
| 43 | fi |
| 44 | } |
| 45 | |
| 46 | # Test git and git --version. |
| 47 | function test_git { |
| 48 | echo -n "Trying git... " |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 49 | local GITV="$(git --version)" || { |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 50 | echo "git isn't installed, please install it" |
| 51 | exit 1 |
| 52 | } |
| 53 | |
| 54 | GITV="${GITV##* }" # Only examine last word (i.e. version number) |
| 55 | local GITD=( ${GITV//./ } ) # Split version number into decimals |
| 56 | if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 57 | echo "git version is ${GITV}, please update to a version later than 1.6" |
| 58 | exit 1 |
| 59 | fi |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 60 | echo "found git version ${GITV}" |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | # Test git svn and git svn --version. |
| 64 | function test_git_svn { |
| 65 | echo -n "Trying git-svn... " |
| 66 | rm -rf "${TMP}" |
| 67 | git clone git://github.com/git/hello-world.git "${TMP}" &>/dev/null && |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 68 | local GITV="$(cd "${TMP}" && git svn --version)" || { |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 69 | echo "git-svn isn't installed, please install it" |
| 70 | exit 1 |
| 71 | } |
| 72 | |
| 73 | GITV="${GITV#* version }" # git svn --version has extra output to remove. |
| 74 | GITV="${GITV% (svn*}" |
| 75 | local GITD=( ${GITV//./ } ) # Split version number into decimals |
| 76 | if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 77 | echo "git version is ${GITV}, please update to a version later than 1.6" |
| 78 | exit 1 |
| 79 | fi |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 80 | echo "found git-svn version ${GITV}" |
| 81 | |
| 82 | echo "Testing git svn init..." |
| 83 | (cd "${TMP}" && git svn init --username="${EMAIL}" --prefix=origin/ \ |
| 84 | -T trunk/src "${SVNSERVER}") & |
| 85 | local pid="$!" |
| 86 | { sleep 10 && kill "${pid}"; } &>/dev/null & |
| 87 | wait "${pid}" &>/dev/null || { |
| 88 | echo "Could not initialize repository, is SVN server ${SVNSERVER} correct?" |
| 89 | echo "The supplied username and password may be incorrect." |
| 90 | exit 1 |
| 91 | } |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | # Verify we can reach our main git URL. |
| 95 | function test_git_url { |
| 96 | echo -n "Testing Chromium git URL... " |
| 97 | mkdir -p "${TMP}" |
| 98 | (cd "${TMP}" && |
| 99 | rm -rf .git .gitignore && |
| 100 | git init && |
| 101 | git remote add origin git://"${GITSERVER}"/chromium.git && |
| 102 | git remote show origin) &>/dev/null & |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 103 | local pid="$!" |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 104 | { sleep 10 && kill "${pid}"; } &>/dev/null & |
| 105 | wait "${pid}" &>/dev/null || { |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 106 | echo "timeout accessing Chromium git URL, is ${GITSERVER} correct?" |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 107 | exit 1 |
| 108 | } |
| 109 | echo OK |
| 110 | } |
| 111 | |
| 112 | # Grab a clone of the Chromium git repository. |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 113 | function cr_git_clone { |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 114 | echo "Grabbing Chromium git repository..." |
| 115 | git clone git://"${GITSERVER}"/chromium.git src || { |
| 116 | echo "git clone exited with error" |
| 117 | echo "You should probably remove 'src' before retrying" |
| 118 | exit 1 |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | # Configure the git repository to know about the upstream SVN server. |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 123 | function cr_git_svn_init { |
| 124 | echo "Configuring upstream SVN..." |
| 125 | (cd src && git svn init --username="${EMAIL}" --prefix=origin/ -T trunk/src \ |
| 126 | "${SVNSERVER}") || { |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 127 | echo "'git svn init' exited with error" |
| 128 | exit 1 |
| 129 | } |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | # Initialize the SVN history in the repository, also sanity checks our upstream |
| 133 | # SVN configuration. |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 134 | function cr_git_svn_fetch { |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 135 | echo "Fetching SVN history..." |
| 136 | (cd src && git svn fetch && git pull) || { |
| 137 | echo "'git svn fetch' exited with error" |
| 138 | exit 1 |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | # Remaining configuration of the git repository: |
| 143 | # - associate with codereview/rietveld |
| 144 | # - set the repository's email address |
| 145 | # - disable crlf munging |
| 146 | # - grab a stock .gclient file |
| 147 | function git_config { |
| 148 | echo -n "Associating with Rietveld... " |
| 149 | (cd src && git cl config http://src.chromium.org/svn/) |
| 150 | echo OK |
| 151 | |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 152 | echo -n "Configuring email address... " |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 153 | (cd src && git config user.email "${EMAIL}") |
| 154 | echo OK |
| 155 | |
| 156 | echo -n "Disabling crlf munging... " |
| 157 | (cd src && git config --global core.autocrlf false) |
| 158 | echo OK |
| 159 | |
| 160 | echo -n "Creating a .gclient file... " |
| 161 | gclient config http://src.chromium.org/svn/trunk/src |
| 162 | echo OK |
| 163 | } |
| 164 | |
| 165 | get_email |
| 166 | check_dirs |
| 167 | test_git |
| 168 | test_git_svn |
| 169 | test_git_url |
[email protected] | e8c918d | 2009-10-20 19:47:59 | [diff] [blame] | 170 | cr_git_clone |
| 171 | cr_git_svn_init |
| 172 | cr_git_svn_fetch |
[email protected] | 5ef7f34 | 2009-09-01 00:39:00 | [diff] [blame] | 173 | git_config |
| 174 | |
| 175 | echo |
| 176 | echo "A Chromium Git repository was created in 'src'." |
| 177 | echo |
| 178 | echo " To create a CL..." |
| 179 | echo " Update: git pull && gclient sync" |
| 180 | echo " Create and use a branch mychange: git checkout -q -b mychange origin" |
| 181 | echo " Edit files and commit: git commit -a -v" |
| 182 | echo " Upload CL: git cl upload" |
| 183 | echo " Try a change: git try origin" |
| 184 | echo " Commit a CL: git cl dcommit" |
| 185 | echo " Switch to the trunk: git checkout trunk" |
| 186 | echo " Delete a branch mychange: git branch -d mychange" |
| 187 | echo |
| 188 | echo " If while on a branch you need to switch back to the trunk..." |
| 189 | echo " Switch to the trunk: git checkout trunk" |
| 190 | echo " List all branches: git branch" |
| 191 | echo " Switch to branch mychange: git checkout mychange" |
| 192 | echo |
| 193 | echo " Examining files and changes..." |
| 194 | echo " Log with patches: git log -p" |
| 195 | echo " Changes to DEPS: git log -p DEPS" |
| 196 | echo " View latest commit: git cat-file commit HEAD" |
| 197 | echo |
| 198 | echo "You should run: gclient sync" |
| 199 | echo |
| 200 | trap cleanup EXIT |