class GitBundle::Repository
Attributes
branch[R]
locked_branch[R]
main[R]
name[R]
path[R]
remote[R]
Public Class Methods
new(name, path, main_repository, locked_branch, locked_revision)
click to toggle source
# File lib/git_bundle/repository.rb, line 20 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 refresh_branch end
new_dependant(name, path, locked_branch, locked_revision)
click to toggle source
# File lib/git_bundle/repository.rb, line 16 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)
click to toggle source
# File lib/git_bundle/repository.rb, line 12 def self.new_main(name, path) GitBundle::Repository.new(name, path, true, nil, nil) end
Public Instance Methods
add_file(filename)
click to toggle source
# File lib/git_bundle/repository.rb, line 100 def add_file(filename) execute_git('add', filename) $?.exitstatus == 0 end
checkout(args)
click to toggle source
# File lib/git_bundle/repository.rb, line 91 def checkout(args) execute_git_output('checkout', args) $?.exitstatus == 0 end
commit(message, *files)
click to toggle source
# File lib/git_bundle/repository.rb, line 105 def commit(message, *files) execute_git('commit', '-m', message, files) $?.exitstatus == 0 end
commit_with_description(message, description, *files)
click to toggle source
# File lib/git_bundle/repository.rb, line 110 def commit_with_description(message, description, *files) execute_git('commit', '-m', message, '-m', description, files) $?.exitstatus == 0 end
commits_not_pushed()
click to toggle source
# File lib/git_bundle/repository.rb, line 76 def commits_not_pushed execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', "#{remote}/#{branch}..#{branch}") end
commits_not_pushed?()
click to toggle source
# File lib/git_bundle/repository.rb, line 71 def commits_not_pushed? return true unless upstream_branch_exists? commits_not_pushed_count > 0 end
commits_not_pushed_count()
click to toggle source
# File lib/git_bundle/repository.rb, line 80 def commits_not_pushed_count execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', '--count', "#{remote}/#{branch}..#{branch}").to_i end
execute_git(*args, **options)
click to toggle source
# File lib/git_bundle/repository.rb, line 121 def execute_git(*args, **options) execute(*git_command(*args, **options)) end
execute_git_output(*args, **options)
click to toggle source
# File lib/git_bundle/repository.rb, line 125 def execute_git_output(*args, **options) execute_live(*git_command(*args, **options)) end
file_changed?(filename)
click to toggle source
# File lib/git_bundle/repository.rb, line 96 def file_changed?(filename) !execute_git('diff', '--name-only', filename).empty? && $?.exitstatus == 0 end
git_command(*args, **options)
click to toggle source
# File lib/git_bundle/repository.rb, line 115 def git_command(*args, **options) git_command = ['git', '-C', @path] git_command += %w(-c color.status=always -c color.ui=always) if options.fetch(:color, false) git_command + args.flatten end
locked_revision()
click to toggle source
# File lib/git_bundle/repository.rb, line 42 def locked_revision @locked_revision || revision end
push(args, create_upstream: nil)
click to toggle source
Example: push([], create_upstream: ‘origin’)
# File lib/git_bundle/repository.rb, line 85 def push(args, create_upstream: nil) args = args.dup + ['--set-upstream', create_upstream, branch] if create_upstream execute_git_output('push', args) $?.exitstatus == 0 || (create_upstream && $?.exitstatus == 128) end
reference_exists?(reference)
click to toggle source
# File lib/git_bundle/repository.rb, line 50 def reference_exists?(reference) execute_git('cat-file', '-e', reference) $?.exitstatus == 0 end
refresh_branch()
click to toggle source
# File lib/git_bundle/repository.rb, line 29 def refresh_branch @remote = execute(*git_command('rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'), silence_err: true).split('/').first @branch = execute_git('rev-parse', '--abbrev-ref', 'HEAD').chomp end
remote_exists?(remote_name)
click to toggle source
# File lib/git_bundle/repository.rb, line 55 def remote_exists?(remote_name) execute_git('remote').split("\n").include?(remote_name) end
revision()
click to toggle source
# File lib/git_bundle/repository.rb, line 38 def revision @revision ||= execute_git('rev-parse', '--verify', 'HEAD').gsub("\n", '') end
stale?()
click to toggle source
# File lib/git_bundle/repository.rb, line 46 def stale? revision != locked_revision end
stale_commits()
click to toggle source
# File lib/git_bundle/repository.rb, line 63 def stale_commits execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', "#{locked_revision}..#{revision}") end
stale_commits_count()
click to toggle source
# File lib/git_bundle/repository.rb, line 67 def stale_commits_count execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', '--count', "#{locked_revision}..#{revision}").to_i end
upstream_branch_exists?()
click to toggle source
# File lib/git_bundle/repository.rb, line 59 def upstream_branch_exists? reference_exists?("#{remote}/#{branch}") end