114 Commits

Author SHA1 Message Date
Cedric Brandily
44707a1e79 Use git push-url instead of a second remote
Having a gerrit remote means that we fetch changes twice. It's also
not necessary since the push-url can be set on the origin remote. As
a first step, add a config option that changes the default for defaultremote
to origin and then reworks the logic to add the remote url to origin as a
push-url instead of creating a gerrit remote.

Since this will cause people with an existing gerrit remote to have a
push url added and the gerrit remote orpahned, a follow on commit will
come that will look for a gerrit remote and, if it exists, use it as the
source of url for the push-url and then delete the old remote.

Change-Id: Ief5d092a796516de9605b7df64e7b902c3b47351
2015-07-21 12:21:25 +00:00
Jenkins
7ff674a3d0 Merge "Don't parse git log header for topic" 2015-06-20 14:11:56 +00:00
Benjamin Pflanz
d80b6cb346 Don't parse git log header for topic
When looking for candidate topic in bug or blueprint ID, get the
git log  without header lines, e.g., commit hash, author, committer,
dates, so that accidental matches such as commit hash (which could look
like a bug ID) or user name (which could look like anything) don't
accidentally get taken as the topic.

Change-Id: Ie45ed7509e7f873e566f078b55cadd547da704dd
Closes-Bug: #2000296
2015-06-18 13:22:37 -04:00
Jeremy Stanley
55a91a6655 Fix H238 violation and enable check for that rule
Change-Id: I04f3d96acfc0be12393cc6cf5f0d3f7006939532
2015-06-17 00:53:01 +00:00
Jenkins
d1266ee0a5 Merge "Add reviewers on upload" 2015-06-12 17:31:43 +00:00
Jenkins
bde9e28e72 Merge "get_remote_url(): also honor url.*.pushInsteadOf" 2015-06-12 15:32:26 +00:00
Jenkins
5df45d4fd2 Merge "Switch to requests to support proxying of 'https'" 2015-06-12 15:16:04 +00:00
Michael Pratt
bb7395009d Add reviewers on upload
Add the --reviewers argument which allows specifying reviewers to be
added to each patch uploaded.  This simplifies the upload process by not
requiring an additional step of adding reviewers to changes.

Gerrit supports specifying reviewers to be added to changes by appending
a list of r='email' options to the refspec being pushed to.  For
example, from the Gerrit 'Uploading Changes' documentation:

git push tr:kernel/common HEAD:refs/for/experimental%r=a@a.com,cc=b@o.com

The --reviewers argument can be passed multiple reviewers to add to the
patch set.  Reviewers containing whitespace are rejected, as whitespace
cannot be added to the refspec.

Change-Id: I8c2f9453a90dd78aa47f7996f2502f9f6cf2d66d
2015-06-12 14:37:42 +00:00
Jenkins
84fc10f563 Merge "Add utf-8 char support" 2015-06-12 14:29:35 +00:00
Jeremy Stanley
0bb2461a2c Override E-mail in Gerrit integration tests
On test platforms where the default hostname is not an FQDN, git
fails to guess a usable E-mail address. We don't actually care what
E-mail address these tests see, so override it with a known working
value.

Change-Id: Id65af4876b9658c34a10d1a8f5c72813830725c4
2015-06-03 21:06:12 +00:00
Jenkins
9b611d7b67 Merge "Provide an explanation on failed rebase" 2015-05-28 00:22:31 +00:00
Jenkins
9f3bc5909f Merge "Isolate tests from user/system git configuration" 2015-05-27 23:45:52 +00:00
James E. Blair
e64e500234 Provide an explanation on failed rebase
It is not clear why git-review might attempt a rebase and fail,
so provide a helpful error message with suggested next steps in
that case.

Co-Authored-By: Clark Boylan <clark.boylan@gmail.com>
Change-Id: I195554ed5c577c39687d9001a177dadf107bab61
2015-05-27 19:37:28 +00:00
Darragh Bailey
48d6059a5f Switch to requests to support proxying of 'https'
Convert to using the requests module which supports proxying of 'https'
connections for retriving the gerrit war file when behind a corporate
proxy.

Change-Id: Id368cb6aa7058970ad6ac10caacea2aec9bfe48b
2015-05-19 18:28:06 +01:00
Darragh Bailey
f78f328b17 Use plumbing rev-parse to get the branch name
Git plumbing command rev-parse is able to return the current branch
symbolic name in a machine readable manner and will return the rev
inputted (HEAD in this case) if no corresponding branch can be found
(detached HEAD).

This works on all versions of git since 1.6.3 and alternatively can be
replaced with 'git symbolic-ref --short -q HEAD' on versions 1.7.10 and
newer.

Change-Id: I486dcad4b73f9f06d7196e6888a4da79c7d574ad
2015-05-05 14:43:33 +01:00
Darragh Bailey
f5bb6e06fd Isolate tests from user/system git configuration
Prevent user or system configuration from impacting the output of git
commands through custom configuration options. Example is enabling of
"branch.autosetuprebase=always" will result a different message being
outputted by git when creating branches causing some tests to fail when
attempting to match against the expected output.

Change-Id: Ic6526217b598abfef0a272bc7cd1852c5821163a
2015-05-04 22:56:48 +01:00
Monty Taylor
a13b7a9d77 Push language override down into the cmd wrapper
There are more things that break if we run git with i18n on. Make sure
that we always set LANG and LANGUAGE to C so that we get predictable
output.

Change-Id: I1bf1124f0b09d6658a7b0703e3b9e74ed80f4eea
2015-05-04 17:08:31 +00:00
Jenkins
f4f6674c9c Merge "Choose tracked branch for rebase when submitting" 2015-04-13 18:43:07 +00:00
Dmitry Ratushnyy
fbdff3245e git review -sv gets more verbose
Sometimes it's difficult to understand reason
why git review -s failed since error description
in code is not streamed to stdout.

Change-Id: I59c0deef5f32d10f9e3e7c50dbaffc6a9f59a466
Closes-Bug: #2000234
2015-04-09 19:59:13 +03:00
liuyang1
f422005d19 Add utf-8 char support
git-review list cannot show CL whose subject contain utf-8 char.

Implements: encode as utf-8
Change-Id: Ifa743e2ac95880172dfa52e160ae8aabaae8f337
2015-04-03 08:46:15 +08:00
Michael Johnson
7da7c37170 Choose tracked branch for rebase when submitting
When choosing the branch to submit a changeset against, and
against which to rebase a changeset if it is being rebased, a new
gerrit.track configuration item and corresponding --track command
line option indicate to use the upstream branch being tracked as the
source of branch information, in preference to configuration. When
downloading a changeset, always set it up to track the matching
remote branch to make --track work for downloaded changesets.
If a branch name is provided explicitly on the command line, it
overrides the tracked branch.

Rationale:

Workflows with multiple active branches are common.  For example,
there may be one development branch (master) and multiple branches
representing prior releases to which bug fixes are still being
made.  Then a common workflow is to fix bugs in the earliest
affected branch still maintained and merge forward or cherry-pick
to master.  The commits being made to the earlier released branches
should not be rebased against master.

A typical usage pattern in this workflow is:

    git checkout -b my-feature origin/master
    ... implement feature ...
    git review -f

    git checkout -b my-bug-fix origin/maintenancebranch
    ... implement bug fix ...
    git review -f maintenancebranch

    git checkout -b my-bug-fix-merge origin/master
    git merge maintenancebranch / git cherry-pick -x ... / git review -x ...
    git review -f

The developer, who is usually implementing features and therefore
used to working against master, may accidentally forget to name
the release branch when running git review for the bug fix to the
release branch.  Mananging .gitreview files across branches and
repositories scales poorly with larger numbers of repositories
and branches and can be vulnerable to missed bad merges altering
configuration to point at wrong branches.

This change rebases changesets against the tracked remote and branch,
or if no branch is tracked, against the previously-specified branch,
instead of against <defaultremote>/master, only if gerrit.track has
been set to true.  With this change, the developer can safely omit
to specify the branch name when committing changes to non-default
branches such as "maintenancebranch" in the example.

When downloading a changeset, it will always be set up to track the
matching remote branch.  That way, whether or not the gerrit.track
configuration item is set when the changeset is downloaded, the right
branch will be chosen when it is submitted if gerrit.track is set
after the changeset is downloaded, or if the --track command line
option is specified.

Closes-Bug: #883176
Story: #883176
Story: #2000176
Change-Id: I25f22b9e3cda38598681d720a2f2ac534baec5a6
2015-03-18 09:17:34 -04:00
Jenkins
79262a5230 Merge "Support authentication in run_http_exc" 2015-03-17 17:25:24 +00:00
Anders Kaseorg
ae4b4f2f90 get_remote_url(): also honor url.*.pushInsteadOf
As a follow up to https://review.openstack.org/109851, we also need to
respect the "url.<base>.pushInsteadOf" setting like git remote show
did.

Change-Id: I6c4cb9e11dcc5f096af03b2b2356216365eaf111
2015-03-01 05:19:57 -05:00
Cedric Brandily
910ffddd1b Support authentication in run_http_exc
Authentication could be required when performing REST API authenticated
queries over http(s) (done by run_http_exc). Typically, it appends with
gerrit behind apache2.

This change queries git credential for gerrit password when http request
returns a 401.

Change-Id: Iad60eea938c42210ba8c5df4a1b76f8d2f4dd76d
2015-02-27 16:17:35 +01:00
Jenkins
80f7cd2c0a Merge "get_remote_url(): honor any "url.<base>.insteadOf" config setting" 2015-02-07 01:01:41 +00:00
Jenkins
0861f1fa88 Merge "Handle correctly http error raise in run_http_exc" 2014-12-30 17:08:43 +00:00
Jenkins
63d9ceffb8 Merge "Update tests to use Gerrit 2.9.2" 2014-12-30 17:04:29 +00:00
Cedric Brandily
0393c989ae Handle correctly http error raise in run_http_exc
Currently http errors are raised inside a try bloc and transformed in
a more generic exception. This change raises http errors outside the
try bloc.

Change-Id: Iece270ac84925625e848f3049072f39e19e068cc
2014-12-22 15:01:04 +01:00
Jenkins
0a1c1b0a86 Merge "Use 'no_proxy' env variable in addition to uppercase" 2014-12-19 14:23:43 +00:00
Jenkins
f3e623f115 Merge "Convert add_remote to use GitReviewExceptions" 2014-12-19 14:08:30 +00:00
Jenkins
0e37367426 Merge "Enable color support based on tty and config" 2014-12-19 14:08:20 +00:00
Julien Danjou
b88055350a Fix encoding header
The encoding header is semi-invalid has the encoding name should be
"utf-8" and not "utf8", which is not the official name of the encoding
and is not recognized by all tools.

Change-Id: I4db673fe86f643f5e1b3e5135d8b0cb72407253e
2014-12-08 11:54:59 +01:00
Michael Pratt
c894704cb7 Update tests to use Gerrit 2.9.2
Gerrit 2.9 adds the '--all-reviewers' option to 'gerrit query', which
allows testing that reviewers have been successfully added to a patch
set in tests for new reviewer functionality.

Change-Id: I17f37c8fd46578b4a8cbfacee4eb8073972b2eee
2014-12-04 14:37:27 -05:00
Darragh Bailey
e2bd0f5f3c Use 'no_proxy' env variable in addition to uppercase
Need to override both variations of the no_proxy environment variable
since some tools do not check for the other if one is already defined.

While 'no_proxy' appears to be now the most common convention, it is
safer to set both lower and upper case to the same value when running
unit tests.

Change-Id: I536b6f2711ac70e0a2a45676098fb461ab3b8d33
2014-12-03 14:38:31 +00:00
Darragh Bailey
7f69ada396 Enable color support based on tty and config
Use the git config command and provided options to have git detect
whether color support should be enabled or disabled. Additionally ensure
that git-review color support can be controlled separately via the
option 'color.review', while still falling back to 'color.ui' if the app
specific option is not defined.

This will ensure that when piping or redirecting the output that colour
output will be disabled unless color.review, or it's fallback color.ui,
is set to always.

Also by utilizing 'git config', the any config options specified on the
command line that change behaviour will be adhered to. e.g.

  git -c color.review=never review -l

Will always output without color enabled.

Change-Id: I8f83ed8623da88e87972109af956331704e15d38
Closes-Bug: #1097961
2014-11-26 20:35:09 +00:00
JC Delay
c87ff1a8e1 get_remote_url(): honor any "url.<base>.insteadOf" config setting
git-review retrieved the remote URL based on the output of git-config.
However, contrary to the previous implementation based on
git-remote-show, git-config does not expand the URL of the given remote
taking into account any "url.<base>.insteadOf" config setting.

This change adds the necessary circuitry to expand URLs.
It also adds a regression test.

Change-Id: I826251aaf85d1b1e8bb2b4562e4b65025a7091b9
Closes-Bug: #1348634
2014-11-26 14:32:45 +01:00
K Jonathan Harker
4e40ede085 Convert add_remote to use GitReviewExceptions
By using the GitReviewException class and subclasses, the raised exceptions
will be caught in main() and properly handled. One Exception can be
converted to a CommandFailed exception, and the other is simple enough
to not need a subclass of GitReviewException.

Change-Id: Idb02d43fd480ab67493c757fb95431602239a55f
2014-11-17 12:25:21 -08:00
Cedric Brandily
1bc87f26d6 Prefer git-config over git-review config files
git-review gets its configuration from multiple sources (by priority):

 * command line options
 * git-config
  * options: username, rebase
  * with local/global/system config
 * git-review config files
  * options: scheme, host, port, project, defaultbranch/remote/rebase
  * locally using .gitreview
  * globally using ~/.config/gitreview/git-review.conf
  * system using /etc/git-review/git-review.conf

.gitreview file is commonly provided versioned in the git repo, where
other git-review config files and git-config is done by developers. It
implies for developers multiple places to define local/global/system
configuration options but some can only be changed by updating
.gitreview (scheme/port...) which is under versioning.

This change proposes to use as configuration sources (by priority):

 * command line options
 * git-config for developer local/global/system config
  * options: username, rebase and all .gitreview options
 * .gitreview local file for repo provided specific config

and deprecates git-review global/system files in order to reduce
configuration sources and allow to overload .gitreview configuration
without updating it.

Change-Id: I24aba0fa089de57d51a79049d9c192f76d576f69
2014-11-17 20:36:37 +01:00
Cedric Brandily
abe76bfe28 Isolate tests from user/system config
git-review behavior depends on git local, global and system configs.
tests have the same dependencies against them but only manage git local
config which implies the config expected by tests could not be the real
one because of git global and system configs.

The same trouble concerns gitreview global and system config files.

This change allows to run git-review in local mode (only using git and
gitreview local config files) by defining the environment variable
"GITREVIEW_LOCAL_MODE". This mode is used by tests to isolate them from
git and gitreview global and system configs. Mocking can not be used as
functional tests call not git-review code but git-review system command.

Change-Id: I598a284aec9e55f9618ab026c55ef0435e370d69
Closes-Bug: #1393192
2014-11-17 17:44:33 +01:00
Jenkins
e31646b3f2 Merge "Define -T/--no-topic to disable review submit with topic" 2014-10-13 19:36:03 +00:00
Jenkins
b5c52cddec Merge "-F/--force-rebase has no effect if rebase is disabled by config" 2014-10-13 14:04:39 +00:00
Cedric Brandily
856ccd958b Align git-review and python -m git_review.cmd behaviors
Currently, python -m git_review.cmd wraps git_review.cmd.main call to
handle correctly unicode in python2 where git-review calls directly
git_review.cmd.main. This change embeds the wrapper inside main in
order to align git-review and python -m git_review.cmd behaviors.

Change-Id: I390e2d68b851299c3b07292b89dee8198068e6aa
2014-09-04 14:24:59 +02:00
Cedric Brandily
9f389bfec6 Define -T/--no-topic to disable review submit with topic
The option -T/--no-topic disables review with topic (mutually
exclusive with -t/--topic).

It allows to submit:

* a change without your current branch name as topic,
* a change update without updating current topic.

Change-Id: I06309b14246cb455d55c6833ab6adb932995edfa
2014-09-03 21:28:12 +02:00
Cedric Brandily
18f34f0cbc -F/--force-rebase has no effect if rebase is disabled by config
--force-rebase has no effect if rebase is disabled through git-config
or git-review config files.

This change ensures -F/--force-rebase "wins" over rebase disabled and
-F/--force-rebase becomes mutually exclusive with -R/--no-rebase.

Change-Id: Idd985a6a7a5b1cffa9bed996bb1ea5907e7d0844
2014-09-03 19:55:05 +02:00
Cedric Brandily
9b9c47f0a2 Remove useless constants
Change-Id: I380dc0ebce2af0636a9bab5901aa9abdae4eb320
2014-08-16 13:13:42 +02:00
Jenkins
499a2f3dbc Merge "Improve windows support for git-review --setup" 2014-08-05 13:17:47 +00:00
julien.marinfrisonroche
8f50043a24 Improve windows support for git-review --setup
If git-review is not run in git repo top-level dir, then the target
path used for scp uses both "/" and "\", and scp fails.

Change-Id: I8ffe163f9e29423b1c19bd54241a526a9843561f
Closes-Bug: #1024073
2014-07-30 17:56:39 +02:00
Jenkins
0a91b0baee Merge "Avoid a stacktrace when no reviews are pending" 2014-07-29 18:50:48 +00:00
Jenkins
5688e715a5 Merge "Enabled hacking checks H305 and H307" 2014-07-29 18:46:35 +00:00
Jenkins
6a9d172604 Merge "Prevent long subjects in reviews causing spurious blank lines" 2014-07-25 11:36:37 +00:00