Created
May 6, 2011 23:20
-
-
Save cognominal/959992 to your computer and use it in GitHub Desktop.
why match is undefined at the last line of the program?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
fs = require 'fs' | |
spawn = (require 'child_process').spawn | |
log = console.log | |
data = fs.readFileSync '.git/FETCH_HEAD', 'utf8' | |
for ln in data.split /\n/ | |
match = /(.{40}).*?branch '(.*)'/.exec ln | |
continue unless match | |
args = "log -1 --format=%cd #{match[1]}".split /\s+/ | |
fun = -> | |
branchNm = match[2] | |
git = spawn 'git', args | |
git.stdout.on 'data', (data) -> log "#{data.toString 'utf8', 0, data.length-1} #{branchNm}" | |
fun() | |
### | |
The problem is that scope in javascript is function and not loop. So I have to create a function to capture the branch name | |
at each iteration of the loop. | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment