Class: GitBundle::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/git_bundle/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#mainObject (readonly)

Returns the value of attribute main.



3
4
5
# File 'lib/git_bundle/repository.rb', line 3

def main
  @main
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/git_bundle/repository.rb', line 3

def name
  @name
end

#pathObject (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

#branchObject



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(message, *files)
  execute_git("commit -m '#{message}' #{files.join(' ')}")
  $?.exitstatus == 0
end

#commit_messages_not_pushedObject



43
44
45
46
# File 'lib/git_bundle/repository.rb', line 43

def commit_messages_not_pushed
  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_pushedObject



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

Returns:

  • (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_branchObject



27
28
29
# File 'lib/git_bundle/repository.rb', line 27

def locked_branch
  @locked_branch || branch
end

#locked_revisionObject



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

#revisionObject



31
32
33
# File 'lib/git_bundle/repository.rb', line 31

def revision
  @revision ||= execute_git('rev-parse --verify HEAD').gsub("\n", '')
end