[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 1 | #!/bin/bash |
2 | |||||
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 3 | # 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] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 7 | # Abort on error. |
8 | set -e | ||||
9 | |||||
[email protected] | 01da4f8 | 2012-01-24 21:54:51 | [diff] [blame] | 10 | export DEPOT_TOOLS_UPDATE=0 |
11 | |||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 12 | PWD=`pwd` |
13 | REPO_URL=file://$PWD/svnrepo | ||||
[email protected] | 866276c | 2011-03-18 20:09:31 | [diff] [blame] | 14 | TRUNK_URL=$REPO_URL/trunk |
15 | BRANCH_URL=$REPO_URL/branches/some_branch | ||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 16 | GITREPO_PATH=$PWD/gitrepo |
17 | GITREPO_URL=file://$GITREPO_PATH | ||||
[email protected] | 8d1a14f | 2013-07-27 02:30:26 | [diff] [blame] | 18 | PATH="$PWD/..:$PATH" |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 19 | GIT_CL=$PWD/../git-cl |
[email protected] | 8d1a14f | 2013-07-27 02:30:26 | [diff] [blame] | 20 | GIT_CL_STATUS="$GIT_CL status -f" |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 21 | |
22 | # Set up an SVN repo that has a few commits to trunk. | ||||
23 | setup_initsvn() { | ||||
24 | echo "Setting up test SVN repo..." | ||||
25 | rm -rf svnrepo | ||||
26 | svnadmin create svnrepo | ||||
[email protected] | a185145 | 2011-03-11 22:54:02 | [diff] [blame] | 27 | # Need this in order for Mac SnowLeopard to work |
28 | echo "enable-rep-sharing = false" >> svnrepo/db/fsfs.conf | ||||
29 | |||||
[email protected] | 866276c | 2011-03-18 20:09:31 | [diff] [blame] | 30 | svn mkdir -q -m 'creating trunk' --parents $TRUNK_URL |
31 | |||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 32 | rm -rf svn |
[email protected] | 866276c | 2011-03-18 20:09:31 | [diff] [blame] | 33 | svn co -q $TRUNK_URL svn |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 34 | ( |
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] | 866276c | 2011-03-18 20:09:31 | [diff] [blame] | 42 | |
43 | svn cp -q -m 'branching' --parents $TRUNK_URL $BRANCH_URL | ||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 44 | } |
45 | |||||
46 | # Set up a git-svn checkout of the repo. | ||||
47 | setup_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] | 4731ec4 | 2013-11-07 19:03:12 | [diff] [blame^] | 52 | git svn --prefix origin/ -q clone -s $REPO_URL git-svn >/dev/null 2>&1 |
[email protected] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 53 | ( |
54 | cd git-svn | ||||
[email protected] | 4731ec4 | 2013-11-07 19:03:12 | [diff] [blame^] | 55 | git remote add origin https://example.com/fake_refspec |
[email protected] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 56 | git config user.name 'TestDood' |
57 | git config user.email '[email protected]' | ||||
58 | ) | ||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 59 | } |
60 | |||||
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 61 | # Set up a git-svn checkout of the repo and apply merge commits |
62 | # (like the submodule repo layout). | ||||
63 | setup_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] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 71 | git config user.name 'TestDood' |
72 | git config user.email '[email protected]' | ||||
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 73 | 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] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 85 | # Set up a git repo that has a few commits to master. |
86 | setup_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] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 94 | git config user.name 'TestDood' |
95 | git config user.email '[email protected]' | ||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 96 | 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. | ||||
108 | setup_gitgit() { | ||||
109 | echo "Setting up test git repo..." | ||||
110 | rm -rf git-git | ||||
111 | git clone -q $GITREPO_URL git-git | ||||
[email protected] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 112 | ( |
113 | cd git-git | ||||
114 | git config user.name 'TestDood' | ||||
115 | git config user.email '[email protected]' | ||||
116 | ) | ||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 117 | } |
118 | |||||
119 | cleanup() { | ||||
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 120 | rm -rf gitrepo svnrepo svn git-git git-svn git-svn-submodule |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 121 | } |
122 | |||||
123 | # Usage: test_expect_success "description of test" "test code". | ||||
124 | test_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". | ||||
135 | test_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. | ||||
146 | print_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 | } |