Add --branch option on the review ssh command
The review command allows the patch set to be specified by the commit's sha1 revision. It is possible that the revision does not identify a unique change if the same sha1 has been pushed to more than one project or to more than one branch of the same project. This causes the review to fail with an error. The results can be narrowed down to a specific project by using the --project option, but it will still fail if the sha1 is on more than one branch in the same project. Add a new --branch option that allows to narrow down the results by branch. Bug: Issue 1752 Change-Id: I555dc9de1b092e7562f5d99c4c60df589935a47f
This commit is contained in:
parent
c42cea2c8d
commit
2ede20d73d
@ -10,6 +10,7 @@ SYNOPSIS
|
||||
--
|
||||
'ssh' -p <port> <host> 'gerrit review'
|
||||
[--project <PROJECT> | -p <PROJECT>]
|
||||
[--branch <BRANCH> | -b <BRANCH>]
|
||||
[--message <MESSAGE> | -m <MESSAGE>]
|
||||
[--notify <NOTIFYHANDLING> | -n <NOTIFYHANDLING>]
|
||||
[--submit | -s]
|
||||
@ -34,6 +35,9 @@ If a patch set is specified with the 'COMMIT' format, the complete
|
||||
or abbreviated commit SHA-1 may be used. If the same commit is available
|
||||
in multiple projects the `--project` option may be used to limit where
|
||||
Gerrit searches for the change to only the contents of the specified project.
|
||||
If the same commit is available in multiple branches the `--branch` option
|
||||
may be used to limit where Gerrit searches for changes to only the specified
|
||||
branch.
|
||||
|
||||
|
||||
OPTIONS
|
||||
@ -45,6 +49,12 @@ OPTIONS
|
||||
within. This option must be supplied before the commit
|
||||
SHA-1 in order to take effect.
|
||||
|
||||
--branch::
|
||||
-b::
|
||||
Name of the branch the intended changes are contained
|
||||
within. This option must be supplied before the commit
|
||||
SHA-1 in order to take effect.
|
||||
|
||||
--message::
|
||||
-m::
|
||||
Optional cover letter to include as part of the message
|
||||
|
@ -91,6 +91,9 @@ public class ReviewCommand extends SshCommand {
|
||||
@Option(name = "--project", aliases = "-p", usage = "project containing the specified patch set(s)")
|
||||
private ProjectControl projectControl;
|
||||
|
||||
@Option(name = "--branch", aliases = "-b", usage = "branch containing the specified patch set(s)")
|
||||
private String branch;
|
||||
|
||||
@Option(name = "--message", aliases = "-m", usage = "cover message to publish on change(s)", metaVar = "MESSAGE")
|
||||
private String changeComment;
|
||||
|
||||
@ -354,7 +357,7 @@ public class ReviewCommand extends SshCommand {
|
||||
final Set<PatchSet> matches = new HashSet<PatchSet>();
|
||||
for (final PatchSet ps : patches) {
|
||||
final Change change = db.changes().get(ps.getId().getParentKey());
|
||||
if (inProject(change)) {
|
||||
if (inProject(change) && inBranch(change)) {
|
||||
matches.add(ps);
|
||||
}
|
||||
}
|
||||
@ -382,12 +385,16 @@ public class ReviewCommand extends SshCommand {
|
||||
if (patchSet == null) {
|
||||
throw error("\"" + patchIdentity + "\" no such patch set");
|
||||
}
|
||||
if (projectControl != null) {
|
||||
if (projectControl != null || branch != null) {
|
||||
final Change change = db.changes().get(patchSetId.getParentKey());
|
||||
if (!inProject(change)) {
|
||||
throw error("change " + change.getId() + " not in project "
|
||||
+ projectControl.getProject().getName());
|
||||
}
|
||||
if (!inBranch(change)) {
|
||||
throw error("change " + change.getId() + " not in branch "
|
||||
+ change.getDest().get());
|
||||
}
|
||||
}
|
||||
return patchSet;
|
||||
}
|
||||
@ -403,6 +410,14 @@ public class ReviewCommand extends SshCommand {
|
||||
return projectControl.getProject().getNameKey().equals(change.getProject());
|
||||
}
|
||||
|
||||
private boolean inBranch(final Change change) {
|
||||
if (branch == null) {
|
||||
// No --branch option, so they want every branch.
|
||||
return true;
|
||||
}
|
||||
return change.getDest().get().equals(branch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parseCommandLine() throws UnloggedFailure {
|
||||
optionList = new ArrayList<ApproveOption>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user