[email protected] | ec238db | 2014-06-02 20:39:42 | [diff] [blame] | 1 | #!/usr/bin/env bash |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 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] | 7e97775 | 2014-12-11 03:06:48 | [diff] [blame] | 12 | PWD=$(pwd) |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 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] | 7e97775 | 2014-12-11 03:06:48 | [diff] [blame] | 18 | PATH="$(dirname $PWD):$PATH" |
19 | GIT_CL=$(dirname $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] | 7e97775 | 2014-12-11 03:06:48 | [diff] [blame] | 52 | # 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] | 4731ec4 | 2013-11-07 19:03:12 | [diff] [blame] | 54 | 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] | 55 | ( |
56 | cd git-svn | ||||
[email protected] | 4731ec4 | 2013-11-07 19:03:12 | [diff] [blame] | 57 | git remote add origin https://example.com/fake_refspec |
[email protected] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 58 | git config user.name 'TestDood' |
59 | git config user.email '[email protected]' | ||||
60 | ) | ||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 61 | } |
62 | |||||
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 63 | # Set up a git-svn checkout of the repo and apply merge commits |
64 | # (like the submodule repo layout). | ||||
65 | setup_gitsvn_submodule() { | ||||
66 | echo "Setting up test remote git-svn-submodule repo..." | ||||
67 | rm -rf git-svn-submodule | ||||
[email protected] | 7e97775 | 2014-12-11 03:06:48 | [diff] [blame] | 68 | # 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] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 71 | svn_revision=`svn info file://$PWD/svnrepo | grep ^Revision | \ |
72 | sed s/^.*:// | xargs` | ||||
73 | ( | ||||
74 | cd git-svn-submodule | ||||
[email protected] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 75 | git config user.name 'TestDood' |
76 | git config user.email '[email protected]' | ||||
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 77 | echo 'merge-file line 1' > merge-file |
78 | git add merge-file; git commit -q -m 'First non-svn commit on master' | ||||
[email protected] | 7e97775 | 2014-12-11 03:06:48 | [diff] [blame] | 79 | git checkout -q refs/remotes/origin/trunk |
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 80 | 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] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 89 | # Set up a git repo that has a few commits to master. |
90 | setup_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] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 98 | git config user.name 'TestDood' |
99 | git config user.email '[email protected]' | ||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 100 | 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] | a4e4ef3 | 2014-03-18 20:45:46 | [diff] [blame] | 107 | git checkout -q --detach master |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 108 | ) |
109 | } | ||||
110 | |||||
111 | # Set up a git checkout of the repo. | ||||
112 | setup_gitgit() { | ||||
113 | echo "Setting up test git repo..." | ||||
114 | rm -rf git-git | ||||
115 | git clone -q $GITREPO_URL git-git | ||||
[email protected] | 2a070f3 | 2013-06-27 19:21:10 | [diff] [blame] | 116 | ( |
117 | cd git-git | ||||
118 | git config user.name 'TestDood' | ||||
119 | git config user.email '[email protected]' | ||||
120 | ) | ||||
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 121 | } |
122 | |||||
123 | cleanup() { | ||||
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 124 | rm -rf gitrepo svnrepo svn git-git git-svn git-svn-submodule |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 125 | } |
126 | |||||
127 | # Usage: test_expect_success "description of test" "test code". | ||||
128 | test_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". | ||||
139 | test_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. | ||||
150 | print_xsrf_token() { | ||||
151 | curl --cookie dev_appserver_login="[email protected]:False" \ | ||||
152 | --header 'X-Requesting-XSRF-Token: 1' \ | ||||
[email protected] | 626e77d | 2014-03-13 01:05:58 | [diff] [blame] | 153 | http://localhost:10000/xsrf_token 2>/dev/null |
[email protected] | cc51cd0 | 2010-12-23 00:48:39 | [diff] [blame] | 154 | } |