Module: Homesick::Actions::GitActions
- Included in:
- CLI
- Defined in:
- lib/homesick/actions/git_actions.rb
Overview
Git-related helper methods for Homesick
Constant Summary collapse
- MIN_VERSION =
Information on the minimum git version required for Homesick
{ major: 1, minor: 8, patch: 0 }
- STRING =
MIN_VERSION.values.join('.')
Instance Method Summary collapse
- #git_add(file) ⇒ Object
-
#git_clone(repo, config = {}) ⇒ Object
TODO: move this to be more like thor’s template, empty_directory, etc.
- #git_commit_all(config = {}) ⇒ Object
- #git_diff ⇒ Object
- #git_init(path = '.') ⇒ Object
- #git_pull ⇒ Object
- #git_push ⇒ Object
- #git_remote_add(name, url) ⇒ Object
- #git_status ⇒ Object
- #git_submodule_init ⇒ Object
- #git_submodule_update ⇒ Object
- #git_version_correct? ⇒ Boolean
Instance Method Details
#git_add(file) ⇒ Object
97 98 99 100 |
# File 'lib/homesick/actions/git_actions.rb', line 97 def git_add(file) say_status 'git add file', '', :green system "git add '#{file}'" end |
#git_clone(repo, config = {}) ⇒ Object
TODO: move this to be more like thor’s template, empty_directory, etc
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/homesick/actions/git_actions.rb', line 26 def git_clone(repo, config = {}) config ||= {} destination = config[:destination] || File.basename(repo, '.git') destination = Pathname.new(destination) unless destination.is_a?(Pathname) FileUtils.mkdir_p destination.dirname if destination.directory? say_status :exist, destination., :blue else say_status 'git clone', "#{repo} to #{destination.expand_path}", :green system "git clone -q --config push.default=upstream --recursive #{repo} #{destination}" end end |
#git_commit_all(config = {}) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/homesick/actions/git_actions.rb', line 88 def git_commit_all(config = {}) say_status 'git commit all', '', :green if config[:message] system %(git commit -a -m "#{config[:message]}") else system 'git commit -v -a' end end |
#git_diff ⇒ Object
107 108 109 110 |
# File 'lib/homesick/actions/git_actions.rb', line 107 def git_diff say_status 'git diff', '', :green system 'git diff' end |
#git_init(path = '.') ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/homesick/actions/git_actions.rb', line 43 def git_init(path = '.') path = Pathname.new(path) inside path do if path.join('.git').exist? say_status 'git init', 'already initialized', :blue else say_status 'git init', '' system 'git init >/dev/null' end end end |
#git_pull ⇒ Object
78 79 80 81 |
# File 'lib/homesick/actions/git_actions.rb', line 78 def git_pull say_status 'git pull', '', :green system 'git pull --quiet' end |
#git_push ⇒ Object
83 84 85 86 |
# File 'lib/homesick/actions/git_actions.rb', line 83 def git_push say_status 'git push', '', :green system 'git push' end |
#git_remote_add(name, url) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/homesick/actions/git_actions.rb', line 56 def git_remote_add(name, url) existing_remote = `git config remote.#{name}.url`.chomp existing_remote = nil if existing_remote == '' if existing_remote say_status 'git remote', "#{name} already exists", :blue else say_status 'git remote', "add #{name} #{url}" system "git remote add #{name} #{url}" end end |
#git_status ⇒ Object
102 103 104 105 |
# File 'lib/homesick/actions/git_actions.rb', line 102 def git_status say_status 'git status', '', :green system 'git status' end |
#git_submodule_init ⇒ Object
68 69 70 71 |
# File 'lib/homesick/actions/git_actions.rb', line 68 def git_submodule_init say_status 'git submodule', 'init', :green system 'git submodule --quiet init' end |
#git_submodule_update ⇒ Object
73 74 75 76 |
# File 'lib/homesick/actions/git_actions.rb', line 73 def git_submodule_update say_status 'git submodule', 'update', :green system 'git submodule --quiet update --init --recursive >/dev/null 2>&1' end |
#git_version_correct? ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/homesick/actions/git_actions.rb', line 14 def git_version_correct? info = `git --version`.scan(/(\d+)\.(\d+)\.(\d+)/).flatten.map(&:to_i) return false unless info.count == 3 current_version = Hash[[:major, :minor, :patch].zip(info)] return true if current_version.eql?(MIN_VERSION) return true if current_version[:major] > MIN_VERSION[:major] return true if current_version[:major] == MIN_VERSION[:major] && current_version[:minor] > MIN_VERSION[:minor] return true if current_version[:major] == MIN_VERSION[:major] && current_version[:minor] == MIN_VERSION[:minor] && current_version[:patch] >= MIN_VERSION[:patch] false end |