blob: ad078180437b8b16700bd79fb66abab331ebc412 [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]866276c2011-03-18 20:09:3152 git svn -q clone -s $REPO_URL git-svn >/dev/null 2>&1
[email protected]2a070f32013-06-27 19:21:1053 (
54 cd git-svn
55 git config user.name 'TestDood'
56 git config user.email '[email protected]'
57 )
[email protected]cc51cd02010-12-23 00:48:3958}
59
[email protected]e84b7542012-06-15 21:26:5860# Set up a git-svn checkout of the repo and apply merge commits
61# (like the submodule repo layout).
62setup_gitsvn_submodule() {
63 echo "Setting up test remote git-svn-submodule repo..."
64 rm -rf git-svn-submodule
65 git svn -q clone -s $REPO_URL git-svn-submodule >/dev/null 2>&1
66 svn_revision=`svn info file://$PWD/svnrepo | grep ^Revision | \
67 sed s/^.*:// | xargs`
68 (
69 cd git-svn-submodule
[email protected]2a070f32013-06-27 19:21:1070 git config user.name 'TestDood'
71 git config user.email '[email protected]'
[email protected]e84b7542012-06-15 21:26:5872 echo 'merge-file line 1' > merge-file
73 git add merge-file; git commit -q -m 'First non-svn commit on master'
74 git checkout -q refs/remotes/trunk
75 git merge -q --no-commit --no-ff refs/heads/master >/dev/null 2>&1
76 echo 'merge-edit-file line 1' > merge-edit-file
77 git add merge-edit-file
78 git commit -q -m "SVN changes up to revision $svn_revision"
79 git update-ref refs/heads/master HEAD
80 git checkout master
81 )
82}
83
[email protected]cc51cd02010-12-23 00:48:3984# Set up a git repo that has a few commits to master.
85setup_initgit() {
86 echo "Setting up test upstream git repo..."
87 rm -rf gitrepo
88 mkdir gitrepo
89
90 (
91 cd gitrepo
92 git init -q
[email protected]2a070f32013-06-27 19:21:1093 git config user.name 'TestDood'
94 git config user.email '[email protected]'
[email protected]cc51cd02010-12-23 00:48:3995 echo "test" > test
96 git add test
97 git commit -qam "initial commit"
98 echo "test2" >> test
99 git commit -qam "second commit"
100 # Hack: make sure master is not the current branch
101 # otherwise push will give a warning
102 git checkout -q -b foo
103 )
104}
105
106# Set up a git checkout of the repo.
107setup_gitgit() {
108 echo "Setting up test git repo..."
109 rm -rf git-git
110 git clone -q $GITREPO_URL git-git
[email protected]2a070f32013-06-27 19:21:10111 (
112 cd git-git
113 git config user.name 'TestDood'
114 git config user.email '[email protected]'
115 )
[email protected]cc51cd02010-12-23 00:48:39116}
117
118cleanup() {
[email protected]e84b7542012-06-15 21:26:58119 rm -rf gitrepo svnrepo svn git-git git-svn git-svn-submodule
[email protected]cc51cd02010-12-23 00:48:39120}
121
122# Usage: test_expect_success "description of test" "test code".
123test_expect_success() {
124 echo "TESTING: $1"
125 exit_code=0
126 sh -c "$2" || exit_code=$?
127 if [ $exit_code != 0 ]; then
128 echo "FAILURE: $1"
129 return $exit_code
130 fi
131}
132
133# Usage: test_expect_failure "description of test" "test code".
134test_expect_failure() {
135 echo "TESTING: $1"
136 exit_code=0
137 sh -c "$2" || exit_code=$?
138 if [ $exit_code = 0 ]; then
139 echo "SUCCESS, BUT EXPECTED FAILURE: $1"
140 return $exit_code
141 fi
142}
143
144# Grab the XSRF token from the review server and print it to stdout.
145print_xsrf_token() {
146 curl --cookie dev_appserver_login="[email protected]:False" \
147 --header 'X-Requesting-XSRF-Token: 1' \
148 http://localhost:8080/xsrf_token 2>/dev/null
149}