-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·62 lines (57 loc) · 1.52 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/node
var exec= require('child_process').exec,
fs= require('fs')
spaces= /[\s]/,
pieces= [null,null]
// this first section, install, builds post-commit files.
if(process.argv[2] == 'install') {
var path= require('path'),
cwd= process.cwd()
dir= cwd
while(dir.length > 1) {
var trial= null,
git_dir= dir+"/.git/hooks"
try {
trial= fs.statSync(git_dir)
} catch(ex) {
}
if(trial && trial.isDirectory) {
dir= git_dir
break;
}
dir= path.dirname(dir)
}
if(dir.length <= 1) {
process.exit(1)
}
var dest= dir+"/post-commit"
try{
fs.statSync(dest)
dest= dest+".git-js-default"
}catch(ex){
}
var file= "#!/bin/sh\ngit-ts-publish"
if(process.argv[3])
file+= " -u '"+process.argv[3]+"'"
for(var i = 4; i < process.argv.length; ++i)
file+= " "+process.argv[i]
fs.writeFileSync(dest,file)
fs.chmod(dest,0755)
process.exit()
}
exec('git log -n1', function(err,stdout,stdin) {
if(err) process.exit(2)
var head= stdout.split(spaces,2)[1]
exec('git cat-file -p '+head,function(err,stdout_catfile,stderr_catfile) {
if(err) process.exit(3)
var tree= stdout.split(spaces,2)[1]
exec('git ls-tree -r -t -l --full-name '+tree,function(err,stdout_tree,stdin_tree) {
if(err) process.exit(4)
process.stdout.write(head)
process.stdout.write("\n")
process.stdout.write(stdout_catfile)
process.stdout.write("\n")
//process.stdout.end(stdout_tree)
})
})
})