Module: Git
- Defined in:
- lib/git.rb
Overview
module for help with git
Constant Summary collapse
- BASE_DIR =
'~/'.freeze
- LOOKFILE_DIR =
'.lookfile'.freeze
Class Method Summary collapse
- .commit(base_dir = BASE_DIR) ⇒ Object
- .init(base_dir = BASE_DIR) ⇒ Object
- .load_git_command(base_dir = BASE_DIR) ⇒ Object
- .make_commit?(message, base_dir = BASE_DIR) ⇒ Boolean
- .push(base_dir = BASE_DIR) ⇒ Object
- .rebase(base_dir = BASE_DIR) ⇒ Object
- .remote?(base_dir = BASE_DIR) ⇒ Boolean
- .set_remote(repository_ssh_name, base_dir = BASE_DIR) ⇒ Object
- .status(base_dir = BASE_DIR) ⇒ Object
Class Method Details
.commit(base_dir = BASE_DIR) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/git.rb', line 52 def commit(base_dir = BASE_DIR) git = load_git_command(base_dir) = status(base_dir) `#{git} add --all` return nil if !make_commit?(, base_dir) || .empty? end |
.init(base_dir = BASE_DIR) ⇒ Object
16 17 18 19 |
# File 'lib/git.rb', line 16 def init(base_dir = BASE_DIR) git = load_git_command(base_dir) `#{git} init` end |
.load_git_command(base_dir = BASE_DIR) ⇒ Object
11 12 13 14 |
# File 'lib/git.rb', line 11 def load_git_command(base_dir = BASE_DIR) directory = Lookfile.load_lookfile_dir(base_dir) "git -C '#{directory}'" end |
.make_commit?(message, base_dir = BASE_DIR) ⇒ Boolean
65 66 67 68 69 70 |
# File 'lib/git.rb', line 65 def make_commit?(, base_dir = BASE_DIR) git = load_git_command(base_dir) commit = `#{git} commit -m "#{}"` return false if commit.include?('nothing to commit') true end |
.push(base_dir = BASE_DIR) ⇒ Object
60 61 62 63 |
# File 'lib/git.rb', line 60 def push(base_dir = BASE_DIR) git = load_git_command(base_dir) `#{git} push origin master` end |
.rebase(base_dir = BASE_DIR) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/git.rb', line 33 def rebase(base_dir = BASE_DIR) git = load_git_command(base_dir) branchs = `#{git} branch -a` return nil unless branchs.include?('remotes/origin/master') `#{git} fetch origin -p` `#{git} pull origin master` end |
.remote?(base_dir = BASE_DIR) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/git.rb', line 21 def remote?(base_dir = BASE_DIR) git = load_git_command(base_dir) remote = `#{git} remote` remote.include?('origin') end |
.set_remote(repository_ssh_name, base_dir = BASE_DIR) ⇒ Object
27 28 29 30 31 |
# File 'lib/git.rb', line 27 def set_remote(repository_ssh_name, base_dir = BASE_DIR) git = load_git_command(base_dir) `#{git} remote remove origin` if remote?(base_dir) `#{git} remote add origin #{repository_ssh_name}` end |
.status(base_dir = BASE_DIR) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/git.rb', line 41 def status(base_dir = BASE_DIR) git = load_git_command(base_dir) untracked_files = `#{git} ls-files --others --exclude-standard`.split deleted_files = `#{git} ls-files --deleted`.split modified_files = `#{git} ls-files --modified`.split - deleted_files = Lookfile.show_files("\nAdded files:", untracked_files) += Lookfile.show_files("\nModified files:", modified_files) += Lookfile.show_files("\nDeleted files:", deleted_files) .strip end |