Reject pushing multiple commits with the same new Change-ID
Pushing two commits with the same new Change-ID (Change-ID which is not yet used in Gerrit) succeeds when done in one push command. As a result there are two changes in Gerrit that have the same Change-ID. Uploading a new patch set for both of the changes then fails with '<change-id> has duplicates'. Pushing the second commit separately after the first commit has been pushed before properly fails with 'squash commits first'. This change ensures that pushing multiple commits at once only succeeds if each of the commits has none or an unique Change-ID. If several commits with the same new Change-ID are pushed, this now fails with 'squash commits first'. Bug: issue 414 Change-Id: Ib009f3188e3967d62cd0f0f37038c2e0a575856c Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
parent
0ff5ff0112
commit
03fcb4f730
@ -819,6 +819,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
}
|
||||
}
|
||||
|
||||
final Set<Change.Key> newChangeIds = new HashSet<Change.Key>();
|
||||
for (;;) {
|
||||
final RevCommit c = walk.next();
|
||||
if (c == null) {
|
||||
@ -839,6 +840,12 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
if (!idList.isEmpty()) {
|
||||
final String idStr = idList.get(idList.size() - 1).trim();
|
||||
final Change.Key key = new Change.Key(idStr);
|
||||
|
||||
if (newChangeIds.contains(key)) {
|
||||
reject(newChange, "squash commits first");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Change> changes =
|
||||
db.changes().byProjectKey(project.getNameKey(), key).toList();
|
||||
if (changes.size() > 1) {
|
||||
@ -861,6 +868,10 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (changes.size() == 0) {
|
||||
newChangeIds.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
toCreate.add(c);
|
||||
|
Loading…
x
Reference in New Issue
Block a user