blob: bcda6c7ec4301c98766e64ed1a79ee69dd6559a3 [file] [log] [blame]
[email protected]ec238db2014-06-02 20:39:421#!/usr/bin/env bash
[email protected]cc51cd02010-12-23 00:48:392
[email protected]e84b7542012-06-15 21:26:583# Copyright (c) 2012 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
[email protected]cc51cd02010-12-23 00:48:397# Abort on error.
8set -e
9
[email protected]01da4f82012-01-24 21:54:5110export DEPOT_TOOLS_UPDATE=0
11
[email protected]7e977752014-12-11 03:06:4812PWD=$(pwd)
[email protected]cc51cd02010-12-23 00:48:3913REPO_URL=file://$PWD/svnrepo
[email protected]866276c2011-03-18 20:09:3114TRUNK_URL=$REPO_URL/trunk
15BRANCH_URL=$REPO_URL/branches/some_branch
[email protected]cc51cd02010-12-23 00:48:3916GITREPO_PATH=$PWD/gitrepo
17GITREPO_URL=file://$GITREPO_PATH
[email protected]7e977752014-12-11 03:06:4818PATH="$(dirname $PWD):$PATH"
19GIT_CL=$(dirname $PWD)/git-cl
[email protected]8d1a14f2013-07-27 02:30:2620GIT_CL_STATUS="$GIT_CL status -f"
[email protected]cc51cd02010-12-23 00:48:3921
22# Set up an SVN repo that has a few commits to trunk.
23setup_initsvn() {
24 echo "Setting up test SVN repo..."
25 rm -rf svnrepo
26 svnadmin create svnrepo
[email protected]a1851452011-03-11 22:54:0227 # Need this in order for Mac SnowLeopard to work
28 echo "enable-rep-sharing = false" >> svnrepo/db/fsfs.conf
29
[email protected]866276c2011-03-18 20:09:3130 svn mkdir -q -m 'creating trunk' --parents $TRUNK_URL
31
[email protected]cc51cd02010-12-23 00:48:3932 rm -rf svn
[email protected]866276c2011-03-18 20:09:3133 svn co -q $TRUNK_URL svn
[email protected]cc51cd02010-12-23 00:48:3934 (
35 cd svn
36 echo "test" > test
37 svn add -q test
38 svn commit -q -m "initial commit"
39 echo "test2" >> test
40 svn commit -q -m "second commit"
41 )
[email protected]866276c2011-03-18 20:09:3142
43 svn cp -q -m 'branching' --parents $TRUNK_URL $BRANCH_URL
[email protected]cc51cd02010-12-23 00:48:3944}
45
46# Set up a git-svn checkout of the repo.
47setup_gitsvn() {
48 echo "Setting up test git-svn repo..."
49 rm -rf git-svn
50 # There appears to be no way to make git-svn completely shut up, so we
51 # redirect its output.
[email protected]7e977752014-12-11 03:06:4852 # clone with --prefix origin/ to ensure the same behaviour with old and new
53 # versions of git (The default prefix was "" prior to Git 2.0)
[email protected]4731ec42013-11-07 19:03:1254 git svn --prefix origin/ -q clone -s $REPO_URL git-svn >/dev/null 2>&1
[email protected]2a070f32013-06-27 19:21:1055 (
56 cd git-svn
[email protected]4731ec42013-11-07 19:03:1257 git remote add origin https://example.com/fake_refspec
[email protected]2a070f32013-06-27 19:21:1058 git config user.name 'TestDood'
59 git config user.email '[email protected]'
60 )
[email protected]cc51cd02010-12-23 00:48:3961}
62
[email protected]e84b7542012-06-15 21:26:5863# Set up a git-svn checkout of the repo and apply merge commits
64# (like the submodule repo layout).
65setup_gitsvn_submodule() {
66 echo "Setting up test remote git-svn-submodule repo..."
67 rm -rf git-svn-submodule
[email protected]7e977752014-12-11 03:06:4868 # clone with --prefix origin/ to ensure the same behaviour with old and new
69 # versions of git (The default prefix was "" prior to Git 2.0)
70 git svn --prefix origin/ -q clone -s $REPO_URL git-svn-submodule >/dev/null 2>&1
[email protected]e84b7542012-06-15 21:26:5871 svn_revision=`svn info file://$PWD/svnrepo | grep ^Revision | \
72 sed s/^.*:// | xargs`
73 (
74 cd git-svn-submodule
[email protected]2a070f32013-06-27 19:21:1075 git config user.name 'TestDood'
76 git config user.email '[email protected]'
[email protected]e84b7542012-06-15 21:26:5877 echo 'merge-file line 1' > merge-file
78 git add merge-file; git commit -q -m 'First non-svn commit on master'
[email protected]7e977752014-12-11 03:06:4879 git checkout -q refs/remotes/origin/trunk
[email protected]e84b7542012-06-15 21:26:5880 git merge -q --no-commit --no-ff refs/heads/master >/dev/null 2>&1
81 echo 'merge-edit-file line 1' > merge-edit-file
82 git add merge-edit-file
83 git commit -q -m "SVN changes up to revision $svn_revision"
84 git update-ref refs/heads/master HEAD
85 git checkout master
86 )
87}
88
[email protected]cc51cd02010-12-23 00:48:3989# Set up a git repo that has a few commits to master.
90setup_initgit() {
91 echo "Setting up test upstream git repo..."
92 rm -rf gitrepo
93 mkdir gitrepo
94
95 (
96 cd gitrepo
97 git init -q
[email protected]2a070f32013-06-27 19:21:1098 git config user.name 'TestDood'
99 git config user.email '[email protected]'
[email protected]cc51cd02010-12-23 00:48:39100 echo "test" > test
101 git add test
102 git commit -qam "initial commit"
103 echo "test2" >> test
104 git commit -qam "second commit"
105 # Hack: make sure master is not the current branch
106 # otherwise push will give a warning
[email protected]a4e4ef32014-03-18 20:45:46107 git checkout -q --detach master
[email protected]cc51cd02010-12-23 00:48:39108 )
109}
110
111# Set up a git checkout of the repo.
112setup_gitgit() {
113 echo "Setting up test git repo..."
114 rm -rf git-git
115 git clone -q $GITREPO_URL git-git
[email protected]2a070f32013-06-27 19:21:10116 (
117 cd git-git
118 git config user.name 'TestDood'
119 git config user.email '[email protected]'
120 )
[email protected]cc51cd02010-12-23 00:48:39121}
122
123cleanup() {
[email protected]e84b7542012-06-15 21:26:58124 rm -rf gitrepo svnrepo svn git-git git-svn git-svn-submodule
[email protected]cc51cd02010-12-23 00:48:39125}
126
127# Usage: test_expect_success "description of test" "test code".
128test_expect_success() {
129 echo "TESTING: $1"
130 exit_code=0
131 sh -c "$2" || exit_code=$?
132 if [ $exit_code != 0 ]; then
133 echo "FAILURE: $1"
134 return $exit_code
135 fi
136}
137
138# Usage: test_expect_failure "description of test" "test code".
139test_expect_failure() {
140 echo "TESTING: $1"
141 exit_code=0
142 sh -c "$2" || exit_code=$?
143 if [ $exit_code = 0 ]; then
144 echo "SUCCESS, BUT EXPECTED FAILURE: $1"
145 return $exit_code
146 fi
147}
148
149# Grab the XSRF token from the review server and print it to stdout.
150print_xsrf_token() {
151 curl --cookie dev_appserver_login="[email protected]:False" \
152 --header 'X-Requesting-XSRF-Token: 1' \
[email protected]626e77d2014-03-13 01:05:58153 http://localhost:10000/xsrf_token 2>/dev/null
[email protected]cc51cd02010-12-23 00:48:39154}