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) ⇒ Object
- #commit(filepath, message) ⇒ Object
- #create_branch!(branch) ⇒ 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
-
#switch_branch(branch) ⇒ Object
checkout moves commits to new branch.
Constructor Details
#initialize(options) ⇒ Git
Returns a new instance of Git.
5 6 7 8 |
# File 'lib/version-manager/vcs/git.rb', line 5 def initialize() @options = @git = ::Git.open([:dir], ) end |
Instance Method Details
#add_tag(tag_name, message) ⇒ Object
36 37 38 |
# File 'lib/version-manager/vcs/git.rb', line 36 def add_tag(tag_name, ) git.add_tag(tag_name, message: , annotate: tag_name) end |
#checkout(branch) ⇒ Object
16 17 18 |
# File 'lib/version-manager/vcs/git.rb', line 16 def checkout(branch) git.branch(branch_name(branch)).checkout end |
#commit(filepath, message) ⇒ Object
31 32 33 34 |
# File 'lib/version-manager/vcs/git.rb', line 31 def commit(filepath, ) git.lib.send(:command, 'add', filepath) git.lib.send(:command, 'commit', "-m #{}", '-o', filepath) end |
#create_branch!(branch) ⇒ Object
10 11 12 13 14 |
# File 'lib/version-manager/vcs/git.rb', line 10 def create_branch!(branch) branch = branch_name(branch) raise VersionManager::VCS::BranchAlreadyExistsError, branch if branch_exists?(branch) checkout(branch) end |
#current_branch ⇒ Object
49 50 51 |
# File 'lib/version-manager/vcs/git.rb', line 49 def current_branch git.current_branch end |
#master_state_actual? ⇒ Boolean
53 54 55 |
# File 'lib/version-manager/vcs/git.rb', line 53 def master_state_actual? git.revparse(master_branch_name) == git.revparse(remote_master_branch_name) end |
#push ⇒ Object
40 41 42 43 |
# File 'lib/version-manager/vcs/git.rb', line 40 def push git.pull(remote, current_branch) if find_remote_branch(current_branch) git.push(remote, current_branch) end |
#push_tag(tag_name) ⇒ Object
45 46 47 |
# File 'lib/version-manager/vcs/git.rb', line 45 def push_tag(tag_name) git.push(remote, tag_name) end |
#remote_branch_names ⇒ Object
64 65 66 |
# File 'lib/version-manager/vcs/git.rb', line 64 def remote_branch_names git_remote['remotes'].keys end |
#show_file(branch, filepath) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/version-manager/vcs/git.rb', line 24 def show_file(branch, filepath) relative_filepath = Pathname.new(filepath).relative_path_from(Pathname.new([:dir])).to_s git.object("#{remote}/#{branch_name(branch)}:#{relative_filepath}").contents rescue StandardError nil end |
#state_actual? ⇒ Boolean
57 58 59 60 61 62 |
# File 'lib/version-manager/vcs/git.rb', line 57 def state_actual? head = git_remote['branches'][git.current_branch] remote_head = find_remote_branch(git.current_branch).last return unless remote_head head[:sha] == remote_head[:sha] end |
#switch_branch(branch) ⇒ Object
checkout moves commits to new branch
20 21 22 |
# File 'lib/version-manager/vcs/git.rb', line 20 def switch_branch(branch) # checkout moves commits to new branch git.lib.send(:command, 'checkout', branch_name(branch)) end |