create-chromium-git-src 5.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/bash -e
#
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# create-chromium-git-src
#
# Create and configure a local Chromium git repository.
#

GITSERVER="${GITSERVER:-git.chromium.org}"
13
SVNSERVER="${SVNSERVER:-svn://svn.chromium.org/chrome}"
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
TMP=".create_chromium_git_src.$$"

function cleanup {
  rm -rf "${TMP}"
}

trap 'cleanup; echo Failure!; tput bel; exit 1' TERM QUIT HUP INT EXIT

function get_email {
  # Get user email address.
  EMAIL=""
  while [ "x${EMAIL}" = "x" ]; do
    echo -n "Email address git should configure in your checkout: "
    read EMAIL
    if [ "x${EMAIL}" = "x${EMAIL%@*}" ]; then
      echo "Invalid email address (must contain @)!"
      EMAIL=""
    fi
  done
  echo -n "Using ${EMAIL} for email address... "
  sleep 1
  echo OK
}

# Verify we can write to particular directories.
function check_dirs {
  if [ -d src ]; then
    echo "Found a src directory, do you already have a Chromium checkout?"
    exit 1
  fi
}

# Test git and git --version.
function test_git {
  echo -n "Trying git... "
49
  local GITV="$(git --version)" || {
50 51 52 53 54 55 56 57 58 59
    echo "git isn't installed, please install it"
    exit 1
  }

  GITV="${GITV##* }"          # Only examine last word (i.e. version number)
  local GITD=( ${GITV//./ } ) # Split version number into decimals
  if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then
    echo "git version is ${GITV}, please update to a version later than 1.6"
    exit 1
  fi
60
  echo "found git version ${GITV}"
61 62 63 64 65 66 67
}

# Test git svn and git svn --version.
function test_git_svn {
  echo -n "Trying git-svn... "
  rm -rf "${TMP}"
  git clone git://github.com/git/hello-world.git "${TMP}" &>/dev/null &&
68
  local GITV="$(cd "${TMP}" && git svn --version)" || {
69 70 71 72 73 74 75 76 77 78 79
    echo "git-svn isn't installed, please install it"
    exit 1
  }

  GITV="${GITV#* version }"   # git svn --version has extra output to remove.
  GITV="${GITV% (svn*}"
  local GITD=( ${GITV//./ } ) # Split version number into decimals
  if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then
    echo "git version is ${GITV}, please update to a version later than 1.6"
    exit 1
  fi
80 81 82 83 84 85 86 87 88 89 90 91
  echo "found git-svn version ${GITV}"

  echo "Testing git svn init..."
  (cd "${TMP}" && git svn init --username="${EMAIL}" --prefix=origin/ \
    -T trunk/src "${SVNSERVER}") &
  local pid="$!"
  { sleep 10 && kill "${pid}"; } &>/dev/null &
  wait "${pid}" &>/dev/null || {
    echo "Could not initialize repository, is SVN server ${SVNSERVER} correct?"
    echo "The supplied username and password may be incorrect."
    exit 1
  }
92 93 94 95 96 97 98 99 100 101 102
}

# Verify we can reach our main git URL.
function test_git_url {
  echo -n "Testing Chromium git URL... "
  mkdir -p "${TMP}"
  (cd "${TMP}" &&
   rm -rf .git .gitignore &&
   git init &&
   git remote add origin git://"${GITSERVER}"/chromium.git &&
   git remote show origin) &>/dev/null &
103
  local pid="$!"
104 105
  { sleep 10 && kill "${pid}"; } &>/dev/null &
  wait "${pid}" &>/dev/null || {
106
    echo "timeout accessing Chromium git URL, is ${GITSERVER} correct?"
107 108 109 110 111 112
    exit 1
  }
  echo OK
}

# Grab a clone of the Chromium git repository.
113
function cr_git_clone {
114 115 116 117 118 119 120 121 122
  echo "Grabbing Chromium git repository..."
  git clone git://"${GITSERVER}"/chromium.git src || {
    echo "git clone exited with error"
    echo "You should probably remove 'src' before retrying"
    exit 1
  }
}

# Configure the git repository to know about the upstream SVN server.
123 124 125 126
function cr_git_svn_init {
  echo "Configuring upstream SVN..."
  (cd src && git svn init --username="${EMAIL}" --prefix=origin/ -T trunk/src \
   "${SVNSERVER}") || {
127 128 129 130 131 132 133
    echo "'git svn init' exited with error"
    exit 1
  }
}

# Initialize the SVN history in the repository, also sanity checks our upstream
# SVN configuration.
134
function cr_git_svn_fetch {
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  echo "Fetching SVN history..."
  (cd src && git svn fetch && git pull) || {
    echo "'git svn fetch' exited with error"
    exit 1
  }
}

# Remaining configuration of the git repository:
# - associate with codereview/rietveld
# - set the repository's email address
# - disable crlf munging
# - grab a stock .gclient file
function git_config {
  echo -n "Associating with Rietveld... "
  (cd src && git cl config http://src.chromium.org/svn/)
  echo OK

152
  echo -n "Configuring email address... "
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
  (cd src && git config user.email "${EMAIL}")
  echo OK

  echo -n "Disabling crlf munging... "
  (cd src && git config --global core.autocrlf false)
  echo OK

  echo -n "Creating a .gclient file... "
  gclient config http://src.chromium.org/svn/trunk/src
  echo OK
}

get_email
check_dirs
test_git
test_git_svn
test_git_url
170 171 172
cr_git_clone
cr_git_svn_init
cr_git_svn_fetch
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
git_config

echo
echo "A Chromium Git repository was created in 'src'."
echo
echo "  To create a CL..."
echo "    Update: git pull && gclient sync"
echo "    Create and use a branch mychange: git checkout -q -b mychange origin"
echo "    Edit files and commit: git commit -a -v"
echo "    Upload CL: git cl upload"
echo "    Try a change: git try origin"
echo "    Commit a CL: git cl dcommit"
echo "    Switch to the trunk: git checkout trunk"
echo "    Delete a branch mychange: git branch -d mychange"
echo
echo "  If while on a branch you need to switch back to the trunk..."
echo "    Switch to the trunk: git checkout trunk"
echo "    List all branches: git branch"
echo "    Switch to branch mychange: git checkout mychange"
echo
echo "  Examining files and changes..."
echo "    Log with patches: git log -p"
echo "    Changes to DEPS: git log -p DEPS"
echo "    View latest commit: git cat-file commit HEAD"
echo
echo "You should run: gclient sync"
echo
trap cleanup EXIT