| | |
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.IStoredSettings;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.client.Translation;
|
| | | import com.gitblit.manager.IRepositoryManager;
|
| | | import com.gitblit.manager.IRuntimeManager;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | |
| | |
|
| | | protected GroovyScriptEngine gse;
|
| | |
|
| | | public GitblitReceivePack(Repository db, RepositoryModel repository, UserModel user) {
|
| | | private final IStoredSettings settings;
|
| | |
|
| | | private final IRepositoryManager repositoryManager;
|
| | |
|
| | | public GitblitReceivePack(
|
| | | IRuntimeManager runtimeManager,
|
| | | IRepositoryManager repositoryManager,
|
| | | Repository db,
|
| | | RepositoryModel repository,
|
| | | UserModel user) {
|
| | |
|
| | | super(db);
|
| | | this.settings = runtimeManager.getSettings();
|
| | | this.repositoryManager = repositoryManager;
|
| | | this.repository = repository;
|
| | | this.user = user == null ? UserModel.ANONYMOUS : user;
|
| | | this.groovyDir = GitBlit.getGroovyScriptsFolder();
|
| | | this.groovyDir = repositoryManager.getHooksFolder();
|
| | | try {
|
| | | // set Grape root
|
| | | File grapeRoot = GitBlit.getFileOrFolder(Keys.groovy.grapeFolder, "${baseFolder}/groovy/grape").getAbsoluteFile();
|
| | | File grapeRoot = repositoryManager.getGrapesFolder();
|
| | | grapeRoot.mkdirs();
|
| | | System.setProperty("grape.root", grapeRoot.getAbsolutePath());
|
| | | this.gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());
|
| | |
| | | setAllowCreates(user.canCreateRef(repository));
|
| | | setAllowDeletes(user.canDeleteRef(repository));
|
| | | setAllowNonFastForwards(user.canRewindRef(repository));
|
| | | |
| | |
|
| | | // setup pre and post receive hook
|
| | | setPreReceiveHook(this);
|
| | | setPostReceiveHook(this);
|
| | |
| | | */
|
| | | @Override
|
| | | public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
|
| | |
|
| | | if (repository.isMirror) {
|
| | | // repository is a mirror
|
| | | for (ReceiveCommand cmd : commands) {
|
| | | sendRejection(cmd, "Gitblit does not allow pushes to \"{0}\" because it is a mirror!", repository.name);
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | if (repository.isFrozen) {
|
| | | // repository is frozen/readonly
|
| | |
| | | }
|
| | |
|
| | | Set<String> scripts = new LinkedHashSet<String>();
|
| | | scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));
|
| | | scripts.addAll(repositoryManager.getPreReceiveScriptsInherited(repository));
|
| | | if (!ArrayUtils.isEmpty(repository.preReceiveScripts)) {
|
| | | scripts.addAll(repository.preReceiveScripts);
|
| | | }
|
| | |
| | | String msg = MessageFormat.format(template, branch);
|
| | | String prefix;
|
| | | if (StringUtils.isEmpty(repository.incrementalPushTagPrefix)) {
|
| | | prefix = GitBlit.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");
|
| | | prefix = settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");
|
| | | } else {
|
| | | prefix = repository.incrementalPushTagPrefix;
|
| | | }
|
| | |
| | |
|
| | | // run Groovy hook scripts
|
| | | Set<String> scripts = new LinkedHashSet<String>();
|
| | | scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));
|
| | | scripts.addAll(repositoryManager.getPostReceiveScriptsInherited(repository));
|
| | | if (!ArrayUtils.isEmpty(repository.postReceiveScripts)) {
|
| | | scripts.addAll(repository.postReceiveScripts);
|
| | | }
|
| | |
| | | LOGGER.error(text + " (" + user.username + ")");
|
| | | }
|
| | |
|
| | | protected void sendHeader(String msg, Object... objects) {
|
| | | sendMessage("--->", msg, objects);
|
| | | }
|
| | |
|
| | | protected void sendMessage(String msg, Object... objects) {
|
| | | sendMessage(" ", msg, objects);
|
| | | }
|
| | |
|
| | | protected void sendMessage(String prefix, String msg, Object... objects) {
|
| | | String text;
|
| | | if (ArrayUtils.isEmpty(objects)) {
|
| | | text = msg;
|
| | | super.sendMessage(msg);
|
| | | super.sendMessage(prefix + msg);
|
| | | } else {
|
| | | text = MessageFormat.format(msg, objects);
|
| | | super.sendMessage(text);
|
| | | super.sendMessage(prefix + text);
|
| | | }
|
| | | LOGGER.info(text + " (" + user.username + ")");
|
| | | }
|
| | |
| | | * @param commands
|
| | | * @param scripts
|
| | | */
|
| | | protected void runGroovy(Collection<ReceiveCommand> commands, Set<String> scripts) {
|
| | | private void runGroovy(Collection<ReceiveCommand> commands, Set<String> scripts) {
|
| | | if (scripts == null || scripts.size() == 0) {
|
| | | // no Groovy scripts to execute
|
| | | return;
|