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