Move git-cl into depot_tools.
BUG=none TEST=git-cl works after move Review URL: http://codereview.chromium.org/5012006 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@70011 0039d316-1c4b-4281-b951-d872f2087c98experimental/szager/collated-output
parent
dcd1522a6c
commit
cc51cd03e0
@ -0,0 +1,26 @@
|
|||||||
|
Copyright (c) 2008 Evan Martin <martine@danga.com>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of the author nor the names of contributors may be
|
||||||
|
used to endorse or promote products derived from this software without
|
||||||
|
specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||||
|
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||||
|
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -0,0 +1,124 @@
|
|||||||
|
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
"""Top-level presubmit script for depot tools.
|
||||||
|
|
||||||
|
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
|
||||||
|
details on the presubmit API built into gcl.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def CheckChangeOnUpload(input_api, output_api):
|
||||||
|
return RunTests(input_api, output_api)
|
||||||
|
|
||||||
|
|
||||||
|
def CheckChangeOnCommit(input_api, output_api):
|
||||||
|
return RunTests(input_api, output_api)
|
||||||
|
|
||||||
|
|
||||||
|
def RunTests(input_api, output_api):
|
||||||
|
"""Run all the shells scripts in the directory test.
|
||||||
|
|
||||||
|
Also verify the GAE python SDK is available, fetches Rietveld if necessary and
|
||||||
|
start a test instance to test against.
|
||||||
|
"""
|
||||||
|
# They are not exposed from InputApi.
|
||||||
|
from os import listdir, pathsep
|
||||||
|
import socket
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Shortcuts
|
||||||
|
join = input_api.os_path.join
|
||||||
|
error = output_api.PresubmitError
|
||||||
|
|
||||||
|
# Paths
|
||||||
|
sdk_path = input_api.os_path.abspath(join('..', '..', 'google_appengine'))
|
||||||
|
dev_app = join(sdk_path, 'dev_appserver.py')
|
||||||
|
rietveld = join('test', 'rietveld')
|
||||||
|
django_path = join(rietveld, 'django')
|
||||||
|
|
||||||
|
# Generate a friendly environment.
|
||||||
|
env = input_api.environ.copy()
|
||||||
|
env['LANGUAGE'] = 'en'
|
||||||
|
if env.get('PYTHONPATH'):
|
||||||
|
env['PYTHONPATH'] = (env['PYTHONPATH'].rstrip(pathsep) + pathsep +
|
||||||
|
django_path)
|
||||||
|
else:
|
||||||
|
env['PYTHONPATH'] = django_path
|
||||||
|
|
||||||
|
def call(*args, **kwargs):
|
||||||
|
kwargs['env'] = env
|
||||||
|
x = input_api.subprocess.Popen(*args, **kwargs)
|
||||||
|
x.communicate()
|
||||||
|
return x.returncode == 0
|
||||||
|
|
||||||
|
def test_port(port):
|
||||||
|
s = socket.socket()
|
||||||
|
try:
|
||||||
|
return s.connect_ex(('127.0.0.1', port)) == 0
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
# First, verify the Google AppEngine SDK is available.
|
||||||
|
if not input_api.os_path.isfile(dev_app):
|
||||||
|
return [error('Install google_appengine sdk in %s' % sdk_path)]
|
||||||
|
|
||||||
|
# Second, checkout rietveld and django if not available.
|
||||||
|
if not input_api.os_path.isdir(rietveld):
|
||||||
|
print('Checking out rietveld...')
|
||||||
|
if not call(['svn', 'co', '-q',
|
||||||
|
'http://rietveld.googlecode.com/svn/trunk@563',
|
||||||
|
rietveld]):
|
||||||
|
return [error('Failed to checkout rietveld')]
|
||||||
|
if not input_api.os_path.isdir(django_path):
|
||||||
|
print('Checking out django...')
|
||||||
|
if not call(
|
||||||
|
['svn', 'co', '-q',
|
||||||
|
'http://code.djangoproject.com/'
|
||||||
|
'svn/django/branches/releases/1.0.X/django@13637',
|
||||||
|
django_path]):
|
||||||
|
return [error('Failed to checkout django')]
|
||||||
|
|
||||||
|
|
||||||
|
# Test to find an available port starting at 8080.
|
||||||
|
port = 8080
|
||||||
|
while test_port(port) and port < 65000:
|
||||||
|
port += 1
|
||||||
|
if port == 65000:
|
||||||
|
return [error('Having issues finding an available port')]
|
||||||
|
|
||||||
|
verbose = False
|
||||||
|
if verbose:
|
||||||
|
stdout = None
|
||||||
|
stderr = None
|
||||||
|
else:
|
||||||
|
stdout = input_api.subprocess.PIPE
|
||||||
|
stderr = input_api.subprocess.PIPE
|
||||||
|
output = []
|
||||||
|
test_server = input_api.subprocess.Popen(
|
||||||
|
[dev_app, rietveld, '--port=%d' % port,
|
||||||
|
'--datastore_path=' + join(rietveld, 'tmp.db'), '-c'],
|
||||||
|
stdout=stdout, stderr=stderr, env=env)
|
||||||
|
try:
|
||||||
|
# Loop until port 127.0.0.1:port opens or the process dies.
|
||||||
|
while not test_port(port):
|
||||||
|
test_server.poll()
|
||||||
|
if test_server.returncode is not None:
|
||||||
|
output.append(error('Test rietveld instance failed early'))
|
||||||
|
break
|
||||||
|
time.sleep(0.001)
|
||||||
|
|
||||||
|
test_path = input_api.os_path.abspath('test')
|
||||||
|
for test in listdir(test_path):
|
||||||
|
# push-from-logs and rename fails for now. Remove from this list once they
|
||||||
|
# work.
|
||||||
|
if (test in ('push-from-logs.sh', 'rename.sh', 'test-lib.sh') or
|
||||||
|
not test.endswith('.sh')):
|
||||||
|
continue
|
||||||
|
print('Running %s' % test)
|
||||||
|
if not call([join(test_path, test)], cwd=test_path, stdout=stdout):
|
||||||
|
output.append(error('%s failed' % test))
|
||||||
|
finally:
|
||||||
|
test_server.kill()
|
||||||
|
return output
|
@ -0,0 +1,52 @@
|
|||||||
|
# git-cl -- a git-command for integrating reviews on Rietveld
|
||||||
|
# Copyright (C) 2008 Evan Martin <martine@danga.com>
|
||||||
|
|
||||||
|
== Background
|
||||||
|
Rietveld, also known as http://codereview.appspot.com, is a nice tool
|
||||||
|
for code reviews. You upload a patch (and some other data) and it lets
|
||||||
|
others comment on your patch.
|
||||||
|
|
||||||
|
For more on how this all works conceptually, please see README.codereview.
|
||||||
|
The remainder of this document is the nuts and bolts of using git-cl.
|
||||||
|
|
||||||
|
== Install
|
||||||
|
Copy (symlink) it into your path somewhere, along with Rietveld
|
||||||
|
upload.py.
|
||||||
|
|
||||||
|
== Setup
|
||||||
|
Run this from your git checkout and answer some questions:
|
||||||
|
$ git cl config
|
||||||
|
|
||||||
|
== How to use it
|
||||||
|
Make a new branch. Write some code. Commit it locally. Send it for
|
||||||
|
review:
|
||||||
|
$ git cl upload
|
||||||
|
By default, it diffs against whatever branch the current branch is
|
||||||
|
tracking (see "git checkout --track"). An optional last argument is
|
||||||
|
passed to "git diff", allowing reviews against other heads.
|
||||||
|
|
||||||
|
You'll be asked some questions, and the review issue number will be
|
||||||
|
associated with your current git branch, so subsequent calls to upload
|
||||||
|
will update that review rather than making a new one.
|
||||||
|
|
||||||
|
== git-svn integration
|
||||||
|
Review looks good? Commit the code:
|
||||||
|
$ git cl dcommit
|
||||||
|
This does a git-svn dcommit, with a twist: all changes in the diff
|
||||||
|
will be squashed into a single commit, and the description of the commit
|
||||||
|
is taken directly from the Rietveld description. This command also accepts
|
||||||
|
arguments to "git diff", much like upload.
|
||||||
|
Try "git cl dcommit --help" for more options.
|
||||||
|
|
||||||
|
== Extra commands
|
||||||
|
Print some status info:
|
||||||
|
$ git cl status
|
||||||
|
|
||||||
|
Edit the issue association on the current branch:
|
||||||
|
$ git cl issue 1234
|
||||||
|
|
||||||
|
Patch in a review:
|
||||||
|
$ git cl patch <url to full patch>
|
||||||
|
Try "git cl patch --help" for more options.
|
||||||
|
|
||||||
|
vim: tw=72 :
|
@ -0,0 +1,99 @@
|
|||||||
|
The git-cl README describes the git-cl command set. This document
|
||||||
|
describes how code review and git work together in general, intended
|
||||||
|
for people familiar with git but unfamiliar with the code review
|
||||||
|
process supported by Rietveld.
|
||||||
|
|
||||||
|
== Concepts and terms
|
||||||
|
A Rietveld review is for discussion of a single change or patch. You
|
||||||
|
upload a proposed change, the reviewer comments on your change, and
|
||||||
|
then you can upload a revised version of your change. Rietveld stores
|
||||||
|
the history of uploaded patches as well as the comments, and can
|
||||||
|
compute diffs in between these patches. The history of a patch is
|
||||||
|
very much like a small branch in git, but since Rietveld is
|
||||||
|
VCS-agnostic the concepts don't map perfectly. The identifier for a
|
||||||
|
single review+patches+comments in Rietveld is called an "issue".
|
||||||
|
|
||||||
|
Rietveld provides a basic uploader that understands git. This program
|
||||||
|
is used by git-cl, and is included in the git-cl repo as upload.py.
|
||||||
|
|
||||||
|
== Basic interaction with git
|
||||||
|
The fundamental problem you encounter when you try to mix git and code
|
||||||
|
review is that with git it's nice to commit code locally, while during
|
||||||
|
a code review you're often requested to change something about your
|
||||||
|
code. There are a few different ways you can handle this workflow
|
||||||
|
with git:
|
||||||
|
|
||||||
|
1) Rewriting a single commit. Say the origin commit is O, and you
|
||||||
|
commit your initial work in a commit A, making your history like
|
||||||
|
O--A. After review comments, you commit --amend, effectively
|
||||||
|
erasing A and making a new commit A', so history is now O--A'.
|
||||||
|
(Equivalently, you can use git reset --soft or git rebase -i.)
|
||||||
|
|
||||||
|
2) Writing follow-up commits. Initial work is again in A, and after
|
||||||
|
review comments, you write a new commit B so your history looks
|
||||||
|
like O--A--B. When you upload the revised patch, you upload the
|
||||||
|
diff of O..B, not A..B; you always upload the full diff of what
|
||||||
|
you're proposing to change.
|
||||||
|
|
||||||
|
The Rietveld patch uploader just takes arguments to "git diff", so
|
||||||
|
either of the above workflows work fine. If all you want to do is
|
||||||
|
upload a patch, you can use the upload.py provided by Rietveld with
|
||||||
|
arguments like this:
|
||||||
|
|
||||||
|
upload.py --server server.com <args to "git diff">
|
||||||
|
|
||||||
|
The first time you upload, it creates a new issue; for follow-ups on
|
||||||
|
the same issue, you need to provide the issue number:
|
||||||
|
|
||||||
|
upload.py --server server.com --issue 1234 <args to "git diff">
|
||||||
|
|
||||||
|
== git-cl to the rescue
|
||||||
|
git-cl simplifies the above in the following ways:
|
||||||
|
|
||||||
|
1) "git cl config" puts a persistent --server setting in your .git/config.
|
||||||
|
|
||||||
|
2) The first time you upload an issue, the issue number is associated with
|
||||||
|
the current *branch*. If you upload again, it will upload on the same
|
||||||
|
issue. (Note that this association is tied to a branch, not a commit,
|
||||||
|
which means you need a separate branch per review.)
|
||||||
|
|
||||||
|
3) If your branch is "tracking" (in the "git checkout --track" sense)
|
||||||
|
another one (like origin/master), calls to "git cl upload" will
|
||||||
|
diff against that branch by default. (You can still pass arguments
|
||||||
|
to "git diff" on the command line, if necessary.)
|
||||||
|
|
||||||
|
In the common case, this means that calling simply "git cl upload"
|
||||||
|
will always upload the correct diff to the correct place.
|
||||||
|
|
||||||
|
== Patch series
|
||||||
|
The above is all you need to know for working on a single patch.
|
||||||
|
|
||||||
|
Things get much more complicated when you have a series of commits
|
||||||
|
that you want to get reviewed. Say your history looks like
|
||||||
|
O--A--B--C. If you want to upload that as a single review, everything
|
||||||
|
works just as above.
|
||||||
|
|
||||||
|
But what if you upload each of A, B, and C as separate reviews?
|
||||||
|
What if you then need to change A?
|
||||||
|
|
||||||
|
1) One option is rewriting history: write a new commit A', then use
|
||||||
|
git rebase -i to insert that diff in as O--A--A'--B--C as well as
|
||||||
|
squash it. This is sometimes not possible if B and C have touched
|
||||||
|
some lines affected by A'.
|
||||||
|
|
||||||
|
2) Another option, and the one espoused by software like topgit, is for
|
||||||
|
you to have separate branches for A, B, and C, and after writing A'
|
||||||
|
you merge it into each of those branches. (topgit automates this
|
||||||
|
merging process.) This is also what is recommended by git-cl, which
|
||||||
|
likes having different branch identifiers to hang the issue number
|
||||||
|
off of. Your history ends up looking like:
|
||||||
|
|
||||||
|
O---A---B---C
|
||||||
|
\ \ \
|
||||||
|
A'--B'--C'
|
||||||
|
|
||||||
|
Which is ugly, but it accurately tracks the real history of your work, can
|
||||||
|
be thrown away at the end by committing A+A' as a single "squash" commit.
|
||||||
|
|
||||||
|
In practice, this comes up pretty rarely. Suggestions for better workflows
|
||||||
|
are welcome.
|
@ -0,0 +1,23 @@
|
|||||||
|
Most of the tests require a local Rietveld server.
|
||||||
|
|
||||||
|
To set this up:
|
||||||
|
Method 1: Let the presubmit script do the work for you.
|
||||||
|
$ git cl presubmit
|
||||||
|
|
||||||
|
Method 2: Manual.
|
||||||
|
1) Check out a copy of Rietveld:
|
||||||
|
$ svn checkout http://rietveld.googlecode.com/svn/trunk/ rietveld
|
||||||
|
(Use git-svn if you must, but man is it slow.)
|
||||||
|
2) Get the Google App Engine SDK:
|
||||||
|
http://code.google.com/appengine/downloads.html
|
||||||
|
3) To run Rietveld you will need Django 1.0, which is not included
|
||||||
|
with the App Engine SDK. Go to http://www.djangoproject.com/download ,
|
||||||
|
download a Django from the 1.0 series (it's in the sidebar on the right),
|
||||||
|
untar it, then
|
||||||
|
$ export PYTHONPATH=`pwd`/Django-1.0.4
|
||||||
|
4) Run Rietveld:
|
||||||
|
$ /path/to/appengine/sdk/dev_appserver.py /path/to/rietveld
|
||||||
|
(If using one of the App Engine launchers, be sure to use port 8080
|
||||||
|
for this project.)
|
||||||
|
|
||||||
|
And then, finally, run the tests.
|
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# git-cl -- a git-command for integrating reviews on Rietveld
|
||||||
|
# Copyright (C) 2008 Evan Martin <martine@danga.com>
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import git_cl
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(git_cl.main(sys.argv[1:]))
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check that abandoning a branch also abandons its issue.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initsvn
|
||||||
|
setup_gitsvn
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-svn
|
||||||
|
git config rietveld.server localhost:8080
|
||||||
|
|
||||||
|
# Create a branch and give it an issue.
|
||||||
|
git checkout -q -b abandoned
|
||||||
|
echo "some work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
export EDITOR=/bin/true
|
||||||
|
test_expect_success "upload succeeds" \
|
||||||
|
"$GIT_CL upload -m test master... | grep -q 'Issue created'"
|
||||||
|
|
||||||
|
# Switch back to master, delete the branch.
|
||||||
|
git checkout master
|
||||||
|
git branch -D abandoned
|
||||||
|
|
||||||
|
# Verify that "status" doesn't know about it anymore.
|
||||||
|
# The "exit" trickiness is inverting the exit status of grep.
|
||||||
|
test_expect_success "git-cl status dropped abandoned branch" \
|
||||||
|
"$GIT_CL status | grep -q abandoned && exit 1 || exit 0"
|
||||||
|
)
|
||||||
|
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,64 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initsvn
|
||||||
|
setup_gitsvn
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-svn
|
||||||
|
git checkout -q -b work
|
||||||
|
echo "some work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
echo "some other work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
|
||||||
|
test_expect_success "git-cl upload wants a server" \
|
||||||
|
"$GIT_CL upload 2>&1 | grep -q 'You must configure'"
|
||||||
|
|
||||||
|
git config rietveld.server localhost:8080
|
||||||
|
|
||||||
|
test_expect_success "git-cl status has no issue" \
|
||||||
|
"$GIT_CL status | grep -q 'no issue'"
|
||||||
|
|
||||||
|
# Prevent the editor from coming up when you upload.
|
||||||
|
export EDITOR=$(which true)
|
||||||
|
|
||||||
|
test_expect_success "upload succeeds (needs a server running on localhost)" \
|
||||||
|
"$GIT_CL upload -m test master... | grep -q 'Issue created'"
|
||||||
|
|
||||||
|
test_expect_success "git-cl status now knows the issue" \
|
||||||
|
"$GIT_CL status | grep -q 'Issue number'"
|
||||||
|
|
||||||
|
# Push a description to this URL.
|
||||||
|
URL=$($GIT_CL status | sed -ne '/Issue number/s/[^(]*(\(.*\))/\1/p')
|
||||||
|
curl --cookie dev_appserver_login="test@example.com:False" \
|
||||||
|
--data-urlencode subject="test" \
|
||||||
|
--data-urlencode description="foo-quux" \
|
||||||
|
--data-urlencode xsrf_token="$(print_xsrf_token)" \
|
||||||
|
$URL/edit
|
||||||
|
|
||||||
|
test_expect_success "git-cl dcommits ok" \
|
||||||
|
"$GIT_CL dcommit -f"
|
||||||
|
|
||||||
|
git checkout -q master
|
||||||
|
git svn -q rebase >/dev/null 2>&1
|
||||||
|
test_expect_success "dcommitted code has proper description" \
|
||||||
|
"git show | grep -q 'foo-quux'"
|
||||||
|
|
||||||
|
test_expect_success "issue no longer has a branch" \
|
||||||
|
"git cl status | grep -q 'work: None'"
|
||||||
|
|
||||||
|
test_expect_success "upstream svn has our commit" \
|
||||||
|
"svn log $REPO_URL 2>/dev/null | grep -q 'foo-quux'"
|
||||||
|
)
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Tests the "preupload and predcommit hooks" functionality, which lets you run
|
||||||
|
# hooks by installing a script into .git/hooks/pre-cl-* first.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initsvn
|
||||||
|
setup_gitsvn
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-svn
|
||||||
|
|
||||||
|
# We need a server set up, but we don't use it.
|
||||||
|
git config rietveld.server localhost:1
|
||||||
|
|
||||||
|
# Install a pre-cl-upload hook.
|
||||||
|
echo "#!/bin/bash" > .git/hooks/pre-cl-upload
|
||||||
|
echo "echo 'sample preupload fail'" >> .git/hooks/pre-cl-upload
|
||||||
|
echo "exit 1" >> .git/hooks/pre-cl-upload
|
||||||
|
chmod 755 .git/hooks/pre-cl-upload
|
||||||
|
|
||||||
|
# Install a pre-cl-dcommit hook.
|
||||||
|
echo "#!/bin/bash" > .git/hooks/pre-cl-dcommit
|
||||||
|
echo "echo 'sample predcommit fail'" >> .git/hooks/pre-cl-dcommit
|
||||||
|
echo "exit 1" >> .git/hooks/pre-cl-dcommit
|
||||||
|
chmod 755 .git/hooks/pre-cl-dcommit
|
||||||
|
|
||||||
|
echo "some work done" >> test
|
||||||
|
git add test; git commit -q -m "work"
|
||||||
|
|
||||||
|
# Verify git cl upload fails.
|
||||||
|
test_expect_failure "git-cl upload hook fails" "$GIT_CL upload master"
|
||||||
|
|
||||||
|
# Verify git cl upload fails.
|
||||||
|
test_expect_failure "git-cl dcommit hook fails" "$GIT_CL dcommit master"
|
||||||
|
)
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
#cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initgit
|
||||||
|
setup_gitgit
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-git
|
||||||
|
git checkout -q --track -b work origin
|
||||||
|
echo "some work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
echo "some other work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
|
||||||
|
test_expect_success "git-cl upload wants a server" \
|
||||||
|
"$GIT_CL upload 2>&1 | grep -q 'You must configure'"
|
||||||
|
|
||||||
|
git config rietveld.server localhost:8080
|
||||||
|
|
||||||
|
test_expect_success "git-cl status has no issue" \
|
||||||
|
"$GIT_CL status | grep -q 'no issue'"
|
||||||
|
|
||||||
|
# Prevent the editor from coming up when you upload.
|
||||||
|
export EDITOR=$(which true)
|
||||||
|
test_expect_success "upload succeeds (needs a server running on localhost)" \
|
||||||
|
"$GIT_CL upload -m test master... | grep -q 'Issue created'"
|
||||||
|
|
||||||
|
test_expect_success "git-cl status now knows the issue" \
|
||||||
|
"$GIT_CL status | grep -q 'Issue number'"
|
||||||
|
|
||||||
|
# Push a description to this URL.
|
||||||
|
URL=$($GIT_CL status | sed -ne '/Issue number/s/[^(]*(\(.*\))/\1/p')
|
||||||
|
curl --cookie dev_appserver_login="test@example.com:False" \
|
||||||
|
--data-urlencode subject="test" \
|
||||||
|
--data-urlencode description="foo-quux" \
|
||||||
|
--data-urlencode xsrf_token="$(print_xsrf_token)" \
|
||||||
|
$URL/edit
|
||||||
|
|
||||||
|
test_expect_success "Base URL contains branch name" \
|
||||||
|
"curl -s $($GIT_CL status --field=url) | grep 'URL:' | grep -q '@master'"
|
||||||
|
|
||||||
|
test_expect_success "git-cl push ok" \
|
||||||
|
"$GIT_CL push -f"
|
||||||
|
|
||||||
|
git checkout -q master > /dev/null 2>&1
|
||||||
|
git pull -q > /dev/null 2>&1
|
||||||
|
|
||||||
|
test_expect_success "committed code has proper description" \
|
||||||
|
"git show | grep -q 'foo-quux'"
|
||||||
|
|
||||||
|
test_expect_success "issue no longer has a branch" \
|
||||||
|
"git cl status | grep -q 'work: None'"
|
||||||
|
|
||||||
|
cd $GITREPO_PATH
|
||||||
|
test_expect_success "upstream repo has our commit" \
|
||||||
|
"git log master 2>/dev/null | grep -q 'foo-quux'"
|
||||||
|
)
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,67 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initgit
|
||||||
|
setup_gitgit
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-git
|
||||||
|
git checkout -q --track -b work origin
|
||||||
|
echo "some work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
echo "some other work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
|
||||||
|
test_expect_success "git-cl upload wants a server" \
|
||||||
|
"$GIT_CL upload 2>&1 | grep -q 'You must configure'"
|
||||||
|
|
||||||
|
git config rietveld.server localhost:8080
|
||||||
|
|
||||||
|
test_expect_success "git-cl status has no issue" \
|
||||||
|
"$GIT_CL status | grep -q 'no issue'"
|
||||||
|
|
||||||
|
# Prevent the editor from coming up when you upload.
|
||||||
|
export EDITOR=$(which true)
|
||||||
|
test_expect_success "upload succeeds (needs a server running on localhost)" \
|
||||||
|
"$GIT_CL upload -m test --desc_from_logs master... | \
|
||||||
|
grep -q 'Issue created'"
|
||||||
|
|
||||||
|
test_expect_success "git-cl status now knows the issue" \
|
||||||
|
"$GIT_CL status | grep -q 'Issue number'"
|
||||||
|
|
||||||
|
# Check to see if the description contains the local commit messages.
|
||||||
|
# Should contain 'branch work' x 2.
|
||||||
|
test_expect_success "git-cl status has the right description for the log" \
|
||||||
|
"$GIT_CL status --field desc | [ $( egrep -q '^branch work$' -c ) -eq 2 ]
|
||||||
|
|
||||||
|
test_expect_success "git-cl status has the right subject from message" \
|
||||||
|
"$GIT_CL status --field desc | \
|
||||||
|
[ $( egrep -q '^test$' --byte-offset) | grep '^0:' ]
|
||||||
|
|
||||||
|
test_expect_success "git-cl push ok" \
|
||||||
|
"$GIT_CL push -f"
|
||||||
|
|
||||||
|
git checkout -q master > /dev/null 2>&1
|
||||||
|
git pull -q > /dev/null 2>&1
|
||||||
|
|
||||||
|
test_expect_success "committed code has proper description" \
|
||||||
|
"git show | [ $( egrep -q '^branch work$' -c ) -eq 2 ]
|
||||||
|
|
||||||
|
test_expect_success "issue no longer has a branch" \
|
||||||
|
"git cl status | grep -q 'work: None'"
|
||||||
|
|
||||||
|
cd $GITREPO_PATH
|
||||||
|
test_expect_success "upstream repo has our commit" \
|
||||||
|
"git log master 2>/dev/null | [ $( egrep -q '^branch work$' -c ) -eq 2 ]
|
||||||
|
)
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Renaming a file should show up as a rename in the review.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initsvn
|
||||||
|
setup_gitsvn
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-svn
|
||||||
|
git config rietveld.server localhost:8080
|
||||||
|
|
||||||
|
# Create a branch, rename a file, upload it.
|
||||||
|
git checkout -q -b rename
|
||||||
|
git mv test test2
|
||||||
|
git commit -q -m "renamed"
|
||||||
|
export EDITOR=/bin/true
|
||||||
|
test_expect_success "upload succeeds" \
|
||||||
|
"$GIT_CL upload -m test master... | grep -q 'Issue created'"
|
||||||
|
|
||||||
|
# Look at the uploaded patch and verify it is a rename patch.
|
||||||
|
echo "Rename test not fully implemented yet. :("
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# We should save a change's description when an upload fails.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
# Back up any previously-saved description the user might have.
|
||||||
|
BACKUP_FILE="$HOME/.git_cl_description_backup"
|
||||||
|
BACKUP_FILE_TMP="$BACKUP_FILE.tmp"
|
||||||
|
if [ -e "$BACKUP_FILE" ]; then
|
||||||
|
mv "$BACKUP_FILE" "$BACKUP_FILE_TMP"
|
||||||
|
fi
|
||||||
|
|
||||||
|
setup_initgit
|
||||||
|
setup_gitgit
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-git
|
||||||
|
|
||||||
|
DESC="this is the description"
|
||||||
|
|
||||||
|
# Create a branch and check in a file.
|
||||||
|
git checkout -q --track -b work origin
|
||||||
|
echo foo >> test
|
||||||
|
git add test; git commit -q -m "$DESC"
|
||||||
|
|
||||||
|
# Try to upload the change to an unresolvable hostname; git-cl should fail.
|
||||||
|
export EDITOR=/bin/true
|
||||||
|
git config rietveld.server bogus.example.com:80
|
||||||
|
test_expect_failure "uploading to bogus server" "$GIT_CL upload 2>/dev/null"
|
||||||
|
|
||||||
|
# Check that the change's description was saved.
|
||||||
|
test_expect_success "description was backed up" \
|
||||||
|
"grep -q '$DESC' '$BACKUP_FILE'"
|
||||||
|
)
|
||||||
|
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
# Restore the previously-saved description.
|
||||||
|
rm -f "$BACKUP_FILE"
|
||||||
|
if [ -e "$BACKUP_FILE_TMP" ]; then
|
||||||
|
mv "$BACKUP_FILE_TMP" "$BACKUP_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check that we're able to submit from a directory that doesn't exist on the
|
||||||
|
# trunk. This tests for a previous bug where we ended up with an invalid CWD
|
||||||
|
# after switching to the merge branch.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initsvn
|
||||||
|
setup_gitsvn
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-svn
|
||||||
|
git config rietveld.server localhost:8080
|
||||||
|
|
||||||
|
# Create a branch and give it an issue.
|
||||||
|
git checkout -q -b new
|
||||||
|
mkdir dir
|
||||||
|
cd dir
|
||||||
|
echo "some work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
export EDITOR=/bin/true
|
||||||
|
test_expect_success "upload succeeds" \
|
||||||
|
"$GIT_CL upload -m test master... | grep -q 'Issue created'"
|
||||||
|
test_expect_success "git-cl dcommits ok" \
|
||||||
|
"$GIT_CL dcommit -f"
|
||||||
|
)
|
||||||
|
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Tests the "tbr" functionality, which lets you submit without uploading
|
||||||
|
# first.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initsvn
|
||||||
|
setup_gitsvn
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-svn
|
||||||
|
|
||||||
|
# We need a server set up, but we don't use it.
|
||||||
|
git config rietveld.server localhost:1
|
||||||
|
|
||||||
|
echo "some work done" >> test
|
||||||
|
git add test; git commit -q -m "work"
|
||||||
|
|
||||||
|
test_expect_success "git-cl dcommit tbr without an issue" \
|
||||||
|
"$GIT_CL dcommit -f --tbr -m 'foo-quux'"
|
||||||
|
|
||||||
|
git svn -q rebase >/dev/null 2>&1
|
||||||
|
test_expect_success "dcommitted code has proper description" \
|
||||||
|
"git show | grep -q 'foo-quux'"
|
||||||
|
|
||||||
|
test_expect_success "upstream svn has our commit" \
|
||||||
|
"svn log $REPO_URL 2>/dev/null | grep -q 'foo-quux'"
|
||||||
|
)
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,97 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Abort on error.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
PWD=`pwd`
|
||||||
|
REPO_URL=file://$PWD/svnrepo
|
||||||
|
GITREPO_PATH=$PWD/gitrepo
|
||||||
|
GITREPO_URL=file://$GITREPO_PATH
|
||||||
|
GIT_CL=$PWD/../git-cl
|
||||||
|
|
||||||
|
# Set up an SVN repo that has a few commits to trunk.
|
||||||
|
setup_initsvn() {
|
||||||
|
echo "Setting up test SVN repo..."
|
||||||
|
rm -rf svnrepo
|
||||||
|
svnadmin create svnrepo
|
||||||
|
|
||||||
|
rm -rf svn
|
||||||
|
svn co -q $REPO_URL svn
|
||||||
|
(
|
||||||
|
cd svn
|
||||||
|
echo "test" > test
|
||||||
|
svn add -q test
|
||||||
|
svn commit -q -m "initial commit"
|
||||||
|
echo "test2" >> test
|
||||||
|
svn commit -q -m "second commit"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up a git-svn checkout of the repo.
|
||||||
|
setup_gitsvn() {
|
||||||
|
echo "Setting up test git-svn repo..."
|
||||||
|
rm -rf git-svn
|
||||||
|
# There appears to be no way to make git-svn completely shut up, so we
|
||||||
|
# redirect its output.
|
||||||
|
git svn -q clone $REPO_URL git-svn >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up a git repo that has a few commits to master.
|
||||||
|
setup_initgit() {
|
||||||
|
echo "Setting up test upstream git repo..."
|
||||||
|
rm -rf gitrepo
|
||||||
|
mkdir gitrepo
|
||||||
|
|
||||||
|
(
|
||||||
|
cd gitrepo
|
||||||
|
git init -q
|
||||||
|
echo "test" > test
|
||||||
|
git add test
|
||||||
|
git commit -qam "initial commit"
|
||||||
|
echo "test2" >> test
|
||||||
|
git commit -qam "second commit"
|
||||||
|
# Hack: make sure master is not the current branch
|
||||||
|
# otherwise push will give a warning
|
||||||
|
git checkout -q -b foo
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up a git checkout of the repo.
|
||||||
|
setup_gitgit() {
|
||||||
|
echo "Setting up test git repo..."
|
||||||
|
rm -rf git-git
|
||||||
|
git clone -q $GITREPO_URL git-git
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
rm -rf gitrepo svnrepo svn git-git git-svn
|
||||||
|
}
|
||||||
|
|
||||||
|
# Usage: test_expect_success "description of test" "test code".
|
||||||
|
test_expect_success() {
|
||||||
|
echo "TESTING: $1"
|
||||||
|
exit_code=0
|
||||||
|
sh -c "$2" || exit_code=$?
|
||||||
|
if [ $exit_code != 0 ]; then
|
||||||
|
echo "FAILURE: $1"
|
||||||
|
return $exit_code
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Usage: test_expect_failure "description of test" "test code".
|
||||||
|
test_expect_failure() {
|
||||||
|
echo "TESTING: $1"
|
||||||
|
exit_code=0
|
||||||
|
sh -c "$2" || exit_code=$?
|
||||||
|
if [ $exit_code = 0 ]; then
|
||||||
|
echo "SUCCESS, BUT EXPECTED FAILURE: $1"
|
||||||
|
return $exit_code
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Grab the XSRF token from the review server and print it to stdout.
|
||||||
|
print_xsrf_token() {
|
||||||
|
curl --cookie dev_appserver_login="test@example.com:False" \
|
||||||
|
--header 'X-Requesting-XSRF-Token: 1' \
|
||||||
|
http://localhost:8080/xsrf_token 2>/dev/null
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initgit
|
||||||
|
setup_gitgit
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-git
|
||||||
|
git checkout -q -b work HEAD^
|
||||||
|
git checkout -q -t -b work2 work
|
||||||
|
echo "some work done on a branch that tracks a local branch" >> test
|
||||||
|
git add test; git commit -q -m "local tracking branch work"
|
||||||
|
|
||||||
|
git config rietveld.server localhost:8080
|
||||||
|
|
||||||
|
# Prevent the editor from coming up when you upload.
|
||||||
|
export EDITOR=/bin/true
|
||||||
|
test_expect_success "upload succeeds (needs a server running on localhost)" \
|
||||||
|
"$GIT_CL upload -m test | grep -q 'Issue created'"
|
||||||
|
)
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_initgit
|
||||||
|
setup_gitgit
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
cd git-git
|
||||||
|
git checkout -q -b work HEAD^
|
||||||
|
echo "some work done on a branch" >> test
|
||||||
|
git add test; git commit -q -m "branch work"
|
||||||
|
|
||||||
|
git config rietveld.server localhost:8080
|
||||||
|
|
||||||
|
# Prevent the editor from coming up when you upload.
|
||||||
|
export EDITOR=/bin/true
|
||||||
|
test_expect_success "upload succeeds (needs a server running on localhost)" \
|
||||||
|
"$GIT_CL upload -m test | grep -q 'Issue created'"
|
||||||
|
|
||||||
|
test_expect_failure "description shouldn't contain unrelated commits" \
|
||||||
|
"$GIT_CL status | grep -q 'second commit'"
|
||||||
|
)
|
||||||
|
SUCCESS=$?
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
if [ $SUCCESS == 0 ]; then
|
||||||
|
echo PASS
|
||||||
|
fi
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue