Class: GitBundle::Repository
- Inherits:
-
Object
- Object
- GitBundle::Repository
show all
- Includes:
- Shell
- Defined in:
- lib/git_bundle/repository.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_file(filename) ⇒ Object
-
#checkout(args) ⇒ Object
-
#commit(message, *files) ⇒ Object
-
#commit_with_description(message, description, *files) ⇒ Object
-
#commits_not_pushed ⇒ Object
-
#commits_not_pushed? ⇒ Boolean
-
#commits_not_pushed_count ⇒ Object
-
#execute_git(*args, **options) ⇒ Object
-
#execute_git_output(*args, **options) ⇒ Object
-
#file_changed?(filename) ⇒ Boolean
-
#git_command(*args, **options) ⇒ Object
-
#initialize(name, path, main_repository, locked_branch, locked_revision) ⇒ Repository
constructor
A new instance of Repository.
-
#locked_revision ⇒ Object
-
#push(args, create_upstream: false) ⇒ Object
-
#reference_exists?(reference) ⇒ Boolean
-
#refresh_branch ⇒ Object
-
#revision ⇒ Object
-
#stale? ⇒ Boolean
-
#stale_commits ⇒ Object
-
#stale_commits_count ⇒ Object
-
#upstream_branch_exists? ⇒ Boolean
Methods included from Shell
#execute, #execute_live, #execute_pipe
Constructor Details
#initialize(name, path, main_repository, locked_branch, locked_revision) ⇒ Repository
Returns a new instance of Repository.
19
20
21
22
23
24
25
26
|
# File 'lib/git_bundle/repository.rb', line 19
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
|
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
5
6
7
|
# File 'lib/git_bundle/repository.rb', line 5
def branch
@branch
end
|
#locked_branch ⇒ Object
Returns the value of attribute locked_branch.
5
6
7
|
# File 'lib/git_bundle/repository.rb', line 5
def locked_branch
@locked_branch
end
|
#main ⇒ Object
Returns the value of attribute main.
5
6
7
|
# File 'lib/git_bundle/repository.rb', line 5
def main
@main
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/git_bundle/repository.rb', line 5
def name
@name
end
|
#path ⇒ Object
Returns the value of attribute path.
5
6
7
|
# File 'lib/git_bundle/repository.rb', line 5
def path
@path
end
|
Class Method Details
.new_dependant(name, path, locked_branch, locked_revision) ⇒ Object
15
16
17
|
# File 'lib/git_bundle/repository.rb', line 15
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
11
12
13
|
# File 'lib/git_bundle/repository.rb', line 11
def self.new_main(name, path)
GitBundle::Repository.new(name, path, true, nil, nil)
end
|
Instance Method Details
#add_file(filename) ⇒ Object
93
94
95
96
|
# File 'lib/git_bundle/repository.rb', line 93
def add_file(filename)
execute_git('add', filename)
$?.exitstatus == 0
end
|
#checkout(args) ⇒ Object
84
85
86
87
|
# File 'lib/git_bundle/repository.rb', line 84
def checkout(args)
execute_git_output('checkout', args)
$?.exitstatus == 0
end
|
#commit(message, *files) ⇒ Object
98
99
100
101
|
# File 'lib/git_bundle/repository.rb', line 98
def commit(message, *files)
execute_git('commit', '-m', message, files)
$?.exitstatus == 0
end
|
#commit_with_description(message, description, *files) ⇒ Object
103
104
105
106
|
# File 'lib/git_bundle/repository.rb', line 103
def commit_with_description(message, description, *files)
execute_git('commit', '-m', message, '-m', description, files)
$?.exitstatus == 0
end
|
#commits_not_pushed ⇒ Object
70
71
72
|
# File 'lib/git_bundle/repository.rb', line 70
def commits_not_pushed
execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', "origin/#{branch}..#{branch}")
end
|
#commits_not_pushed? ⇒ Boolean
65
66
67
68
|
# File 'lib/git_bundle/repository.rb', line 65
def commits_not_pushed?
return true unless upstream_branch_exists?
commits_not_pushed_count > 0
end
|
#commits_not_pushed_count ⇒ Object
74
75
76
|
# File 'lib/git_bundle/repository.rb', line 74
def commits_not_pushed_count
execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', '--count', "origin/#{branch}..#{branch}").to_i
end
|
#execute_git(*args, **options) ⇒ Object
114
115
116
|
# File 'lib/git_bundle/repository.rb', line 114
def execute_git(*args, **options)
execute(*git_command(*args, **options))
end
|
#execute_git_output(*args, **options) ⇒ Object
118
119
120
|
# File 'lib/git_bundle/repository.rb', line 118
def execute_git_output(*args, **options)
execute_live(*git_command(*args, **options))
end
|
#file_changed?(filename) ⇒ Boolean
89
90
91
|
# File 'lib/git_bundle/repository.rb', line 89
def file_changed?(filename)
!execute_git('diff', '--name-only', filename).empty? && $?.exitstatus == 0
end
|
#git_command(*args, **options) ⇒ Object
108
109
110
111
112
|
# File 'lib/git_bundle/repository.rb', line 108
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 ⇒ Object
40
41
42
|
# File 'lib/git_bundle/repository.rb', line 40
def locked_revision
@locked_revision || revision
end
|
#push(args, create_upstream: false) ⇒ Object
78
79
80
81
82
|
# File 'lib/git_bundle/repository.rb', line 78
def push(args, create_upstream: false)
args = args.dup + ['--set-upstream', 'origin', branch] if create_upstream
execute_git_output('push', args)
$?.exitstatus == 0 || (create_upstream && $?.exitstatus == 128)
end
|
#reference_exists?(reference) ⇒ Boolean
48
49
50
51
|
# File 'lib/git_bundle/repository.rb', line 48
def reference_exists?(reference)
execute_git('cat-file', '-e', reference)
$?.exitstatus == 0
end
|
#refresh_branch ⇒ Object
28
29
30
|
# File 'lib/git_bundle/repository.rb', line 28
def refresh_branch
@branch = execute_git('rev-parse', '--abbrev-ref', 'HEAD').chomp
end
|
#revision ⇒ Object
36
37
38
|
# File 'lib/git_bundle/repository.rb', line 36
def revision
@revision ||= execute_git('rev-parse', '--verify', 'HEAD').gsub("\n", '')
end
|
#stale? ⇒ Boolean
44
45
46
|
# File 'lib/git_bundle/repository.rb', line 44
def stale?
revision != locked_revision
end
|
#stale_commits ⇒ Object
57
58
59
|
# File 'lib/git_bundle/repository.rb', line 57
def stale_commits
execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', "#{locked_revision}..#{revision}")
end
|
#stale_commits_count ⇒ Object
61
62
63
|
# File 'lib/git_bundle/repository.rb', line 61
def stale_commits_count
execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', '--count', "#{locked_revision}..#{revision}").to_i
end
|
#upstream_branch_exists? ⇒ Boolean
53
54
55
|
# File 'lib/git_bundle/repository.rb', line 53
def upstream_branch_exists?
reference_exists?("origin/#{branch}")
end
|