blob: 92ec3bbdd4c1457564d83c00d720b3743fc9ea94 [file] [log] [blame]
[email protected]cc51cd02010-12-23 00:48:391#!/bin/bash
2
[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]cc51cd02010-12-23 00:48:3912PWD=`pwd`
13REPO_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]8d1a14f2013-07-27 02:30:2618PATH="$PWD/..:$PATH"
[email protected]cc51cd02010-12-23 00:48:3919GIT_CL=$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]4731ec42013-11-07 19:03:1252 git svn --prefix origin/ -q clone -s $REPO_URL git-svn >/dev/null 2>&1
[email protected]2a070f32013-06-27 19:21:1053 (
54 cd git-svn
[email protected]4731ec42013-11-07 19:03:1255 git remote add origin https://example.com/fake_refspec
[email protected]2a070f32013-06-27 19:21:1056 git config user.name 'TestDood'
57 git config user.email '[email protected]'
58 )
[email protected]cc51cd02010-12-23 00:48:3959}
60
[email protected]e84b7542012-06-15 21:26:5861# Set up a git-svn checkout of the repo and apply merge commits
62# (like the submodule repo layout).
63setup_gitsvn_submodule() {
64 echo "Setting up test remote git-svn-submodule repo..."
65 rm -rf git-svn-submodule
66 git svn -q clone -s $REPO_URL git-svn-submodule >/dev/null 2>&1
67 svn_revision=`svn info file://$PWD/svnrepo | grep ^Revision | \
68 sed s/^.*:// | xargs`
69 (
70 cd git-svn-submodule
[email protected]2a070f32013-06-27 19:21:1071 git config user.name 'TestDood'
72 git config user.email '[email protected]'
[email protected]e84b7542012-06-15 21:26:5873 echo 'merge-file line 1' > merge-file
74 git add merge-file; git commit -q -m 'First non-svn commit on master'
75 git checkout -q refs/remotes/trunk
76 git merge -q --no-commit --no-ff refs/heads/master >/dev/null 2>&1
77 echo 'merge-edit-file line 1' > merge-edit-file
78 git add merge-edit-file
79 git commit -q -m "SVN changes up to revision $svn_revision"
80 git update-ref refs/heads/master HEAD
81 git checkout master
82 )
83}
84
[email protected]cc51cd02010-12-23 00:48:3985# Set up a git repo that has a few commits to master.
86setup_initgit() {
87 echo "Setting up test upstream git repo..."
88 rm -rf gitrepo
89 mkdir gitrepo
90
91 (
92 cd gitrepo
93 git init -q
[email protected]2a070f32013-06-27 19:21:1094 git config user.name 'TestDood'
95 git config user.email '[email protected]'
[email protected]cc51cd02010-12-23 00:48:3996 echo "test" > test
97 git add test
98 git commit -qam "initial commit"
99 echo "test2" >> test
100 git commit -qam "second commit"
101 # Hack: make sure master is not the current branch
102 # otherwise push will give a warning
103 git checkout -q -b foo
104 )
105}
106
107# Set up a git checkout of the repo.
108setup_gitgit() {
109 echo "Setting up test git repo..."
110 rm -rf git-git
111 git clone -q $GITREPO_URL git-git
[email protected]2a070f32013-06-27 19:21:10112 (
113 cd git-git
114 git config user.name 'TestDood'
115 git config user.email '[email protected]'
116 )
[email protected]cc51cd02010-12-23 00:48:39117}
118
119cleanup() {
[email protected]e84b7542012-06-15 21:26:58120 rm -rf gitrepo svnrepo svn git-git git-svn git-svn-submodule
[email protected]cc51cd02010-12-23 00:48:39121}
122
123# Usage: test_expect_success "description of test" "test code".
124test_expect_success() {
125 echo "TESTING: $1"
126 exit_code=0
127 sh -c "$2" || exit_code=$?
128 if [ $exit_code != 0 ]; then
129 echo "FAILURE: $1"
130 return $exit_code
131 fi
132}
133
134# Usage: test_expect_failure "description of test" "test code".
135test_expect_failure() {
136 echo "TESTING: $1"
137 exit_code=0
138 sh -c "$2" || exit_code=$?
139 if [ $exit_code = 0 ]; then
140 echo "SUCCESS, BUT EXPECTED FAILURE: $1"
141 return $exit_code
142 fi
143}
144
145# Grab the XSRF token from the review server and print it to stdout.
146print_xsrf_token() {
147 curl --cookie dev_appserver_login="[email protected]:False" \
148 --header 'X-Requesting-XSRF-Token: 1' \
149 http://localhost:8080/xsrf_token 2>/dev/null
150}