Download specific Patch Set for Review
Adds ability to request download and checkout of specific review-patchset using syntax: git review -d <reviewId>,<patchsetNumber> It will create and checkout the <author>/<topic>-patch<number> branch. Change-Id: Idaf57acb1464e1e71a436d741ae889494a91d446
This commit is contained in:
parent
eae8ead205
commit
e23ca3848e
1
AUTHORS
1
AUTHORS
@ -5,3 +5,4 @@ Kiall Mac Innes <kiall@managedit.ie>
|
|||||||
Roan Kattouw <roan.kattouw@gmail.com>
|
Roan Kattouw <roan.kattouw@gmail.com>
|
||||||
Antoine Musso <hashar@free.fr>
|
Antoine Musso <hashar@free.fr>
|
||||||
Yuriy Taraday <yorik.sar@gmail.com>
|
Yuriy Taraday <yorik.sar@gmail.com>
|
||||||
|
Pavel Sedlák <psedlak@redhat.com>
|
||||||
|
@ -49,6 +49,10 @@ If you want to download change 781 from gerrit to review it::
|
|||||||
|
|
||||||
git review -d 781
|
git review -d 781
|
||||||
|
|
||||||
|
If you want to download patchset 4 for change 781 from gerrit to review it::
|
||||||
|
|
||||||
|
git review -d 781,4
|
||||||
|
|
||||||
If you just want to do the commit message and remote setup steps::
|
If you just want to do the commit message and remote setup steps::
|
||||||
|
|
||||||
git review -s
|
git review -s
|
||||||
|
37
git-review
37
git-review
@ -639,12 +639,12 @@ class CannotQueryPatchSet(CommandFailed):
|
|||||||
EXIT_CODE = 34
|
EXIT_CODE = 34
|
||||||
|
|
||||||
|
|
||||||
class PatchSetInformationNotFound(ChangeSetException):
|
class ReviewInformationNotFound(ChangeSetException):
|
||||||
"Could not fetch review information for change %s"
|
"Could not fetch review information for change %s"
|
||||||
EXIT_CODE = 35
|
EXIT_CODE = 35
|
||||||
|
|
||||||
|
|
||||||
class PatchSetNotFound(ChangeSetException):
|
class ReviewNotFound(ChangeSetException):
|
||||||
"Gerrit review %s not found"
|
"Gerrit review %s not found"
|
||||||
EXIT_CODE = 36
|
EXIT_CODE = 36
|
||||||
|
|
||||||
@ -656,6 +656,11 @@ Does specified change number belong to this project?"""
|
|||||||
EXIT_CODE = 37
|
EXIT_CODE = 37
|
||||||
|
|
||||||
|
|
||||||
|
class PatchSetNotFound(ChangeSetException):
|
||||||
|
"Review patchset %s not found"
|
||||||
|
EXIT_CODE = 38
|
||||||
|
|
||||||
|
|
||||||
class CheckoutNewBranchFailed(CommandFailed):
|
class CheckoutNewBranchFailed(CommandFailed):
|
||||||
"Cannot checkout to new branch"
|
"Cannot checkout to new branch"
|
||||||
EXIT_CODE = 64
|
EXIT_CODE = 64
|
||||||
@ -685,12 +690,19 @@ def fetch_review(review, masterbranch, remote):
|
|||||||
else:
|
else:
|
||||||
userhost = "%s@%s" % (username, hostname)
|
userhost = "%s@%s" % (username, hostname)
|
||||||
|
|
||||||
|
review_arg = review
|
||||||
|
patchset_number = None
|
||||||
|
patchset_opt = '--current-patch-set'
|
||||||
|
if ',' in review:
|
||||||
|
review, patchset_number = review.split(',')
|
||||||
|
patchset_opt = '--patch-sets'
|
||||||
|
|
||||||
review_info = None
|
review_info = None
|
||||||
output = run_command_exc(
|
output = run_command_exc(
|
||||||
CannotQueryPatchSet,
|
CannotQueryPatchSet,
|
||||||
"ssh", "-x", port, userhost,
|
"ssh", "-x", port, userhost,
|
||||||
"gerrit", "query",
|
"gerrit", "query",
|
||||||
"--format=JSON --current-patch-set change:%s" % review)
|
"--format=JSON %s change:%s" % (patchset_opt, review))
|
||||||
|
|
||||||
review_jsons = output.split("\n")
|
review_jsons = output.split("\n")
|
||||||
found_review = False
|
found_review = False
|
||||||
@ -705,12 +717,19 @@ def fetch_review(review, masterbranch, remote):
|
|||||||
if not found_review:
|
if not found_review:
|
||||||
if VERBOSE:
|
if VERBOSE:
|
||||||
print(output)
|
print(output)
|
||||||
raise PatchSetInformationNotFound(review)
|
raise ReviewInformationNotFound(review)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
refspec = review_info['currentPatchSet']['ref']
|
if patchset_number is None:
|
||||||
|
refspec = review_info['currentPatchSet']['ref']
|
||||||
|
else:
|
||||||
|
refspec = [ps for ps
|
||||||
|
in review_info['patchSets']
|
||||||
|
if ps['number'] == patchset_number][0]['ref']
|
||||||
|
except IndexError:
|
||||||
|
raise PatchSetNotFound(review_arg)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise PatchSetNotFound(review)
|
raise ReviewNotFound(review)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
topic = review_info['topic']
|
topic = review_info['topic']
|
||||||
@ -722,7 +741,11 @@ def fetch_review(review, masterbranch, remote):
|
|||||||
author = re.sub('\W+', '_', review_info['owner']['name']).lower()
|
author = re.sub('\W+', '_', review_info['owner']['name']).lower()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
author = 'unknown'
|
author = 'unknown'
|
||||||
branch_name = "review/%s/%s" % (author, topic)
|
|
||||||
|
if patchset_number is None:
|
||||||
|
branch_name = "review/%s/%s" % (author, topic)
|
||||||
|
else:
|
||||||
|
branch_name = "review/%s/%s-patch%s" % (author, topic, patchset_number)
|
||||||
|
|
||||||
print("Downloading %s from gerrit" % refspec)
|
print("Downloading %s from gerrit" % refspec)
|
||||||
run_command_exc(PatchSetGitFetchFailed,
|
run_command_exc(PatchSetGitFetchFailed,
|
||||||
|
20
git-review.1
20
git-review.1
@ -46,6 +46,12 @@ designed to make it easier to apprehend Gerrit, especially for
|
|||||||
users that have recently switched to Git from another version
|
users that have recently switched to Git from another version
|
||||||
control system.
|
control system.
|
||||||
.Pp
|
.Pp
|
||||||
|
.Ar change
|
||||||
|
can be changeNumber as obtained using
|
||||||
|
.Fl --list
|
||||||
|
option, or it can be changeNumber,patchsetNumber for fetching exact patchset from the change.
|
||||||
|
In that case local branch will get -patch[patchsetNumber] suffix.
|
||||||
|
.Pp
|
||||||
The following options are available:
|
The following options are available:
|
||||||
.Bl -tag -width indent
|
.Bl -tag -width indent
|
||||||
.It Fl d Ar change , Fl -download= Ns Ar change
|
.It Fl d Ar change , Fl -download= Ns Ar change
|
||||||
@ -197,6 +203,8 @@ Cannot fetch information about the changeset to be downloaded.
|
|||||||
Changeset not found.
|
Changeset not found.
|
||||||
.It 37
|
.It 37
|
||||||
Particular patchset cannot be fetched from the remote git repository.
|
Particular patchset cannot be fetched from the remote git repository.
|
||||||
|
.It 38
|
||||||
|
Specified patchset number not found in the changeset.
|
||||||
.It 64
|
.It 64
|
||||||
Cannot checkout downloaded patchset into the new branch.
|
Cannot checkout downloaded patchset into the new branch.
|
||||||
.It 65
|
.It 65
|
||||||
@ -239,6 +247,18 @@ $ git branch
|
|||||||
Gerrit looks up both name of the author and the topic name from Gerrit
|
Gerrit looks up both name of the author and the topic name from Gerrit
|
||||||
to name a local branch. This facilitates easier identification of changes.
|
to name a local branch. This facilitates easier identification of changes.
|
||||||
.Pp
|
.Pp
|
||||||
|
To fetch a remote patchset number 5 from change number 3004:
|
||||||
|
.Pp
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
$ git-review -d 3004,5
|
||||||
|
Downloading refs/changes/04/3004/5 from gerrit into
|
||||||
|
review/someone/topic_name-patch5
|
||||||
|
Switched to branch 'review/someone/topic_name-patch5
|
||||||
|
$ git branch
|
||||||
|
master
|
||||||
|
* review/author/topic_name-patch5
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
To send a change for review and delete local branch afterwards:
|
To send a change for review and delete local branch afterwards:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
$ git-review -f
|
$ git-review -f
|
||||||
|
Loading…
x
Reference in New Issue
Block a user