|
|
|
|
|
|
|
|
/** Hook to validate the update commands before execution. */ |
|
|
/** Hook to validate the update commands before execution. */ |
|
|
private PreReceiveHook preReceive; |
|
|
private PreReceiveHook preReceive; |
|
|
|
|
|
|
|
|
|
|
|
private ReceiveCommandErrorHandler receiveCommandErrorHandler = new ReceiveCommandErrorHandler() { |
|
|
|
|
|
// Use the default implementation. |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/** Hook to report on the commands after execution. */ |
|
|
/** Hook to report on the commands after execution. */ |
|
|
private PostReceiveHook postReceive; |
|
|
private PostReceiveHook postReceive; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Collections.unmodifiableList(commands); |
|
|
return Collections.unmodifiableList(commands); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set an error handler for {@link ReceiveCommand}. |
|
|
|
|
|
* |
|
|
|
|
|
* @param receiveCommandErrorHandler |
|
|
|
|
|
* @since 5.7 |
|
|
|
|
|
*/ |
|
|
|
|
|
public void setReceiveCommandErrorHandler( |
|
|
|
|
|
ReceiveCommandErrorHandler receiveCommandErrorHandler) { |
|
|
|
|
|
this.receiveCommandErrorHandler = receiveCommandErrorHandler; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Send an error message to the client. |
|
|
* Send an error message to the client. |
|
|
* <p> |
|
|
* <p> |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
oldObj = walk.parseAny(cmd.getOldId()); |
|
|
oldObj = walk.parseAny(cmd.getOldId()); |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
cmd.setResult(Result.REJECTED_MISSING_OBJECT, |
|
|
|
|
|
cmd.getOldId().name()); |
|
|
|
|
|
|
|
|
receiveCommandErrorHandler |
|
|
|
|
|
.handleOldIdValidationException(cmd, e); |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
newObj = walk.parseAny(cmd.getNewId()); |
|
|
newObj = walk.parseAny(cmd.getNewId()); |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
cmd.setResult(Result.REJECTED_MISSING_OBJECT, |
|
|
|
|
|
cmd.getNewId().name()); |
|
|
|
|
|
|
|
|
receiveCommandErrorHandler |
|
|
|
|
|
.handleNewIdValidationException(cmd, e); |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
&& newObj instanceof RevCommit) { |
|
|
&& newObj instanceof RevCommit) { |
|
|
try { |
|
|
try { |
|
|
if (walk.isMergedInto((RevCommit) oldObj, |
|
|
if (walk.isMergedInto((RevCommit) oldObj, |
|
|
(RevCommit) newObj)) |
|
|
|
|
|
|
|
|
(RevCommit) newObj)) { |
|
|
cmd.setTypeFastForwardUpdate(); |
|
|
cmd.setTypeFastForwardUpdate(); |
|
|
else |
|
|
|
|
|
cmd.setType( |
|
|
|
|
|
ReceiveCommand.Type.UPDATE_NONFASTFORWARD); |
|
|
|
|
|
} catch (MissingObjectException e) { |
|
|
|
|
|
cmd.setResult(Result.REJECTED_MISSING_OBJECT, |
|
|
|
|
|
e.getMessage()); |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
cmd.setType(ReceiveCommand.Type.UPDATE_NONFASTFORWARD); |
|
|
|
|
|
} |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
cmd.setResult(Result.REJECTED_OTHER_REASON); |
|
|
|
|
|
|
|
|
receiveCommandErrorHandler |
|
|
|
|
|
.handleFastForwardCheckException(cmd, e); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
cmd.setType(ReceiveCommand.Type.UPDATE_NONFASTFORWARD); |
|
|
cmd.setType(ReceiveCommand.Type.UPDATE_NONFASTFORWARD); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
batch.setPushCertificate(getPushCertificate()); |
|
|
batch.setPushCertificate(getPushCertificate()); |
|
|
batch.execute(walk, updating); |
|
|
batch.execute(walk, updating); |
|
|
} catch (IOException err) { |
|
|
|
|
|
for (ReceiveCommand cmd : toApply) { |
|
|
|
|
|
if (cmd.getResult() == Result.NOT_ATTEMPTED) |
|
|
|
|
|
cmd.reject(err); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
receiveCommandErrorHandler.handleBatchRefUpdateException(toApply, |
|
|
|
|
|
e); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|