Class: VersionManager::VCS::Git
- Inherits:
-
Object
- Object
- VersionManager::VCS::Git
- Defined in:
- lib/version-manager/vcs/git.rb
Instance Method Summary collapse
- #add_tag(tag_name, message) ⇒ Object
- #checkout(branch_name) ⇒ Object
- #commit(filepath, message) ⇒ Object
- #create_branch!(branch_name) ⇒ Object
- #current_branch ⇒ Object
-
#initialize(options) ⇒ Git
constructor
A new instance of Git.
- #master_state_actual? ⇒ Boolean
- #push ⇒ Object
- #push_tag(tag_name) ⇒ Object
- #remote_branch_names ⇒ Object
- #show_file(branch, filepath) ⇒ Object
- #state_actual? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Git
Returns a new instance of Git.
4 5 6 7 |
# File 'lib/version-manager/vcs/git.rb', line 4 def initialize() = @git = ::Git.open(ROOT_DIR, ) end |
Instance Method Details
#add_tag(tag_name, message) ⇒ Object
29 30 31 |
# File 'lib/version-manager/vcs/git.rb', line 29 def add_tag(tag_name, ) git.add_tag(tag_name, message: , annotate: tag_name) end |
#checkout(branch_name) ⇒ Object
14 15 16 |
# File 'lib/version-manager/vcs/git.rb', line 14 def checkout(branch_name) git.branch(branch_name).checkout end |
#commit(filepath, message) ⇒ Object
24 25 26 27 |
# File 'lib/version-manager/vcs/git.rb', line 24 def commit(filepath, ) git.lib.send(:command, 'add', filepath) git.lib.send(:command, 'commit', "-m #{message}", '-o', "#{filepath}") end |
#create_branch!(branch_name) ⇒ Object
9 10 11 12 |
# File 'lib/version-manager/vcs/git.rb', line 9 def create_branch!(branch_name) raise VersionManager::VCS::BranchAlreadyExistsError.new(branch_name) if branch_exists?(branch_name) checkout(branch_name) end |
#current_branch ⇒ Object
42 43 44 |
# File 'lib/version-manager/vcs/git.rb', line 42 def current_branch git.current_branch end |
#master_state_actual? ⇒ Boolean
46 47 48 |
# File 'lib/version-manager/vcs/git.rb', line 46 def master_state_actual? git.revparse(master_branch_name) == git.revparse(remote_master_branch_name) end |
#push ⇒ Object
33 34 35 36 |
# File 'lib/version-manager/vcs/git.rb', line 33 def push git.pull(remote, current_branch) if find_remote_branch(current_branch) git.push(remote, current_branch) end |
#push_tag(tag_name) ⇒ Object
38 39 40 |
# File 'lib/version-manager/vcs/git.rb', line 38 def push_tag(tag_name) git.push(remote, tag_name) end |
#remote_branch_names ⇒ Object
57 58 59 |
# File 'lib/version-manager/vcs/git.rb', line 57 def remote_branch_names ::Git.ls_remote['remotes'].keys end |
#show_file(branch, filepath) ⇒ Object
18 19 20 21 22 |
# File 'lib/version-manager/vcs/git.rb', line 18 def show_file(branch, filepath) git.object("#{branch}:#{filepath}").contents rescue StandardError nil end |
#state_actual? ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/version-manager/vcs/git.rb', line 50 def state_actual? head = ::Git.ls_remote['branches'][git.current_branch] remote_head = find_remote_branch(git.current_branch).last return unless remote_head head[:sha] == remote_head[:sha] end |