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_git(command) ⇒ 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') end |
#commit(message, *files) ⇒ Object
62 63 64 65 |
# File 'lib/git_bundle/repository.rb', line 62 def commit(, *files) execute_git("commit -m '#{message}' #{files.join(' ')}") $?.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 #{branch} --count --not --remotes").to_i count.times.map { |num| execute_git("log #{branch} --not --remotes --skip=#{num} --max-count=1 --pretty=format:'%B'").strip } end |
#commits_not_pushed ⇒ Object
39 40 41 |
# File 'lib/git_bundle/repository.rb', line 39 def commits_not_pushed execute_git("log #{branch} --not --remotes") end |
#execute_git(command) ⇒ Object
67 68 69 70 71 |
# File 'lib/git_bundle/repository.rb', line 67 def execute_git(command) full_command = "git -C #{@path} #{command}" puts full_command if ENV['DEBUG'] == 'true' `#{full_command}`.strip 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.join(' ')}") $?.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 |