Allow updates of commits where only the parent changes
This is necessary to support updates caused by a rebase, where the parent commit didn't update its tree but perhaps only updated its commit message, or the rebase is around a cherry-pick followed by a revert. Bug: issue 359 Change-Id: I2c53a4a5b11c2c90967b3ba0ea2452668f3f4723 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -986,19 +986,29 @@ final class Receive extends AbstractGitCommand {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't allow the same tree if the commit message is unmodified,
|
// Don't allow the same tree if the commit message is unmodified
|
||||||
// else warn that only the message changed.
|
// or no parents were updated (rebase), else warn that only part
|
||||||
|
// of the commit was modified.
|
||||||
//
|
//
|
||||||
if (priorPatchSet.equals(ps.getId())
|
if (priorPatchSet.equals(ps.getId())
|
||||||
&& c.getTree() == prior.getTree()) {
|
&& c.getTree() == prior.getTree()) {
|
||||||
rp.getRevWalk().parseBody(prior);
|
rp.getRevWalk().parseBody(prior);
|
||||||
if (c.getFullMessage().equals(prior.getFullMessage())) {
|
final boolean messageEq =
|
||||||
|
c.getFullMessage().equals(prior.getFullMessage());
|
||||||
|
final boolean parentsEq = parentsEqual(c, prior);
|
||||||
|
|
||||||
|
if (messageEq && parentsEq) {
|
||||||
reject(request.cmd, "no changes made");
|
reject(request.cmd, "no changes made");
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
err.write(Constants
|
err.write(Constants.encode("warning: " //
|
||||||
.encode("warning: Only commit message changed in "
|
+ change.getKey().abbreviate() + ": " //
|
||||||
+ change.getKey().abbreviate() + "\n"));
|
+ " no files changed, but" //
|
||||||
|
+ (!messageEq ? " message updated" : "") //
|
||||||
|
+ (!messageEq && !parentsEq ? " and" : "") //
|
||||||
|
+ (!parentsEq ? " was rebased" : "") //
|
||||||
|
+ "\n" //
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -1141,6 +1151,18 @@ final class Receive extends AbstractGitCommand {
|
|||||||
return result != null ? result.info.getKey() : null;
|
return result != null ? result.info.getKey() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean parentsEqual(RevCommit a, RevCommit b) {
|
||||||
|
if (a.getParentCount() != b.getParentCount()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < a.getParentCount(); i++) {
|
||||||
|
if (a.getParent(i) != b.getParent(i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void insertDummyApproval(final ReplaceResult result,
|
private void insertDummyApproval(final ReplaceResult result,
|
||||||
final Account.Id forAccount, final ApprovalCategory.Id catId,
|
final Account.Id forAccount, final ApprovalCategory.Id catId,
|
||||||
final ReviewDb db, final Transaction txn) throws OrmException {
|
final ReviewDb db, final Transaction txn) throws OrmException {
|
||||||
|
Reference in New Issue
Block a user