Method: Docman::Application#drush

Defined in:
lib/application.rb

#drush(env, site, command) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/application.rb', line 119

def drush(env, site, command)
  with_rescue(false) do
    cmd = "drush env: '#{env}', site: '#{site}', '#{command}'"
    log cmd
    path = Dir.pwd
    branch = 'commands'
    current_branch = GitUtil.branch
    GitUtil.exec("fetch")
    have_branch = Exec.do("git ls-remote --exit-code . origin/#{branch} &> /dev/null")
    log have_branch
    if have_branch
      GitUtil.exec("checkout #{branch}")
      GitUtil.exec("pull origin #{branch}")
    else
      GitUtil.exec("checkout --orphan #{branch}")
      GitUtil.exec("rm --cached -r .", false)
      GitUtil.exec("clean -f -d", false)
    end
    File.open(File.join(path, 'commands'), 'a') {|f| f.puts cmd}
    GitUtil.exec("add commands")
    GitUtil.exec("commit -m 'Added command'")
    GitUtil.exec("push origin #{branch}")
    GitUtil.exec("checkout #{current_branch}")
  end
end