blob: 464e20b42966f42cf3071938a67fda46bad4bc83 [file] [log] [blame]
[email protected]3bb0d6f2010-11-15 17:01:521#!/usr/bin/env -S bash -e
[email protected]5ef7f342009-09-01 00:39:002#
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
12GITSERVER="${GITSERVER:-git.chromium.org}"
[email protected]e8c918d2009-10-20 19:47:5913SVNSERVER="${SVNSERVER:-svn://svn.chromium.org/chrome}"
[email protected]5ef7f342009-09-01 00:39:0014TMP=".create_chromium_git_src.$$"
15
16function cleanup {
17 rm -rf "${TMP}"
18}
19
20trap 'cleanup; echo Failure!; tput bel; exit 1' TERM QUIT HUP INT EXIT
21
22function 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.
39function 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.
47function test_git {
48 echo -n "Trying git... "
[email protected]e8c918d2009-10-20 19:47:5949 local GITV="$(git --version)" || {
[email protected]5ef7f342009-09-01 00:39:0050 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]5ef7f342009-09-01 00:39:0057 echo "git version is ${GITV}, please update to a version later than 1.6"
58 exit 1
59 fi
[email protected]e8c918d2009-10-20 19:47:5960 echo "found git version ${GITV}"
[email protected]5ef7f342009-09-01 00:39:0061}
62
63# Test git svn and git svn --version.
64function 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]e8c918d2009-10-20 19:47:5968 local GITV="$(cd "${TMP}" && git svn --version)" || {
[email protected]5ef7f342009-09-01 00:39:0069 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]5ef7f342009-09-01 00:39:0077 echo "git version is ${GITV}, please update to a version later than 1.6"
78 exit 1
79 fi
[email protected]e8c918d2009-10-20 19:47:5980 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]5ef7f342009-09-01 00:39:0092}
93
94# Verify we can reach our main git URL.
95function 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]e8c918d2009-10-20 19:47:59103 local pid="$!"
[email protected]5ef7f342009-09-01 00:39:00104 { sleep 10 && kill "${pid}"; } &>/dev/null &
105 wait "${pid}" &>/dev/null || {
[email protected]e8c918d2009-10-20 19:47:59106 echo "timeout accessing Chromium git URL, is ${GITSERVER} correct?"
[email protected]5ef7f342009-09-01 00:39:00107 exit 1
108 }
109 echo OK
110}
111
112# Grab a clone of the Chromium git repository.
[email protected]e8c918d2009-10-20 19:47:59113function cr_git_clone {
[email protected]5ef7f342009-09-01 00:39:00114 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]e8c918d2009-10-20 19:47:59123function 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]5ef7f342009-09-01 00:39:00127 echo "'git svn init' exited with error"
128 exit 1
129 }
[email protected]5ef7f342009-09-01 00:39:00130}
131
132# Initialize the SVN history in the repository, also sanity checks our upstream
133# SVN configuration.
[email protected]e8c918d2009-10-20 19:47:59134function cr_git_svn_fetch {
[email protected]5ef7f342009-09-01 00:39:00135 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
147function 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]e8c918d2009-10-20 19:47:59152 echo -n "Configuring email address... "
[email protected]5ef7f342009-09-01 00:39:00153 (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
165get_email
166check_dirs
167test_git
168test_git_svn
169test_git_url
[email protected]e8c918d2009-10-20 19:47:59170cr_git_clone
171cr_git_svn_init
172cr_git_svn_fetch
[email protected]5ef7f342009-09-01 00:39:00173git_config
174
175echo
176echo "A Chromium Git repository was created in 'src'."
177echo
178echo " To create a CL..."
179echo " Update: git pull && gclient sync"
180echo " Create and use a branch mychange: git checkout -q -b mychange origin"
181echo " Edit files and commit: git commit -a -v"
182echo " Upload CL: git cl upload"
183echo " Try a change: git try origin"
184echo " Commit a CL: git cl dcommit"
185echo " Switch to the trunk: git checkout trunk"
186echo " Delete a branch mychange: git branch -d mychange"
187echo
188echo " If while on a branch you need to switch back to the trunk..."
189echo " Switch to the trunk: git checkout trunk"
190echo " List all branches: git branch"
191echo " Switch to branch mychange: git checkout mychange"
192echo
193echo " Examining files and changes..."
194echo " Log with patches: git log -p"
195echo " Changes to DEPS: git log -p DEPS"
196echo " View latest commit: git cat-file commit HEAD"
197echo
198echo "You should run: gclient sync"
199echo
200trap cleanup EXIT