mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Added checking for the master branch.
This commit is contained in:
parent
77a9ef8cc8
commit
128e24d2fb
3 changed files with 48 additions and 4 deletions
|
@ -8,6 +8,7 @@ import org.eclipse.jgit.transport.ReceivePack;
|
|||
import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents;
|
||||
import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
|
||||
import uk.ac.ic.wlgitbridge.git.handler.hook.exception.ForcedPushException;
|
||||
import uk.ac.ic.wlgitbridge.git.handler.hook.exception.WrongBranchException;
|
||||
import uk.ac.ic.wlgitbridge.git.util.RepositoryObjectTreeWalker;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.OutOfDateException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
|
@ -56,6 +57,7 @@ public class WriteLatexPutHook implements PreReceiveHook {
|
|||
}
|
||||
|
||||
private void handleReceiveCommand(Repository repository, ReceiveCommand receiveCommand) throws IOException, SnapshotPostException, FailedConnectionException {
|
||||
checkBranch(receiveCommand);
|
||||
checkForcedPush(receiveCommand);
|
||||
writeLatexDataSource.putDirectoryContentsToProjectWithName(repository.getWorkTree().getName(),
|
||||
getPushedDirectoryContents(repository,
|
||||
|
@ -63,6 +65,12 @@ public class WriteLatexPutHook implements PreReceiveHook {
|
|||
hostname);
|
||||
}
|
||||
|
||||
private void checkBranch(ReceiveCommand receiveCommand) throws WrongBranchException {
|
||||
if (!receiveCommand.getRefName().equals("refs/heads/master")) {
|
||||
throw new WrongBranchException();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForcedPush(ReceiveCommand receiveCommand) throws ForcedPushException {
|
||||
if (receiveCommand.getType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD) {
|
||||
throw new ForcedPushException();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package uk.ac.ic.wlgitbridge.git.handler.hook.exception;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import uk.ac.ic.wlgitbridge.util.Util;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -12,7 +13,7 @@ import java.util.List;
|
|||
public class ForcedPushException extends SnapshotPostException {
|
||||
|
||||
private static final String[] DESCRIPTION_LINES = {
|
||||
"You can't git push --force to a WriteLatex project.",
|
||||
"You can't git push --force to a " + Util.getServiceName() + " project.",
|
||||
"Try to put your changes on top of the current head.",
|
||||
"If everything else fails, delete and reclone your repository, make your changes, then push again."
|
||||
};
|
||||
|
@ -31,4 +32,5 @@ public class ForcedPushException extends SnapshotPostException {
|
|||
public void fromJSON(JsonElement json) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package uk.ac.ic.wlgitbridge.git.handler.hook.exception;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Winston on 19/12/14.
|
||||
*/
|
||||
public class WrongBranchException extends SnapshotPostException {
|
||||
|
||||
private static final String[] DESCRIPTION_LINES = {
|
||||
"You can't push any new branches.",
|
||||
"Please use the master branch."
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "wrong branch";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDescriptionLines() {
|
||||
return Arrays.asList(DESCRIPTION_LINES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJSON(JsonElement json) {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue