Class: Gitomator::ServiceProvider::GitShell
- Inherits:
-
Object
- Object
- Gitomator::ServiceProvider::GitShell
- Defined in:
- lib/gitomator/service_provider/git_shell.rb
Instance Method Summary collapse
- #_run_command(cmd, opts = {}) ⇒ Object
- #_run_git_command(cmd, local_repo_root, opts = {}) ⇒ Object
- #add(local_repo_root, path, opts = {}) ⇒ Object
- #checkout(local_repo_root, branch, opts) ⇒ Object
- #clone(repo_url, local_repo_root, opts) ⇒ Object
- #command(local_repo_root, command) ⇒ Object
- #commit(local_repo_root, message, opts = {}) ⇒ Object
- #init(local_repo_root, opts = {}) ⇒ Object
- #push(local_repo_root, remote, opts) ⇒ Object
- #set_remote(local_repo_root, remote, url, opts) ⇒ Object
Instance Method Details
#_run_command(cmd, opts = {}) ⇒ Object
54 55 56 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 54 def _run_command(cmd, opts = {}) system({}, cmd, opts) end |
#_run_git_command(cmd, local_repo_root, opts = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 58 def _run_git_command(cmd, local_repo_root, opts = {}) opts[:chdir] = local_repo_root unless cmd.strip.start_with? 'git' cmd = 'git ' + cmd end _run_command(cmd, opts) end |
#add(local_repo_root, path, opts = {}) ⇒ Object
14 15 16 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 14 def add(local_repo_root, path, opts={}) _run_git_command("add #{path}", local_repo_root, opts) end |
#checkout(local_repo_root, branch, opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 23 def checkout(local_repo_root, branch, opts) cmd = 'checkout ' if opts[:is_new] cmd += '-b ' end cmd += branch if opts[:is_remote] cmd += " origin/#{branch}" end _run_git_command(cmd, local_repo_root, {}) end |
#clone(repo_url, local_repo_root, opts) ⇒ Object
5 6 7 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 5 def clone(repo_url, local_repo_root, opts) _run_command("git clone #{repo_url} #{local_repo_root}", opts = {}) end |
#command(local_repo_root, command) ⇒ Object
47 48 49 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 47 def command(local_repo_root, command) _run_git_command(command, local_repo_root, opts = {}) end |
#commit(local_repo_root, message, opts = {}) ⇒ Object
18 19 20 21 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 18 def commit(local_repo_root, , opts={}) cmd = "commit -m \"#{message.gsub('"', '\\\"')}\"" _run_git_command(cmd, local_repo_root, opts) end |
#init(local_repo_root, opts = {}) ⇒ Object
9 10 11 12 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 9 def init(local_repo_root, opts = {}) Dir.mkdir(local_repo_root) unless Dir.exists?(local_repo_root) _run_git_command("init", local_repo_root) end |
#push(local_repo_root, remote, opts) ⇒ Object
42 43 44 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 42 def push(local_repo_root, remote, opts) raise "Unsupported" end |
#set_remote(local_repo_root, remote, url, opts) ⇒ Object
36 37 38 39 40 |
# File 'lib/gitomator/service_provider/git_shell.rb', line 36 def set_remote(local_repo_root, remote, url, opts) cmd = "remote #{opts[:create] ? 'add' : 'set-url'} #{remote} #{url}" opts.delete :create _run_git_command(cmd, local_repo_root, opts) end |