|
|
|
|
|
|
|
|
import groovy.lang.Binding;
|
|
|
import groovy.lang.Binding;
|
|
|
import groovy.util.GroovyScriptEngine;
|
|
|
import groovy.util.GroovyScriptEngine;
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
import java.text.MessageFormat;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Enumeration;
|
|
|
import java.util.Enumeration;
|
|
|
|
|
|
|
|
|
.getName(), cmd.getResult(), cmd.getMessage()));
|
|
|
.getName(), cmd.getResult(), cmd.getMessage()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Experimental
|
|
|
|
|
|
// runNativeScript(rp, "hooks/pre-receive", commands);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
|
|
|
|
|
|
scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));
|
|
|
scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));
|
|
|
scripts.addAll(repository.postReceiveScripts);
|
|
|
scripts.addAll(repository.postReceiveScripts);
|
|
|
runGroovy(repository, user, commands, rp, scripts);
|
|
|
runGroovy(repository, user, commands, rp, scripts);
|
|
|
|
|
|
|
|
|
// Experimental
|
|
|
|
|
|
// runNativeScript(rp, "hooks/post-receive", commands);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Runs the native push hook script.
|
|
|
|
|
|
*
|
|
|
|
|
|
* http://book.git-scm.com/5_git_hooks.html
|
|
|
|
|
|
* http://longair.net/blog/2011/04/09/missing-git-hooks-documentation/
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param rp
|
|
|
|
|
|
* @param script
|
|
|
|
|
|
* @param commands
|
|
|
|
|
|
*/
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
|
protected void runNativeScript(ReceivePack rp, String script,
|
|
|
|
|
|
Collection<ReceiveCommand> commands) {
|
|
|
|
|
|
|
|
|
|
|
|
Repository repository = rp.getRepository();
|
|
|
|
|
|
File scriptFile = new File(repository.getDirectory(), script);
|
|
|
|
|
|
|
|
|
|
|
|
int resultCode = 0;
|
|
|
|
|
|
if (scriptFile.exists()) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
logger.debug("executing " + scriptFile);
|
|
|
|
|
|
Process process = Runtime.getRuntime().exec(scriptFile.getAbsolutePath(), null,
|
|
|
|
|
|
repository.getDirectory());
|
|
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
|
|
|
|
|
process.getInputStream()));
|
|
|
|
|
|
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
|
|
|
|
|
|
process.getOutputStream()));
|
|
|
|
|
|
for (ReceiveCommand command : commands) {
|
|
|
|
|
|
switch (command.getType()) {
|
|
|
|
|
|
case UPDATE:
|
|
|
|
|
|
// updating a ref
|
|
|
|
|
|
writer.append(MessageFormat.format("{0} {1} {2}\n", command.getOldId()
|
|
|
|
|
|
.getName(), command.getNewId().getName(), command.getRefName()));
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CREATE:
|
|
|
|
|
|
// new ref
|
|
|
|
|
|
// oldrev hard-coded to 40? weird.
|
|
|
|
|
|
writer.append(MessageFormat.format("40 {0} {1}\n", command.getNewId()
|
|
|
|
|
|
.getName(), command.getRefName()));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
resultCode = process.waitFor();
|
|
|
|
|
|
|
|
|
|
|
|
// read and buffer stdin
|
|
|
|
|
|
// this is supposed to be piped back to the git client.
|
|
|
|
|
|
// not sure how to do that right now.
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
String line = null;
|
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
|
sb.append(line).append('\n');
|
|
|
|
|
|
}
|
|
|
|
|
|
logger.debug(sb.toString());
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
|
resultCode = -1;
|
|
|
|
|
|
logger.error(
|
|
|
|
|
|
MessageFormat.format("Failed to execute {0}",
|
|
|
|
|
|
scriptFile.getAbsolutePath()), e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// reject push
|
|
|
|
|
|
if (resultCode != 0) {
|
|
|
|
|
|
for (ReceiveCommand command : commands) {
|
|
|
|
|
|
command.setResult(Result.REJECTED_OTHER_REASON, MessageFormat.format(
|
|
|
|
|
|
"Native script {0} rejected push or failed",
|
|
|
|
|
|
scriptFile.getAbsolutePath()));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|