Class: GitBundle::Repository
- Inherits:
-
Object
- Object
- GitBundle::Repository
- Defined in:
- lib/git_bundle/repository.rb
Instance Attribute Summary collapse
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #add_file(filename) ⇒ Object
- #branch ⇒ Object
- #commit(message, *files) ⇒ Object
- #commit_messages_not_pushed ⇒ Object
- #commits_not_pushed ⇒ Object
- #execute(*args) ⇒ Object
- #execute_git(*args, **options) ⇒ Object
- #file_changed?(filename) ⇒ Boolean
-
#initialize(name, path, main_repository, locked_branch, locked_revision) ⇒ Repository
constructor
A new instance of Repository.
- #locked_branch ⇒ Object
- #locked_revision ⇒ Object
- #push(args) ⇒ Object
- #revision ⇒ Object
Constructor Details
#initialize(name, path, main_repository, locked_branch, locked_revision) ⇒ Repository
Returns a new instance of Repository.
15 16 17 18 19 20 21 |
# File 'lib/git_bundle/repository.rb', line 15 def initialize(name, path, main_repository, locked_branch, locked_revision) @name = name @path = path @main = main_repository @locked_branch = locked_branch @locked_revision = locked_revision end |
Instance Attribute Details
#main ⇒ Object (readonly)
Returns the value of attribute main.
3 4 5 |
# File 'lib/git_bundle/repository.rb', line 3 def main @main end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/git_bundle/repository.rb', line 3 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/git_bundle/repository.rb', line 3 def path @path end |
Class Method Details
.new_dependant(name, path, locked_branch, locked_revision) ⇒ Object
11 12 13 |
# File 'lib/git_bundle/repository.rb', line 11 def self.new_dependant(name, path, locked_branch, locked_revision) GitBundle::Repository.new(name, path, false, locked_branch, locked_revision) end |
.new_main(name, path) ⇒ Object
7 8 9 |
# File 'lib/git_bundle/repository.rb', line 7 def self.new_main(name, path) GitBundle::Repository.new(name, path, true, nil, nil) end |
Instance Method Details
#add_file(filename) ⇒ Object
57 58 59 60 |
# File 'lib/git_bundle/repository.rb', line 57 def add_file(filename) execute_git('add', filename) $?.exitstatus == 0 end |
#branch ⇒ Object
23 24 25 |
# File 'lib/git_bundle/repository.rb', line 23 def branch @branch ||= execute_git('rev-parse', '--abbrev-ref', 'HEAD').chomp end |
#commit(message, *files) ⇒ Object
62 63 64 65 |
# File 'lib/git_bundle/repository.rb', line 62 def commit(, *files) execute_git('commit', '-m', , files) $?.exitstatus == 0 end |
#commit_messages_not_pushed ⇒ Object
43 44 45 46 |
# File 'lib/git_bundle/repository.rb', line 43 def count = execute_git('rev-list', "origin/#{branch}..#{branch}", '--count').to_i count.times.map { |num| execute_git('rev-list', '--pretty=oneline', "--skip=#{num}", '--max-count=1', "origin/#{branch}..#{branch}").sub(/\h*\s/, '').strip } end |
#commits_not_pushed ⇒ Object
39 40 41 |
# File 'lib/git_bundle/repository.rb', line 39 def commits_not_pushed execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', "origin/#{branch}..#{branch}") end |
#execute(*args) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/git_bundle/repository.rb', line 74 def execute(*args) puts args.map{ |arg| "'#{arg}'" }.join(' ') if ENV['DEBUG'] == 'true' pipe_out, pipe_in = IO.pipe system *args, out: pipe_in, err: pipe_in pipe_in.close pipe_out.read end |
#execute_git(*args, **options) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/git_bundle/repository.rb', line 67 def execute_git(*args, **) git_command = ['git', '-C', @path] git_command += %w(-c color.status=always -c color.ui=always) if .fetch(:color, false) git_command += args.flatten execute(*git_command) end |
#file_changed?(filename) ⇒ Boolean
53 54 55 |
# File 'lib/git_bundle/repository.rb', line 53 def file_changed?(filename) !execute_git('diff', '--name-only', filename).empty? && $?.exitstatus == 0 end |
#locked_branch ⇒ Object
27 28 29 |
# File 'lib/git_bundle/repository.rb', line 27 def locked_branch @locked_branch || branch end |
#locked_revision ⇒ Object
35 36 37 |
# File 'lib/git_bundle/repository.rb', line 35 def locked_revision @locked_revision || revision end |
#push(args) ⇒ Object
48 49 50 51 |
# File 'lib/git_bundle/repository.rb', line 48 def push(args) puts execute_git('push', args) $?.exitstatus == 0 end |
#revision ⇒ Object
31 32 33 |
# File 'lib/git_bundle/repository.rb', line 31 def revision @revision ||= execute_git('rev-parse', '--verify', 'HEAD').gsub("\n", '') end |