right_git 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/VERSION +1 -1
- data/lib/right_git/git/belongs_to_repository.rb +9 -0
- data/lib/right_git/git/branch.rb +22 -10
- data/lib/right_git/git/branch_collection.rb +97 -17
- data/lib/right_git/git/commit.rb +21 -9
- data/lib/right_git/git/repository.rb +33 -24
- data/lib/right_git/git/tag.rb +10 -4
- data/lib/right_git/git.rb +8 -6
- data/lib/right_git/shell/default.rb +7 -14
- data/lib/right_git/shell/interface.rb +5 -7
- data/lib/right_git/shell.rb +4 -3
- data/right_git.gemspec +13 -8
- metadata +44 -16
data/.rspec
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/right_git/git/branch.rb
CHANGED
@@ -29,8 +29,16 @@ module RightGit::Git
|
|
29
29
|
# like a string, whose value is the name of the branch. This allows branches
|
30
30
|
# to be sorted, matched against Regexp, and certain other string-y operations.
|
31
31
|
class Branch
|
32
|
-
|
32
|
+
include ::RightGit::Git::BelongsToRepository
|
33
|
+
|
34
|
+
# Regexp fragment that matches a valid Git branch name consisting of alphanumerics
|
35
|
+
# plus the punctuation characters "#", "." "_", "/" and "-".
|
36
|
+
BRANCH_NAME = '[#A-Za-z0-9._\/+-]+'
|
37
|
+
|
38
|
+
# Regexp that matches a line of Git output containing information about a branch.
|
33
39
|
BRANCH_INFO = /^(\* | )?(#{BRANCH_NAME})( -> #{BRANCH_NAME})?$/
|
40
|
+
|
41
|
+
# Regexp that matches a valid Git branch name, possibly prepended by "remotes/"
|
34
42
|
BRANCH_FULLNAME = /(remotes\/)?(#{BRANCH_NAME})/
|
35
43
|
|
36
44
|
DEFAULT_DISPLAY_WIDTH = 40
|
@@ -39,7 +47,7 @@ module RightGit::Git
|
|
39
47
|
|
40
48
|
class BranchError < GitError; end
|
41
49
|
|
42
|
-
attr_reader :
|
50
|
+
attr_reader :fullname
|
43
51
|
|
44
52
|
# @param [Repository] repo hosting branch
|
45
53
|
# @param [String] line of git output describing branch
|
@@ -52,18 +60,22 @@ module RightGit::Git
|
|
52
60
|
@remote = !!(match[1] || fullname.index('/'))
|
53
61
|
@repo = repo
|
54
62
|
else
|
55
|
-
raise BranchError,
|
63
|
+
raise BranchError, "Internal error; matched info but not fullname of #{line.inspect}"
|
56
64
|
end
|
57
65
|
else
|
58
|
-
raise BranchError, "
|
66
|
+
raise BranchError, "Malformed branch name #{line.inspect}"
|
59
67
|
end
|
60
68
|
end
|
61
69
|
|
62
|
-
#
|
70
|
+
# Provide a String representation of this branch (specifically, its fullname).
|
63
71
|
def to_s
|
64
|
-
|
72
|
+
fullname.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
# Provide a programmer-friendly representation of this branch.
|
76
|
+
def inspect
|
77
|
+
'#<%s:%s>' % [self.class.name, fullname.inspect]
|
65
78
|
end
|
66
|
-
alias inspect to_s
|
67
79
|
|
68
80
|
# @param [Regexp] regexp
|
69
81
|
# @return [Integer] match offset
|
@@ -96,7 +108,7 @@ module RightGit::Git
|
|
96
108
|
@remote
|
97
109
|
end
|
98
110
|
|
99
|
-
# @return [String] name of branch sans
|
111
|
+
# @return [String] name of branch sans name of remote (if any)
|
100
112
|
def name
|
101
113
|
if remote?
|
102
114
|
#remove the initial remote-name in the branch (origin/master --> master)
|
@@ -126,9 +138,9 @@ module RightGit::Git
|
|
126
138
|
# @return [TrueClass] always true
|
127
139
|
def delete
|
128
140
|
if self.remote?
|
129
|
-
|
141
|
+
repo.vet_output("push origin :#{self.name}")
|
130
142
|
else
|
131
|
-
|
143
|
+
repo.vet_output("branch -D #{@fullname}")
|
132
144
|
end
|
133
145
|
true
|
134
146
|
end
|
@@ -28,38 +28,103 @@ module RightGit::Git
|
|
28
28
|
# A collection of Git branches. Acts a bit like an Array, allowing it to be
|
29
29
|
# mapped, sorted and compared as such.
|
30
30
|
class BranchCollection
|
31
|
+
include ::RightGit::Git::BelongsToRepository
|
32
|
+
|
33
|
+
# Regexp matching (and capturing) the output of 'git symbolic-ref'; used to determine which
|
34
|
+
# branch is currently checked out.
|
35
|
+
HEAD_REF = %r{^refs/heads/(#{Branch::BRANCH_NAME})$}
|
36
|
+
|
37
|
+
# The output of 'git symbolic-ref' when the HEAD ref is not on any branch.
|
38
|
+
NO_HEAD_REF = /^HEAD is not a symbolic ref$/
|
39
|
+
|
40
|
+
# The output of the 'git branch' command when the HEAD ref is not on any branch.
|
41
|
+
# This is not useful to RightGit, so we must filter it out of Git's output when
|
42
|
+
# we see it.
|
43
|
+
NO_BRANCH = '* (no branch)'
|
44
|
+
|
45
|
+
# Create a new BranchCollection. Don't pass in a branches parameter unless you really know
|
46
|
+
# what you're doing; it's intended more for internal use than anything else.
|
47
|
+
#
|
31
48
|
# @param [Repository] repo to host branch collection
|
32
|
-
# @param [Array]
|
33
|
-
def initialize(repo,
|
49
|
+
# @param optional [Array] branches an array of Branch objects, or nil to auto-populate this collection with ALL branches
|
50
|
+
def initialize(repo, branches=nil)
|
34
51
|
@repo = repo
|
35
|
-
|
52
|
+
|
53
|
+
if branches
|
54
|
+
# Use an arbitrary set of branches that was passed in
|
55
|
+
@branches = branches
|
56
|
+
else
|
57
|
+
@branches = []
|
58
|
+
|
59
|
+
# Initialize ourselves with all branches in the repository
|
60
|
+
git_args = ['branch', '-a']
|
61
|
+
@repo.git_output(git_args).lines.each do |line|
|
62
|
+
line.strip!
|
63
|
+
|
64
|
+
if line == NO_BRANCH
|
65
|
+
#no-op; ignore this one
|
66
|
+
else
|
67
|
+
@branches << Branch.new(@repo, line)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
36
71
|
end
|
37
72
|
|
73
|
+
# Provide a String representation of this collection, depicting it as a comma-separated list of
|
74
|
+
# branch names.
|
38
75
|
def to_s
|
39
|
-
|
76
|
+
@branches.join(',')
|
40
77
|
end
|
41
|
-
alias inspect to_s
|
42
78
|
|
43
|
-
#
|
79
|
+
# Provide a programmer-friendly representation of this collection.
|
80
|
+
def inspect
|
81
|
+
'#<%s:%s>' % [self.class.name, @branches.inspect]
|
82
|
+
end
|
83
|
+
|
84
|
+
# Return a Branch object representing whichever branch is currently checked out, IF AND ONLY IF
|
85
|
+
# that branch is a member of the collection. If the current branch isn't part of the collection
|
86
|
+
# or HEAD refers to something other than a branch, return nil.
|
87
|
+
#
|
88
|
+
# @return [Branch] the current branch if any, nil otherwise
|
89
|
+
def current
|
90
|
+
lines = @repo.git_output(['symbolic-ref', 'HEAD'], :raise_on_failure => false).lines
|
91
|
+
|
92
|
+
if lines.size == 1
|
93
|
+
line = lines.first.strip
|
94
|
+
if (match = HEAD_REF.match(line))
|
95
|
+
@branches.detect { |b| b.fullname == match[1] }
|
96
|
+
elsif line == NO_HEAD_REF
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
else
|
100
|
+
raise GitError, "Unexpected output from 'git symbolic-ref'; need 1 lines, got #{lines.size}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Return another collection that contains only the local branches in this collection.
|
44
105
|
#
|
45
106
|
# @return [BranchCollection] local branches
|
46
107
|
def local
|
47
|
-
local =
|
108
|
+
local = []
|
109
|
+
|
48
110
|
@branches.each do |branch|
|
49
111
|
local << branch unless branch.remote?
|
50
112
|
end
|
51
|
-
|
113
|
+
|
114
|
+
BranchCollection.new(@repo, local)
|
52
115
|
end
|
53
116
|
|
54
|
-
#
|
117
|
+
# Return another collection that contains only the local branches in this collection.
|
55
118
|
#
|
56
119
|
# @return [BranchCollection] remote branches
|
57
120
|
def remote
|
58
|
-
remote =
|
121
|
+
remote = []
|
122
|
+
|
59
123
|
@branches.each do |branch|
|
60
124
|
remote << branch if branch.remote?
|
61
125
|
end
|
62
|
-
|
126
|
+
|
127
|
+
BranchCollection.new(@repo, remote)
|
63
128
|
end
|
64
129
|
|
65
130
|
# Queries and filters on branches reachable from the given revision, if any.
|
@@ -68,18 +133,23 @@ module RightGit::Git
|
|
68
133
|
#
|
69
134
|
# @return [BranchCollection] merged branches
|
70
135
|
def merged(revision)
|
71
|
-
|
72
|
-
|
73
|
-
|
136
|
+
# By hand, build a list of all branches known to be merged into master
|
137
|
+
git_args = ['branch', '-a', '--merged', revision]
|
138
|
+
all_merged = []
|
139
|
+
@repo.git_output(git_args).lines.each do |line|
|
140
|
+
line.strip!
|
141
|
+
all_merged << Branch.new(@repo, line)
|
74
142
|
end
|
75
143
|
|
76
|
-
|
144
|
+
# Filter the contents of this collection according to the big list
|
145
|
+
merged = []
|
77
146
|
@branches.each do |candidate|
|
78
147
|
# For some reason Set#include? does not play nice with our overridden comparison operators
|
79
148
|
# for branches, so we need to do this the hard way :(
|
80
149
|
merged << candidate if all_merged.detect { |b| candidate == b }
|
81
150
|
end
|
82
|
-
|
151
|
+
|
152
|
+
BranchCollection.new(@repo, merged)
|
83
153
|
end
|
84
154
|
|
85
155
|
# Accessor that acts like either a Hash or Array accessor
|
@@ -93,15 +163,25 @@ module RightGit::Git
|
|
93
163
|
end
|
94
164
|
end
|
95
165
|
|
166
|
+
# Dispatch to the underlying Array of Branch objects, allowing the branch collection to act a
|
167
|
+
# bit like an Array.
|
168
|
+
#
|
169
|
+
# If the dispatched-to method returns an Array, it is wrapped in another BranchCollection object
|
170
|
+
# before returning to the caller. This allows array-like method calls to be chained together
|
171
|
+
# without losing the BranchCollection-ness of the underlying object.
|
96
172
|
def method_missing(meth, *args, &block)
|
97
173
|
result = @branches.__send__(meth, *args, &block)
|
98
174
|
|
99
175
|
if result.is_a?(::Array)
|
100
|
-
BranchCollection.new(@repo,
|
176
|
+
BranchCollection.new(@repo, result)
|
101
177
|
else
|
102
178
|
result
|
103
179
|
end
|
104
180
|
end
|
105
181
|
|
182
|
+
# Polite implementation of #respond_to that honors our #method_missing.
|
183
|
+
def respond_to?(meth)
|
184
|
+
super || @branches.respond_to?(meth)
|
185
|
+
end
|
106
186
|
end # BranchCollection
|
107
187
|
end # RightGit
|
data/lib/right_git/git/commit.rb
CHANGED
@@ -27,12 +27,12 @@ module RightGit::Git
|
|
27
27
|
|
28
28
|
# A commit within a Git repository.
|
29
29
|
class Commit
|
30
|
-
|
31
|
-
|
30
|
+
include ::RightGit::Git::BelongsToRepository
|
31
|
+
LOG_FORMAT_LONG = "%H %at %aE %s"
|
32
|
+
LOG_FORMAT = "%h %at %aE %s"
|
33
|
+
COMMIT_INFO = /^([0-9A-Fa-f]+) ([0-9]+) (\S+) (.*)$/
|
32
34
|
COMMIT_SHA1_REGEX = /^[0-9a-fA-F]{40}$/
|
33
35
|
|
34
|
-
attr_reader :repo
|
35
|
-
|
36
36
|
class CommitError < GitError; end
|
37
37
|
|
38
38
|
# @param [Repository] repo hosting commit
|
@@ -42,18 +42,23 @@ module RightGit::Git
|
|
42
42
|
unless match = COMMIT_INFO.match(line)
|
43
43
|
raise CommitError, "Unrecognized commit summary: #{line.inspect}"
|
44
44
|
end
|
45
|
-
@info = [ match[1], Integer(match[2]), match[3] ]
|
45
|
+
@info = [ match[1], Integer(match[2]), match[3], match[4] ]
|
46
46
|
end
|
47
47
|
|
48
|
-
#
|
48
|
+
# Provide a String representation of this commit (specifically, its commit hash).
|
49
49
|
def to_s
|
50
|
-
|
50
|
+
hash
|
51
|
+
end
|
52
|
+
|
53
|
+
# Provide a programmer-friendly representation of this branch.
|
54
|
+
def inspect
|
55
|
+
'#<%s:%s>' % [self.class.name, hash]
|
51
56
|
end
|
52
|
-
alias inspect to_s
|
53
57
|
|
58
|
+
# The commit hash. This overrides String#hash on purpose
|
59
|
+
#
|
54
60
|
# @return [String] hash of commit (may be abbreviated)
|
55
61
|
def hash
|
56
|
-
# This overrides String#hash on purpose
|
57
62
|
@info[0]
|
58
63
|
end
|
59
64
|
|
@@ -67,6 +72,13 @@ module RightGit::Git
|
|
67
72
|
@info[2]
|
68
73
|
end
|
69
74
|
|
75
|
+
# @return [String]
|
76
|
+
def subject
|
77
|
+
@info[3]
|
78
|
+
end
|
79
|
+
|
80
|
+
alias comment subject
|
81
|
+
|
70
82
|
# @return [TrueClass|FalseClass] true if the given revision is a (fully qualified, not abbreviated) commit SHA
|
71
83
|
def self.sha?(revision)
|
72
84
|
!!COMMIT_SHA1_REGEX.match(revision)
|
@@ -23,6 +23,9 @@
|
|
23
23
|
# ancestor
|
24
24
|
require 'right_git/git'
|
25
25
|
|
26
|
+
# dependencies
|
27
|
+
require 'right_support'
|
28
|
+
|
26
29
|
module RightGit::Git
|
27
30
|
|
28
31
|
# Provides an API for managing a git repository that is suitable for
|
@@ -31,28 +34,32 @@ module RightGit::Git
|
|
31
34
|
# not covered here. What is provided are APIs for cloning, fetching, listing
|
32
35
|
# and grooming git-related objects.
|
33
36
|
class Repository
|
37
|
+
include RightSupport::Log::Mixin
|
38
|
+
|
34
39
|
COMMIT_SHA1_REGEX = /^commit ([0-9a-fA-F]{40})$/
|
35
40
|
|
36
41
|
SUBMODULE_STATUS_REGEX = /^([+\- ])([0-9a-fA-F]{40}) (.*) (.*)$/
|
37
42
|
|
38
|
-
attr_reader :repo_dir, :
|
43
|
+
attr_reader :repo_dir, :shell
|
39
44
|
|
40
45
|
# @param [String] repo_dir for git actions or '.'
|
41
46
|
# @param [Hash] options for repository
|
42
47
|
# @option options [Object] :shell for git command execution (default = DefaultShell)
|
43
|
-
# @option options [Logger] :logger
|
48
|
+
# @option options [Logger] :logger custom logger to use; (default = class-level logger provided by Log::Mixin)
|
44
49
|
def initialize(repo_dir, options = {})
|
45
50
|
options = {
|
46
51
|
:shell => nil,
|
47
52
|
:logger => nil
|
48
53
|
}.merge(options)
|
54
|
+
|
49
55
|
if repo_dir && ::File.directory?(repo_dir)
|
50
56
|
@repo_dir = ::File.expand_path(repo_dir)
|
51
57
|
else
|
52
58
|
raise ::ArgumentError.new('A valid repo_dir is required')
|
53
59
|
end
|
60
|
+
|
54
61
|
@shell = options[:shell] || ::RightGit::Shell::Default
|
55
|
-
|
62
|
+
self.logger = options[:logger] || self.class.logger
|
56
63
|
end
|
57
64
|
|
58
65
|
# Factory method to clone the repo given by URL to the given destination and
|
@@ -110,12 +117,19 @@ module RightGit::Git
|
|
110
117
|
true
|
111
118
|
end
|
112
119
|
|
113
|
-
#
|
120
|
+
# @deprecated alias for #branch
|
121
|
+
def branch_for(branch_name)
|
122
|
+
warn "#{self.class.name}#branch_for is deprecated; please use #{self.class.name}#branch instead"
|
123
|
+
branch(branch_name)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Factory method for a branch object referencing this repository. The branch may be
|
127
|
+
# hypothetical (e.g. does not exist yet).
|
114
128
|
#
|
115
129
|
# @param [String] branch_name for reference
|
116
130
|
#
|
117
131
|
# @return [Branch] new branch
|
118
|
-
def
|
132
|
+
def branch(branch_name)
|
119
133
|
Branch.new(self, branch_name)
|
120
134
|
end
|
121
135
|
|
@@ -123,25 +137,17 @@ module RightGit::Git
|
|
123
137
|
# directory.
|
124
138
|
#
|
125
139
|
# @param [Hash] options for branches
|
126
|
-
# @option options [
|
140
|
+
# @option options [Boolean] :all true to include remote branches, else local only (default)
|
127
141
|
#
|
128
142
|
# @return [Array] list of branches
|
129
143
|
def branches(options = {})
|
130
|
-
options = {
|
131
|
-
:all => true
|
132
|
-
}.merge(options)
|
133
|
-
git_args = ['branch']
|
134
|
-
git_args << '-a' if options[:all] # note older versions of git don't accept --all
|
135
144
|
branches = BranchCollection.new(self)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
branches << branch if branch
|
142
|
-
end
|
145
|
+
|
146
|
+
if options[:all]
|
147
|
+
branches
|
148
|
+
else
|
149
|
+
branches.local
|
143
150
|
end
|
144
|
-
branches
|
145
151
|
end
|
146
152
|
|
147
153
|
# Factory method for a tag object referencing this repository.
|
@@ -166,6 +172,7 @@ module RightGit::Git
|
|
166
172
|
# @param [Hash] options for log
|
167
173
|
# @option options [Integer] :skip as lines of most recent history to skip (Default = include most recent)
|
168
174
|
# @option options [Integer] :tail as max history of log
|
175
|
+
# @option options [TrueClass|FalseClass] :merges as true to exclude non-merge commits
|
169
176
|
# @option options [TrueClass|FalseClass] :no_merges as true to exclude merge commits
|
170
177
|
# @option options [TrueClass|FalseClass] :full_hashes as true show full hashes, false for (7-character) abbreviations
|
171
178
|
#
|
@@ -173,7 +180,8 @@ module RightGit::Git
|
|
173
180
|
def log(revision, options = {})
|
174
181
|
options = {
|
175
182
|
:skip => nil,
|
176
|
-
:tail =>
|
183
|
+
:tail => 10_000,
|
184
|
+
:merges => false,
|
177
185
|
:no_merges => false,
|
178
186
|
:full_hashes => false,
|
179
187
|
}.merge(options)
|
@@ -181,12 +189,13 @@ module RightGit::Git
|
|
181
189
|
git_args = [
|
182
190
|
'log',
|
183
191
|
"-n#{options[:tail]}",
|
184
|
-
"--format=\"
|
192
|
+
"--format=\"#{options[:full_hashes] ? Commit::LOG_FORMAT_LONG : Commit::LOG_FORMAT}\"" # double-quotes are Windows friendly
|
185
193
|
]
|
186
194
|
git_args << "--skip #{skip}" if skip
|
195
|
+
git_args << "--merges" if options[:merges]
|
187
196
|
git_args << "--no-merges" if options[:no_merges]
|
188
197
|
git_args << revision if revision
|
189
|
-
git_output(git_args).lines.map { |line| Commit.new(self, line) }
|
198
|
+
git_output(git_args).lines.map { |line| Commit.new(self, line.strip) }
|
190
199
|
end
|
191
200
|
|
192
201
|
# Cleans the current repository of untracked files.
|
@@ -359,9 +368,9 @@ module RightGit::Git
|
|
359
368
|
shell.send(
|
360
369
|
shell_method,
|
361
370
|
['git', git_args].flatten.join(' '),
|
362
|
-
:logger => logger,
|
363
371
|
:directory => @repo_dir,
|
364
|
-
:clear_env_vars => CLEAR_GIT_ENV_VARS
|
372
|
+
:clear_env_vars => CLEAR_GIT_ENV_VARS,
|
373
|
+
:logger => logger)
|
365
374
|
end
|
366
375
|
|
367
376
|
end # Repository
|
data/lib/right_git/git/tag.rb
CHANGED
@@ -27,7 +27,9 @@ module RightGit::Git
|
|
27
27
|
|
28
28
|
# A tag in a Git repository.
|
29
29
|
class Tag
|
30
|
-
|
30
|
+
include ::RightGit::Git::BelongsToRepository
|
31
|
+
|
32
|
+
attr_reader :name
|
31
33
|
|
32
34
|
class TagError < GitError; end
|
33
35
|
|
@@ -44,11 +46,15 @@ module RightGit::Git
|
|
44
46
|
@name = name
|
45
47
|
end
|
46
48
|
|
47
|
-
# @return [String]
|
49
|
+
# @return [String] the tag's name
|
48
50
|
def to_s
|
49
|
-
|
51
|
+
name
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String] info about this Ruby object
|
55
|
+
def inspect
|
56
|
+
"#<#{self.class.name}:#{name.inspect}>"
|
50
57
|
end
|
51
|
-
alias inspect to_s
|
52
58
|
|
53
59
|
# @param [Tag] other
|
54
60
|
# @return [TrueClass|FalseClass] true if equivalent
|
data/lib/right_git/git.rb
CHANGED
@@ -26,11 +26,13 @@ require 'right_git'
|
|
26
26
|
module RightGit
|
27
27
|
module Git
|
28
28
|
class GitError < RightGitError; end
|
29
|
-
|
30
|
-
autoload :Branch, 'right_git/git/branch'
|
31
|
-
autoload :BranchCollection, 'right_git/git/branch_collection'
|
32
|
-
autoload :Commit, 'right_git/git/commit'
|
33
|
-
autoload :Repository, 'right_git/git/repository'
|
34
|
-
autoload :Tag, 'right_git/git/tag'
|
35
29
|
end
|
36
30
|
end
|
31
|
+
|
32
|
+
# module contents
|
33
|
+
require 'right_git/git/belongs_to_repository'
|
34
|
+
require 'right_git/git/branch'
|
35
|
+
require 'right_git/git/branch_collection'
|
36
|
+
require 'right_git/git/commit'
|
37
|
+
require 'right_git/git/repository'
|
38
|
+
require 'right_git/git/tag'
|
@@ -24,7 +24,6 @@
|
|
24
24
|
require 'right_git/shell'
|
25
25
|
|
26
26
|
# local
|
27
|
-
require 'logger'
|
28
27
|
require 'stringio'
|
29
28
|
require 'singleton'
|
30
29
|
|
@@ -33,33 +32,27 @@ module RightGit::Shell
|
|
33
32
|
# Default shell singleton implementation.
|
34
33
|
class Default
|
35
34
|
include ::RightGit::Shell::Interface
|
36
|
-
include ::
|
35
|
+
include ::RightSupport::Ruby::EasySingleton
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
def self.method_missing(method_sym, *arguments, &block)
|
43
|
-
if instance.respond_to?(method_sym)
|
44
|
-
instance.send(method_sym, *arguments, &block)
|
45
|
-
else
|
46
|
-
super
|
47
|
-
end
|
37
|
+
# Delegates to the RightGit class logger.
|
38
|
+
def default_logger
|
39
|
+
::RightGit::Git::Repository.logger
|
48
40
|
end
|
49
41
|
|
50
42
|
# Implements execute interface.
|
51
43
|
def execute(cmd, options = {})
|
52
44
|
options = {
|
53
45
|
:directory => nil,
|
54
|
-
:logger => nil,
|
55
46
|
:outstream => nil,
|
56
47
|
:raise_on_failure => true,
|
57
48
|
:set_env_vars => nil,
|
58
49
|
:clear_env_vars => nil,
|
50
|
+
:logger => default_logger
|
59
51
|
}.merge(options)
|
60
|
-
logger = options[:logger] || default_logger
|
61
52
|
outstream = options[:outstream]
|
62
53
|
|
54
|
+
logger = options[:logger]
|
55
|
+
|
63
56
|
# build execution block.
|
64
57
|
exitstatus = nil
|
65
58
|
executioner = lambda do
|
@@ -23,19 +23,18 @@
|
|
23
23
|
# ancestor
|
24
24
|
require 'right_git/shell'
|
25
25
|
|
26
|
-
# local
|
27
|
-
require 'logger'
|
28
|
-
|
29
26
|
module RightGit::Shell
|
30
27
|
|
31
28
|
# Interface for a shell intended to work with RightGit.
|
32
29
|
module Interface
|
33
30
|
|
34
|
-
#
|
31
|
+
# Return a logger object to be used for logging if nothing else is passed in as an option.
|
32
|
+
#
|
33
|
+
# Must be overridden.
|
35
34
|
#
|
36
|
-
# @return [Logger]
|
35
|
+
# @return [Logger]
|
37
36
|
def default_logger
|
38
|
-
|
37
|
+
raise NotImplementedError
|
39
38
|
end
|
40
39
|
|
41
40
|
# Run the given command and print the output to stdout.
|
@@ -45,7 +44,6 @@ module RightGit::Shell
|
|
45
44
|
# @param [String] cmd the shell command to run
|
46
45
|
# @param [Hash] options for execution
|
47
46
|
# @option options :directory [String] to use as working directory during command execution or nil
|
48
|
-
# @option options :logger [Logger] logger for shell execution (default = STDOUT)
|
49
47
|
# @option options :outstream [IO] output stream to receive STDOUT and STDERR from command (default = STDOUT)
|
50
48
|
# @option options :raise_on_failure [TrueClass|FalseClass] if true, wil raise a RuntimeError if the command does not end successfully (default), false to ignore errors
|
51
49
|
# @option options :set_env_vars [Hash] environment variables to set during execution (default = none set)
|
data/lib/right_git/shell.rb
CHANGED
@@ -26,8 +26,9 @@ require 'right_git'
|
|
26
26
|
module RightGit
|
27
27
|
module Shell
|
28
28
|
class ShellError < RightGitError; end
|
29
|
-
|
30
|
-
autoload :Default, 'right_git/shell/default'
|
31
|
-
autoload :Interface, 'right_git/shell/interface'
|
32
29
|
end
|
33
30
|
end
|
31
|
+
|
32
|
+
# Module contents
|
33
|
+
require 'right_git/shell/interface'
|
34
|
+
require 'right_git/shell/default'
|
data/right_git.gemspec
CHANGED
@@ -4,19 +4,20 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.0
|
7
|
+
s.name = %q{right_git}
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tony Spataro", "Scott Messier"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = %q{2014-01-16}
|
13
|
+
s.description = %q{An assortment of git-related classes created by RightScale.}
|
14
|
+
s.email = %q{support@rightscale.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
+
".rspec",
|
20
21
|
"CHANGELOG.rdoc",
|
21
22
|
"LICENSE",
|
22
23
|
"README.rdoc",
|
@@ -24,6 +25,7 @@ Gem::Specification.new do |s|
|
|
24
25
|
"VERSION",
|
25
26
|
"lib/right_git.rb",
|
26
27
|
"lib/right_git/git.rb",
|
28
|
+
"lib/right_git/git/belongs_to_repository.rb",
|
27
29
|
"lib/right_git/git/branch.rb",
|
28
30
|
"lib/right_git/git/branch_collection.rb",
|
29
31
|
"lib/right_git/git/commit.rb",
|
@@ -34,25 +36,28 @@ Gem::Specification.new do |s|
|
|
34
36
|
"lib/right_git/shell/interface.rb",
|
35
37
|
"right_git.gemspec"
|
36
38
|
]
|
37
|
-
s.homepage =
|
39
|
+
s.homepage = %q{https://github.com/rightscale/right_git}
|
38
40
|
s.licenses = ["MIT"]
|
39
41
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version =
|
41
|
-
s.summary =
|
42
|
+
s.rubygems_version = %q{1.6.2}
|
43
|
+
s.summary = %q{Reusable Git repository management code.}
|
42
44
|
|
43
45
|
if s.respond_to? :specification_version then
|
44
46
|
s.specification_version = 3
|
45
47
|
|
46
48
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<right_support>, ["< 3.0.0", ">= 2.8.10"])
|
47
50
|
s.add_development_dependency(%q<rake>, ["< 0.10", ">= 0.8.7"])
|
48
51
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
49
52
|
s.add_development_dependency(%q<nokogiri>, ["= 1.5.6"])
|
50
53
|
else
|
54
|
+
s.add_dependency(%q<right_support>, ["< 3.0.0", ">= 2.8.10"])
|
51
55
|
s.add_dependency(%q<rake>, ["< 0.10", ">= 0.8.7"])
|
52
56
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
53
57
|
s.add_dependency(%q<nokogiri>, ["= 1.5.6"])
|
54
58
|
end
|
55
59
|
else
|
60
|
+
s.add_dependency(%q<right_support>, ["< 3.0.0", ">= 2.8.10"])
|
56
61
|
s.add_dependency(%q<rake>, ["< 0.10", ">= 0.8.7"])
|
57
62
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
58
63
|
s.add_dependency(%q<nokogiri>, ["= 1.5.6"])
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.3
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Spataro
|
@@ -16,10 +16,36 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2014-01-16 00:00:00 -08:00
|
20
|
+
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
23
|
+
type: :runtime
|
22
24
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - <
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 3.0.0
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
hash: 59
|
38
|
+
segments:
|
39
|
+
- 2
|
40
|
+
- 8
|
41
|
+
- 10
|
42
|
+
version: 2.8.10
|
43
|
+
prerelease: false
|
44
|
+
requirement: *id001
|
45
|
+
name: right_support
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
type: :development
|
48
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
23
49
|
none: false
|
24
50
|
requirements:
|
25
51
|
- - <
|
@@ -37,12 +63,12 @@ dependencies:
|
|
37
63
|
- 8
|
38
64
|
- 7
|
39
65
|
version: 0.8.7
|
40
|
-
name: rake
|
41
66
|
prerelease: false
|
42
|
-
|
43
|
-
|
67
|
+
requirement: *id002
|
68
|
+
name: rake
|
44
69
|
- !ruby/object:Gem::Dependency
|
45
|
-
|
70
|
+
type: :development
|
71
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
46
72
|
none: false
|
47
73
|
requirements:
|
48
74
|
- - ~>
|
@@ -53,12 +79,12 @@ dependencies:
|
|
53
79
|
- 8
|
54
80
|
- 3
|
55
81
|
version: 1.8.3
|
56
|
-
name: jeweler
|
57
82
|
prerelease: false
|
58
|
-
|
59
|
-
|
83
|
+
requirement: *id003
|
84
|
+
name: jeweler
|
60
85
|
- !ruby/object:Gem::Dependency
|
61
|
-
|
86
|
+
type: :development
|
87
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
62
88
|
none: false
|
63
89
|
requirements:
|
64
90
|
- - "="
|
@@ -69,10 +95,9 @@ dependencies:
|
|
69
95
|
- 5
|
70
96
|
- 6
|
71
97
|
version: 1.5.6
|
72
|
-
name: nokogiri
|
73
98
|
prerelease: false
|
74
|
-
|
75
|
-
|
99
|
+
requirement: *id004
|
100
|
+
name: nokogiri
|
76
101
|
description: An assortment of git-related classes created by RightScale.
|
77
102
|
email: support@rightscale.com
|
78
103
|
executables: []
|
@@ -83,6 +108,7 @@ extra_rdoc_files:
|
|
83
108
|
- LICENSE
|
84
109
|
- README.rdoc
|
85
110
|
files:
|
111
|
+
- .rspec
|
86
112
|
- CHANGELOG.rdoc
|
87
113
|
- LICENSE
|
88
114
|
- README.rdoc
|
@@ -90,6 +116,7 @@ files:
|
|
90
116
|
- VERSION
|
91
117
|
- lib/right_git.rb
|
92
118
|
- lib/right_git/git.rb
|
119
|
+
- lib/right_git/git/belongs_to_repository.rb
|
93
120
|
- lib/right_git/git/branch.rb
|
94
121
|
- lib/right_git/git/branch_collection.rb
|
95
122
|
- lib/right_git/git/commit.rb
|
@@ -99,6 +126,7 @@ files:
|
|
99
126
|
- lib/right_git/shell/default.rb
|
100
127
|
- lib/right_git/shell/interface.rb
|
101
128
|
- right_git.gemspec
|
129
|
+
has_rdoc: true
|
102
130
|
homepage: https://github.com/rightscale/right_git
|
103
131
|
licenses:
|
104
132
|
- MIT
|
@@ -128,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
156
|
requirements: []
|
129
157
|
|
130
158
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.
|
159
|
+
rubygems_version: 1.6.2
|
132
160
|
signing_key:
|
133
161
|
specification_version: 3
|
134
162
|
summary: Reusable Git repository management code.
|