Page MenuHomePhabricator

"git review -d XXX" doesn't work for http gerrit
Closed, DeclinedPublic

Description

Output follows. Looks like it is expecting some python scripts to be in place.

mah@flynn: HitCounters$ git review -d 202629
Traceback (most recent call last):
  File "/usr/local/bin/git-review", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/git_review/cmd.py", line 1180, in main
    local_branch = fetch_review(options.changeidentifier, branch, remote)
  File "/usr/local/lib/python2.7/dist-packages/git_review/cmd.py", line 886, in fetch_review
    parse_exc=ReviewInformationNotFound)
  File "/usr/local/lib/python2.7/dist-packages/git_review/cmd.py", line 416, in query_reviews
    parse_exc=parse_exc)
  File "/usr/local/lib/python2.7/dist-packages/git_review/cmd.py", line 434, in query_reviews_over_http
    request = run_http_exc(exception, url)
  File "/usr/local/lib/python2.7/dist-packages/git_review/cmd.py", line 175, in run_http_exc
    raise klazz(255, str(err), ('GET', url), env)
git_review.cmd.CannotQueryPatchSet: Cannot query patchset information
The following command failed with exit code 255
    "GET https://gerrit.wikimedia.org/changes/?q=202629&o=CURRENT_REVISION"
-----------------------
Cannot query patchset information
The following command failed with exit code 104
    "GET https://gerrit.wikimedia.org/changes/?q=202629&o=CURRENT_REVISION"
-----------------------
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /changes/ was not found on this server.</p>
</body></html>

-----------------------
-----------------------
mah@flynn: HitCounters$

Event Timeline

MarkAHershberger raised the priority of this task from to Needs Triage.
MarkAHershberger updated the task description. (Show Details)
MarkAHershberger added a project: Gerrit.

I think this might be a duplicate - it's been annoying me for a long while.

@Krenair, thanks. If you find it, merge this one with the one it dupes. If you could, I'd like to get you to review the documentation I'm going to write for people behind firewalls that need to commit to gerrit.

@demon ping :)

Friends don't let friends use git-review :p

hashar claimed this task.

The reason for the failure is that git-review uses the wrong Gerrit base path: https://gerrit.wikimedia.org/ . It is missing the trailing /r/ . But if you add it it works just fine:

https://gerrit.wikimedia.org/r/changes/?q=202629&o=CURRENT_REVISION
                             ^

The root cause is git-review looks at the remote URL then does:

>>> import urlparse
>>> urlparse.urljoin( 'https://gerrit.wikimedia.org/r/p/mediawiki/core.git', '/changes/' )
'https://gerrit.wikimedia.org/changes/'
>>>

https://docs.python.org/2/library/urlparse.html#urlparse.urljoin

So git-review expect the Gerrit base path to be at the root / when our setup namespaces it under /r/'.

The workaround are:

  • use the ssh:// protocol for review
  • fetch patches manually (eg: git fetch origin refs/changes/DE/ABCDE && git checkout FETCH_HEAD

The fix would be to add support in git-review to specify the base path fragment which would be appended to the scheme + host. Feel free to report it upstream. Meanwhile I am closing this task since the supported way is to use ssh.

hashar writes:

The fix would be to add support in git-review to specify the base
path fragment which would be appended to the scheme + host. Feel free
to report it upstream. Meanwhile I am closing this task since the
supported way is to use ssh.

An alternative fix: don't depend on "git review -s" to set up gerrit.
Instead, the following set up works:

$ curl https://gerrit.wikimedia.org/r/tools/hooks/commit-msg > .git/hooks; chmod +x .git/hooks/commit-msg
$ git remote add gerrit https://USER@gerrit.wikimedia.org/r/p/PROJECT

After that "git review -d XXXX" should work.

Found it

https://github.com/openstack-infra/git-review/blob/67dbbc2e59b0b104c9de0a8ab1d39ca54e9845ca/git_review/cmd.py#L571

Probably want to add either /r/ on the end of the URL in the git review file. Or add a new prefix config to prefix the url.

Hm, I'm seeing this even with the gerrit remote set to ssh:// -- it appears that your origin remote also has to be via ssh (not https) in order for gerrit to be happy.

The workaround are:

  • use the ssh:// protocol for review
  • fetch patches manually (eg: git fetch origin refs/changes/DE/ABCDE && git checkout FETCH_HEAD

@hashar: Could you explain these workarounds for those of us that aren't as git proficient? For example, what is the "DE/ABCDE"? And how does one use the ssh:// protocol for review? Would that be something like:
git remote set-url origin ssh://kaldari@gerrit.wikimedia.org:29418/mediawiki/...?

@kaldari sure thing!

fetch patches manually (eg: git fetch origin refs/changes/DE/ABCDE && git checkout FETCH_HEAD

ref/changes/DE/ABCDE is the git reference for an hypothetical change ABCDE.

On a change web page, on the top right there is a Download link. Clicking on it brings a popup that gives you command line to cherry-pick / checkout patches. Eg:

https://gerrit.wikimedia.org/r/#/c/320200/

git fetch https://gerrit.wikimedia.org/r/operations/mediawiki-config refs/changes/00/320200/3 && git checkout FETCH_HEAD

use the ssh:// protocol for review

That all depends on your git-review version. IIRC with 1.25, it would setup and use the a git remote named gerrit. You would thus have something like:

$ git remote -v
origin	https://gerrit.wikimedia.org/r/p/mediawiki/core.git (fetch)
origin	https://gerrit.wikimedia.org/r/p/mediawiki/core.git (push)
gerrit	ssh://hashar@gerrit.wikimedia.org:29418/mediawiki/core.git (push)
gerrit	ssh://hashar@gerrit.wikimedia.org:29418/mediawiki/core.git (fetch)

You can change a remote url with eg:

git remote set-url gerrit ssh://gerrit.wikimedia.org:29418/mediawiki/core.git

git-review 1.25 is the last tagged version. It is two years old and lack a few nice feature introduced meanwhile. My recommandation is to run it from sources!

Install

Install the python package manager system:
sudo apt-get install python-pip

Get the source:
git clone https://git.openstack.org/openstack-infra/git-review

Get the python package system to craft a git-review command in your home directory and pointing to that source tree.

cd git-review
pip install --user -e .

That should install the script as ~/.local/bin/git-review. Add that path to your PATH:
PATH="~/.local/bin:$PATH"

Config

git-review looks at setting in .gitconfig. You would want to configure your username and enable some features introduced after git-review v1.25 got tagged:

git config ---global gitreview.username kaldari
git config ---global gitreview.usepushurl 1
git config ---global gitreview.track 1

Where:

gitreview.username is your ssh account for Gerrit

gitreview.usepushurl

Use remote push-url logic instead of separate remotes

With that, git-review would no more use a gerrit remote. Instead it will configure the origin remote with a push-url pointing to ssh:// . Example:

$ git remote -v
origin	https://gerrit.wikimedia.org/r/p/mediawiki/core.git (fetch)
origin	ssh://gerrit.wikimedia.org:29418/mediawiki/core.git (push)

Thus you would fetch over HTTP put push over ssh with authentication.

gitreview.track

Use tracked branch as default.

I think git-review default to push to master branch, and we had .gitreview files to explicitly mention the branch. With track git-review looks at the remote tracked branch and would use that, that is 99% of the time what you intend to do.

Conclusion

As always, you can dry-run / verbose a run which is the best way to understand how it works:

git-review -n -v

At some point I should probably copy my previous comment T100987#3353888 to the wiki :-]