 require 'shelljs/global'
+{platform} = require 'os'
 # 修改shelljs内部的common.config，只是为了兼容window platform，不然windows会报BDADF, bad descriptor
 {config} = require 'shelljs'
 config.silent = true;

  #         resolve()
  .then =>
    Q.Promise (resolve, reject, notify) =>
      console.log "options5"
      console.log options
      console.log "pwd:#{pwd()}"
      console.log 'git push -u origin master'
      # ssh-add 清除客户端公钥缓存
      exec "eval \"$(ssh-agent -s)\" && ssh-add #{home}/.ssh/id_rsa_#{username} && git push -u origin master#{EOL}#{EOL}#{EOL}#{EOL}", options, (code, output) ->
        console.log('Exit code:', code);
        console.log('Program output:', output);
        if code != 0
          e = new Error "Error: git push -u origin master failed: #{output}"
          e.code = code
          reject e
        else
          resolve()

  console.log options

  Q.Promise (resolve, reject, notify) =>
    env["path"] = options.env.path # 非永久设置环境变量
    if not which 'git'
      return reject new Error 'Sorry, this script requires git'

