cucumber_fm-core 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENCE +20 -0
- data/lib/cucumber_f_m/aggregator.rb +65 -0
- data/lib/cucumber_f_m/comment_module/comment.rb +7 -0
- data/lib/cucumber_f_m/config.rb +37 -0
- data/lib/cucumber_f_m/cvs/git.rb +7 -0
- data/lib/cucumber_f_m/feature.rb +141 -0
- data/lib/cucumber_f_m/feature_element/background.rb +10 -0
- data/lib/cucumber_f_m/feature_element/comment.rb +13 -0
- data/lib/cucumber_f_m/feature_element/component/comments.rb +21 -0
- data/lib/cucumber_f_m/feature_element/component/information/component.rb +16 -0
- data/lib/cucumber_f_m/feature_element/component/tags.rb +108 -0
- data/lib/cucumber_f_m/feature_element/component/title.rb +26 -0
- data/lib/cucumber_f_m/feature_element/component/total_estimation.rb +42 -0
- data/lib/cucumber_f_m/feature_element/example.rb +7 -0
- data/lib/cucumber_f_m/feature_element/info.rb +13 -0
- data/lib/cucumber_f_m/feature_element/narrative.rb +7 -0
- data/lib/cucumber_f_m/feature_element/scenario.rb +15 -0
- data/lib/cucumber_f_m/feature_element/scenario_outline.rb +23 -0
- data/lib/cucumber_f_m/feature_element/step.rb +7 -0
- data/lib/cucumber_f_m/statistic.rb +31 -0
- data/lib/cucumber_f_m/tag_filter.rb +85 -0
- data/lib/cucumber_feature_manager.rb +164 -0
- data/lib/grit/lib/grit.rb +75 -0
- data/lib/grit/lib/grit/actor.rb +36 -0
- data/lib/grit/lib/grit/blame.rb +61 -0
- data/lib/grit/lib/grit/blob.rb +126 -0
- data/lib/grit/lib/grit/commit.rb +247 -0
- data/lib/grit/lib/grit/commit_stats.rb +128 -0
- data/lib/grit/lib/grit/config.rb +44 -0
- data/lib/grit/lib/grit/diff.rb +70 -0
- data/lib/grit/lib/grit/errors.rb +7 -0
- data/lib/grit/lib/grit/git-ruby.rb +267 -0
- data/lib/grit/lib/grit/git-ruby/commit_db.rb +52 -0
- data/lib/grit/lib/grit/git-ruby/file_index.rb +193 -0
- data/lib/grit/lib/grit/git-ruby/git_object.rb +350 -0
- data/lib/grit/lib/grit/git-ruby/internal/file_window.rb +58 -0
- data/lib/grit/lib/grit/git-ruby/internal/loose.rb +137 -0
- data/lib/grit/lib/grit/git-ruby/internal/pack.rb +384 -0
- data/lib/grit/lib/grit/git-ruby/internal/raw_object.rb +37 -0
- data/lib/grit/lib/grit/git-ruby/object.rb +325 -0
- data/lib/grit/lib/grit/git-ruby/repository.rb +767 -0
- data/lib/grit/lib/grit/git.rb +323 -0
- data/lib/grit/lib/grit/index.rb +122 -0
- data/lib/grit/lib/grit/lazy.rb +33 -0
- data/lib/grit/lib/grit/merge.rb +45 -0
- data/lib/grit/lib/grit/ref.rb +74 -0
- data/lib/grit/lib/grit/repo.rb +482 -0
- data/lib/grit/lib/grit/ruby1.9.rb +7 -0
- data/lib/grit/lib/grit/status.rb +151 -0
- data/lib/grit/lib/grit/submodule.rb +88 -0
- data/lib/grit/lib/grit/tag.rb +16 -0
- data/lib/grit/lib/grit/tree.rb +123 -0
- data/lib/grit/lib/open3_detach.rb +46 -0
- data/spec/cucumber_f_m/aggregator_spec.rb +210 -0
- data/spec/cucumber_f_m/comment_module/comment_spec.rb +4 -0
- data/spec/cucumber_f_m/config_spec.rb +27 -0
- data/spec/cucumber_f_m/cvs/git_spec.rb +40 -0
- data/spec/cucumber_f_m/feature_all_tags_to_scenario_spec.rb +7 -0
- data/spec/cucumber_f_m/feature_file_manipulation_spec.rb +29 -0
- data/spec/cucumber_f_m/feature_module/background_spec.rb +30 -0
- data/spec/cucumber_f_m/feature_module/comment_spec.rb +23 -0
- data/spec/cucumber_f_m/feature_module/example_spec.rb +5 -0
- data/spec/cucumber_f_m/feature_module/info_spec.rb +30 -0
- data/spec/cucumber_f_m/feature_module/narrative_spec.rb +7 -0
- data/spec/cucumber_f_m/feature_module/scenario_outline_spec.rb +39 -0
- data/spec/cucumber_f_m/feature_module/scenario_spec.rb +33 -0
- data/spec/cucumber_f_m/feature_module/step_spec.rb +7 -0
- data/spec/cucumber_f_m/feature_module/tag_spec.rb +96 -0
- data/spec/cucumber_f_m/feature_spec.rb +229 -0
- data/spec/cucumber_f_m/tag_filter_spec.rb +191 -0
- data/spec/cucumber_feature_manager_spec.rb +59 -0
- data/spec/data/feature_manager/some_ruby_file.rb +0 -0
- data/spec/spec_helper.rb +1 -0
- metadata +141 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
module Grit
|
2
|
+
|
3
|
+
class Merge
|
4
|
+
|
5
|
+
STATUS_BOTH = 'both'
|
6
|
+
STATUS_OURS = 'ours'
|
7
|
+
STATUS_THEIRS = 'theirs'
|
8
|
+
|
9
|
+
attr_reader :conflicts, :text, :sections
|
10
|
+
|
11
|
+
def initialize(str)
|
12
|
+
status = STATUS_BOTH
|
13
|
+
|
14
|
+
section = 1
|
15
|
+
@conflicts = 0
|
16
|
+
@text = {}
|
17
|
+
|
18
|
+
lines = str.split("\n")
|
19
|
+
lines.each do |line|
|
20
|
+
if /^<<<<<<< (.*?)/.match(line)
|
21
|
+
status = STATUS_OURS
|
22
|
+
@conflicts += 1
|
23
|
+
section += 1
|
24
|
+
elsif line == '======='
|
25
|
+
status = STATUS_THEIRS
|
26
|
+
elsif /^>>>>>>> (.*?)/.match(line)
|
27
|
+
status = STATUS_BOTH
|
28
|
+
section += 1
|
29
|
+
else
|
30
|
+
@text[section] ||= {}
|
31
|
+
@text[section][status] ||= []
|
32
|
+
@text[section][status] << line
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@text = @text.values
|
36
|
+
@sections = @text.size
|
37
|
+
end
|
38
|
+
|
39
|
+
# Pretty object inspection
|
40
|
+
def inspect
|
41
|
+
%Q{#<Grit::Merge}
|
42
|
+
end
|
43
|
+
end # Merge
|
44
|
+
|
45
|
+
end # Grit
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Grit
|
2
|
+
|
3
|
+
class Ref
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
# Find all Refs
|
8
|
+
# +repo+ is the Repo
|
9
|
+
# +options+ is a Hash of options
|
10
|
+
#
|
11
|
+
# Returns Grit::Ref[] (baked)
|
12
|
+
def find_all(repo, options = {})
|
13
|
+
refs = repo.git.refs(options, prefix)
|
14
|
+
refs.split("\n").map do |ref|
|
15
|
+
name, id = *ref.split(' ')
|
16
|
+
commit = Commit.create(repo, :id => id)
|
17
|
+
self.new(name, commit)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def prefix
|
24
|
+
"refs/#{name.to_s.gsub(/^.*::/, '').downcase}s"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :name
|
30
|
+
attr_reader :commit
|
31
|
+
|
32
|
+
# Instantiate a new Head
|
33
|
+
# +name+ is the name of the head
|
34
|
+
# +commit+ is the Commit that the head points to
|
35
|
+
#
|
36
|
+
# Returns Grit::Head (baked)
|
37
|
+
def initialize(name, commit)
|
38
|
+
@name = name
|
39
|
+
@commit = commit
|
40
|
+
end
|
41
|
+
|
42
|
+
# Pretty object inspection
|
43
|
+
def inspect
|
44
|
+
%Q{#<#{self.class.name} "#{@name}">}
|
45
|
+
end
|
46
|
+
end # Ref
|
47
|
+
|
48
|
+
# A Head is a named reference to a Commit. Every Head instance contains a name
|
49
|
+
# and a Commit object.
|
50
|
+
#
|
51
|
+
# r = Grit::Repo.new("/path/to/repo")
|
52
|
+
# h = r.heads.first
|
53
|
+
# h.name # => "master"
|
54
|
+
# h.commit # => #<Grit::Commit "1c09f116cbc2cb4100fb6935bb162daa4723f455">
|
55
|
+
# h.commit.id # => "1c09f116cbc2cb4100fb6935bb162daa4723f455"
|
56
|
+
class Head < Ref
|
57
|
+
|
58
|
+
# Get the HEAD revision of the repo.
|
59
|
+
# +repo+ is the Repo
|
60
|
+
# +options+ is a Hash of options
|
61
|
+
#
|
62
|
+
# Returns Grit::Head (baked)
|
63
|
+
def self.current(repo, options = {})
|
64
|
+
head = repo.git.fs_read('HEAD').chomp
|
65
|
+
if /ref: refs\/heads\/(.*)/.match(head)
|
66
|
+
self.new($1, repo.git.rev_parse(options, 'HEAD'))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end # Head
|
71
|
+
|
72
|
+
class Remote < Ref; end
|
73
|
+
|
74
|
+
end # Grit
|
@@ -0,0 +1,482 @@
|
|
1
|
+
module Grit
|
2
|
+
|
3
|
+
class Repo
|
4
|
+
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
|
5
|
+
|
6
|
+
# The path of the git repo as a String
|
7
|
+
attr_accessor :path
|
8
|
+
attr_accessor :working_dir
|
9
|
+
attr_reader :bare
|
10
|
+
|
11
|
+
# The git command line interface object
|
12
|
+
attr_accessor :git
|
13
|
+
|
14
|
+
# Create a new Repo instance
|
15
|
+
# +path+ is the path to either the root git directory or the bare git repo
|
16
|
+
# +options+ :is_bare force to load a bare repo
|
17
|
+
#
|
18
|
+
# Examples
|
19
|
+
# g = Repo.new("/Users/tom/dev/grit")
|
20
|
+
# g = Repo.new("/Users/tom/public/grit.git")
|
21
|
+
#
|
22
|
+
# Returns Grit::Repo
|
23
|
+
def initialize(path, options = {})
|
24
|
+
epath = File.expand_path(path)
|
25
|
+
|
26
|
+
if File.exist?(File.join(epath, '.git'))
|
27
|
+
self.working_dir = epath
|
28
|
+
self.path = File.join(epath, '.git')
|
29
|
+
@bare = false
|
30
|
+
elsif File.exist?(epath) && (epath =~ /\.git$/ || options[:is_bare])
|
31
|
+
self.path = epath
|
32
|
+
@bare = true
|
33
|
+
elsif File.exist?(epath)
|
34
|
+
raise InvalidGitRepositoryError.new(epath)
|
35
|
+
else
|
36
|
+
raise NoSuchPathError.new(epath)
|
37
|
+
end
|
38
|
+
|
39
|
+
self.git = Git.new(self.path)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Does nothing yet...
|
43
|
+
def self.init(path)
|
44
|
+
# !! TODO !!
|
45
|
+
# create directory
|
46
|
+
# generate initial git directory
|
47
|
+
# create new Grit::Repo on that dir, return it
|
48
|
+
end
|
49
|
+
|
50
|
+
# The project's description. Taken verbatim from GIT_REPO/description
|
51
|
+
#
|
52
|
+
# Returns String
|
53
|
+
def description
|
54
|
+
self.git.fs_read('description').chomp
|
55
|
+
end
|
56
|
+
|
57
|
+
def blame(file, commit = nil)
|
58
|
+
Blame.new(self, file, commit)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# An array of Head objects representing the branch heads in
|
63
|
+
# this repo
|
64
|
+
#
|
65
|
+
# Returns Grit::Head[] (baked)
|
66
|
+
def heads
|
67
|
+
Head.find_all(self)
|
68
|
+
end
|
69
|
+
|
70
|
+
alias_method :branches, :heads
|
71
|
+
|
72
|
+
def get_head(head_name)
|
73
|
+
heads.find { |h| h.name == head_name }
|
74
|
+
end
|
75
|
+
|
76
|
+
def is_head?(head_name)
|
77
|
+
get_head(head_name)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Object reprsenting the current repo head.
|
81
|
+
#
|
82
|
+
# Returns Grit::Head (baked)
|
83
|
+
def head
|
84
|
+
Head.current(self)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# Commits current index
|
89
|
+
#
|
90
|
+
# Returns true/false if commit worked
|
91
|
+
def commit_index(message)
|
92
|
+
self.git.commit({}, '-m', message)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Commits all tracked and modified files
|
96
|
+
#
|
97
|
+
# Returns true/false if commit worked
|
98
|
+
def commit_all(message)
|
99
|
+
self.git.commit({}, '-a', '-m', message)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Adds files to the index
|
103
|
+
def add(*files)
|
104
|
+
self.git.add({}, *files.flatten)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Remove files from the index
|
108
|
+
def remove(*files)
|
109
|
+
self.git.rm({}, *files.flatten)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def blame_tree(commit, path = nil)
|
114
|
+
commit_array = self.git.blame_tree(commit, path)
|
115
|
+
|
116
|
+
final_array = {}
|
117
|
+
commit_array.each do |file, sha|
|
118
|
+
final_array[file] = commit(sha)
|
119
|
+
end
|
120
|
+
final_array
|
121
|
+
end
|
122
|
+
|
123
|
+
def status
|
124
|
+
Status.new(self)
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
# An array of Tag objects that are available in this repo
|
129
|
+
#
|
130
|
+
# Returns Grit::Tag[] (baked)
|
131
|
+
def tags
|
132
|
+
Tag.find_all(self)
|
133
|
+
end
|
134
|
+
|
135
|
+
# An array of Remote objects representing the remote branches in
|
136
|
+
# this repo
|
137
|
+
#
|
138
|
+
# Returns Grit::Remote[] (baked)
|
139
|
+
def remotes
|
140
|
+
Remote.find_all(self)
|
141
|
+
end
|
142
|
+
|
143
|
+
def remote_list
|
144
|
+
self.git.list_remotes
|
145
|
+
end
|
146
|
+
|
147
|
+
def remote_add(name, url)
|
148
|
+
self.git.remote({}, 'add', name, url)
|
149
|
+
end
|
150
|
+
|
151
|
+
def remote_fetch(name)
|
152
|
+
self.git.fetch({}, name)
|
153
|
+
end
|
154
|
+
|
155
|
+
# takes an array of remote names and last pushed dates
|
156
|
+
# fetches from all of the remotes where the local fetch
|
157
|
+
# date is earlier than the passed date, then records the
|
158
|
+
# last fetched date
|
159
|
+
#
|
160
|
+
# { 'origin' => date,
|
161
|
+
# 'peter => date,
|
162
|
+
# }
|
163
|
+
def remotes_fetch_needed(remotes)
|
164
|
+
remotes.each do |remote, date|
|
165
|
+
# TODO: check against date
|
166
|
+
self.remote_fetch(remote)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
# An array of Ref objects representing the refs in
|
172
|
+
# this repo
|
173
|
+
#
|
174
|
+
# Returns Grit::Ref[] (baked)
|
175
|
+
def refs
|
176
|
+
[ Head.find_all(self), Tag.find_all(self), Remote.find_all(self) ].flatten
|
177
|
+
end
|
178
|
+
|
179
|
+
def commit_stats(start = 'master', max_count = 10, skip = 0)
|
180
|
+
options = {:max_count => max_count,
|
181
|
+
:skip => skip}
|
182
|
+
|
183
|
+
CommitStats.find_all(self, start, options)
|
184
|
+
end
|
185
|
+
|
186
|
+
# An array of Commit objects representing the history of a given ref/commit
|
187
|
+
# +start+ is the branch/commit name (default 'master')
|
188
|
+
# +max_count+ is the maximum number of commits to return (default 10, use +false+ for all)
|
189
|
+
# +skip+ is the number of commits to skip (default 0)
|
190
|
+
#
|
191
|
+
# Returns Grit::Commit[] (baked)
|
192
|
+
def commits(start = 'master', max_count = 10, skip = 0)
|
193
|
+
options = {:max_count => max_count,
|
194
|
+
:skip => skip}
|
195
|
+
|
196
|
+
Commit.find_all(self, start, options)
|
197
|
+
end
|
198
|
+
|
199
|
+
# The Commits objects that are reachable via +to+ but not via +from+
|
200
|
+
# Commits are returned in chronological order.
|
201
|
+
# +from+ is the branch/commit name of the younger item
|
202
|
+
# +to+ is the branch/commit name of the older item
|
203
|
+
#
|
204
|
+
# Returns Grit::Commit[] (baked)
|
205
|
+
def commits_between(from, to)
|
206
|
+
Commit.find_all(self, "#{from}..#{to}").reverse
|
207
|
+
end
|
208
|
+
|
209
|
+
# The Commits objects that are newer than the specified date.
|
210
|
+
# Commits are returned in chronological order.
|
211
|
+
# +start+ is the branch/commit name (default 'master')
|
212
|
+
# +since+ is a string represeting a date/time
|
213
|
+
# +extra_options+ is a hash of extra options
|
214
|
+
#
|
215
|
+
# Returns Grit::Commit[] (baked)
|
216
|
+
def commits_since(start = 'master', since = '1970-01-01', extra_options = {})
|
217
|
+
options = {:since => since}.merge(extra_options)
|
218
|
+
|
219
|
+
Commit.find_all(self, start, options)
|
220
|
+
end
|
221
|
+
|
222
|
+
# The number of commits reachable by the given branch/commit
|
223
|
+
# +start+ is the branch/commit name (default 'master')
|
224
|
+
#
|
225
|
+
# Returns Integer
|
226
|
+
def commit_count(start = 'master')
|
227
|
+
Commit.count(self, start)
|
228
|
+
end
|
229
|
+
|
230
|
+
# The Commit object for the specified id
|
231
|
+
# +id+ is the SHA1 identifier of the commit
|
232
|
+
#
|
233
|
+
# Returns Grit::Commit (baked)
|
234
|
+
def commit(id)
|
235
|
+
options = {:max_count => 1}
|
236
|
+
|
237
|
+
Commit.find_all(self, id, options).first
|
238
|
+
end
|
239
|
+
|
240
|
+
# Returns a list of commits that is in +other_repo+ but not in self
|
241
|
+
#
|
242
|
+
# Returns Grit::Commit[]
|
243
|
+
def commit_deltas_from(other_repo, ref = "master", other_ref = "master")
|
244
|
+
# TODO: we should be able to figure out the branch point, rather than
|
245
|
+
# rev-list'ing the whole thing
|
246
|
+
repo_refs = self.git.rev_list({}, ref).strip.split("\n")
|
247
|
+
other_repo_refs = other_repo.git.rev_list({}, other_ref).strip.split("\n")
|
248
|
+
|
249
|
+
(other_repo_refs - repo_refs).map do |ref|
|
250
|
+
Commit.find_all(other_repo, ref, {:max_count => 1}).first
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
# The Tree object for the given treeish reference
|
255
|
+
# +treeish+ is the reference (default 'master')
|
256
|
+
# +paths+ is an optional Array of directory paths to restrict the tree (deafult [])
|
257
|
+
#
|
258
|
+
# Examples
|
259
|
+
# repo.tree('master', ['lib/'])
|
260
|
+
#
|
261
|
+
# Returns Grit::Tree (baked)
|
262
|
+
def tree(treeish = 'master', paths = [])
|
263
|
+
Tree.construct(self, treeish, paths)
|
264
|
+
end
|
265
|
+
|
266
|
+
# The Blob object for the given id
|
267
|
+
# +id+ is the SHA1 id of the blob
|
268
|
+
#
|
269
|
+
# Returns Grit::Blob (unbaked)
|
270
|
+
def blob(id)
|
271
|
+
Blob.create(self, :id => id)
|
272
|
+
end
|
273
|
+
|
274
|
+
# The commit log for a treeish
|
275
|
+
#
|
276
|
+
# Returns Grit::Commit[]
|
277
|
+
def log(commit = 'master', path = nil, options = {})
|
278
|
+
default_options = {:pretty => "raw"}
|
279
|
+
actual_options = default_options.merge(options)
|
280
|
+
arg = path ? [commit, '--', path] : [commit]
|
281
|
+
commits = self.git.log(actual_options, *arg)
|
282
|
+
Commit.list_from_string(self, commits)
|
283
|
+
end
|
284
|
+
|
285
|
+
# The diff from commit +a+ to commit +b+, optionally restricted to the given file(s)
|
286
|
+
# +a+ is the base commit
|
287
|
+
# +b+ is the other commit
|
288
|
+
# +paths+ is an optional list of file paths on which to restrict the diff
|
289
|
+
def diff(a, b, *paths)
|
290
|
+
self.git.diff({}, a, b, '--', *paths)
|
291
|
+
end
|
292
|
+
|
293
|
+
# The commit diff for the given commit
|
294
|
+
# +commit+ is the commit name/id
|
295
|
+
#
|
296
|
+
# Returns Grit::Diff[]
|
297
|
+
def commit_diff(commit)
|
298
|
+
Commit.diff(self, commit)
|
299
|
+
end
|
300
|
+
|
301
|
+
# Initialize a bare git repository at the given path
|
302
|
+
# +path+ is the full path to the repo (traditionally ends with /<name>.git)
|
303
|
+
# +options+ is any additional options to the git init command
|
304
|
+
#
|
305
|
+
# Examples
|
306
|
+
# Grit::Repo.init_bare('/var/git/myrepo.git')
|
307
|
+
#
|
308
|
+
# Returns Grit::Repo (the newly created repo)
|
309
|
+
def self.init_bare(path, git_options = {}, repo_options = {})
|
310
|
+
git_options = {:bare => true}.merge(git_options)
|
311
|
+
git = Git.new(path)
|
312
|
+
git.fs_mkdir('..')
|
313
|
+
git.init(git_options)
|
314
|
+
self.new(path, repo_options)
|
315
|
+
end
|
316
|
+
|
317
|
+
# Fork a bare git repository from this repo
|
318
|
+
# +path+ is the full path of the new repo (traditionally ends with /<name>.git)
|
319
|
+
# +options+ is any additional options to the git clone command (:bare and :shared are true by default)
|
320
|
+
#
|
321
|
+
# Returns Grit::Repo (the newly forked repo)
|
322
|
+
def fork_bare(path, options = {})
|
323
|
+
default_options = {:bare => true, :shared => true}
|
324
|
+
real_options = default_options.merge(options)
|
325
|
+
Git.new(path).fs_mkdir('..')
|
326
|
+
self.git.clone(real_options, self.path, path)
|
327
|
+
Repo.new(path)
|
328
|
+
end
|
329
|
+
|
330
|
+
# Fork a bare git repository from another repo
|
331
|
+
# +path+ is the full path of the new repo (traditionally ends with /<name>.git)
|
332
|
+
# +options+ is any additional options to the git clone command (:bare and :shared are true by default)
|
333
|
+
#
|
334
|
+
# Returns Grit::Repo (the newly forked repo)
|
335
|
+
def fork_bare_from(path, options = {})
|
336
|
+
default_options = {:bare => true, :shared => true}
|
337
|
+
real_options = default_options.merge(options)
|
338
|
+
Git.new(self.path).fs_mkdir('..')
|
339
|
+
self.git.clone(real_options, path, self.path)
|
340
|
+
Repo.new(self.path)
|
341
|
+
end
|
342
|
+
|
343
|
+
# Archive the given treeish
|
344
|
+
# +treeish+ is the treeish name/id (default 'master')
|
345
|
+
# +prefix+ is the optional prefix
|
346
|
+
#
|
347
|
+
# Examples
|
348
|
+
# repo.archive_tar
|
349
|
+
# # => <String containing tar archive>
|
350
|
+
#
|
351
|
+
# repo.archive_tar('a87ff14')
|
352
|
+
# # => <String containing tar archive for commit a87ff14>
|
353
|
+
#
|
354
|
+
# repo.archive_tar('master', 'myproject/')
|
355
|
+
# # => <String containing tar archive and prefixed with 'myproject/'>
|
356
|
+
#
|
357
|
+
# Returns String (containing tar archive)
|
358
|
+
def archive_tar(treeish = 'master', prefix = nil)
|
359
|
+
options = {}
|
360
|
+
options[:prefix] = prefix if prefix
|
361
|
+
self.git.archive(options, treeish)
|
362
|
+
end
|
363
|
+
|
364
|
+
# Archive and gzip the given treeish
|
365
|
+
# +treeish+ is the treeish name/id (default 'master')
|
366
|
+
# +prefix+ is the optional prefix
|
367
|
+
#
|
368
|
+
# Examples
|
369
|
+
# repo.archive_tar_gz
|
370
|
+
# # => <String containing tar.gz archive>
|
371
|
+
#
|
372
|
+
# repo.archive_tar_gz('a87ff14')
|
373
|
+
# # => <String containing tar.gz archive for commit a87ff14>
|
374
|
+
#
|
375
|
+
# repo.archive_tar_gz('master', 'myproject/')
|
376
|
+
# # => <String containing tar.gz archive and prefixed with 'myproject/'>
|
377
|
+
#
|
378
|
+
# Returns String (containing tar.gz archive)
|
379
|
+
def archive_tar_gz(treeish = 'master', prefix = nil)
|
380
|
+
options = {}
|
381
|
+
options[:prefix] = prefix if prefix
|
382
|
+
self.git.archive(options, treeish, "| gzip -n")
|
383
|
+
end
|
384
|
+
|
385
|
+
# Write an archive directly to a file
|
386
|
+
# +treeish+ is the treeish name/id (default 'master')
|
387
|
+
# +prefix+ is the optional prefix (default nil)
|
388
|
+
# +filename+ is the name of the file (default 'archive.tar.gz')
|
389
|
+
# +format+ is the optional format (default nil)
|
390
|
+
# +pipe+ is the command to run the output through (default 'gzip')
|
391
|
+
#
|
392
|
+
# Returns nothing
|
393
|
+
def archive_to_file(treeish = 'master', prefix = nil, filename = 'archive.tar.gz', format = nil, pipe = "gzip")
|
394
|
+
options = {}
|
395
|
+
options[:prefix] = prefix if prefix
|
396
|
+
options[:format] = format if format
|
397
|
+
self.git.archive(options, treeish, "| #{pipe} > #{filename}")
|
398
|
+
end
|
399
|
+
|
400
|
+
# Enable git-daemon serving of this repository by writing the
|
401
|
+
# git-daemon-export-ok file to its git directory
|
402
|
+
#
|
403
|
+
# Returns nothing
|
404
|
+
def enable_daemon_serve
|
405
|
+
self.git.fs_write(DAEMON_EXPORT_FILE, '')
|
406
|
+
end
|
407
|
+
|
408
|
+
# Disable git-daemon serving of this repository by ensuring there is no
|
409
|
+
# git-daemon-export-ok file in its git directory
|
410
|
+
#
|
411
|
+
# Returns nothing
|
412
|
+
def disable_daemon_serve
|
413
|
+
self.git.fs_delete(DAEMON_EXPORT_FILE)
|
414
|
+
end
|
415
|
+
|
416
|
+
def gc_auto
|
417
|
+
self.git.gc({:auto => true})
|
418
|
+
end
|
419
|
+
|
420
|
+
# The list of alternates for this repo
|
421
|
+
#
|
422
|
+
# Returns Array[String] (pathnames of alternates)
|
423
|
+
def alternates
|
424
|
+
alternates_path = "objects/info/alternates"
|
425
|
+
if self.git.fs_exist?(alternates_path)
|
426
|
+
self.git.fs_read(alternates_path).strip.split("\n")
|
427
|
+
else
|
428
|
+
[]
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
# Sets the alternates
|
433
|
+
# +alts+ is the Array of String paths representing the alternates
|
434
|
+
#
|
435
|
+
# Returns nothing
|
436
|
+
def alternates=(alts)
|
437
|
+
alts.each do |alt|
|
438
|
+
unless File.exist?(alt)
|
439
|
+
raise "Could not set alternates. Alternate path #{alt} must exist"
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
if alts.empty?
|
444
|
+
self.git.fs_write('objects/info/alternates', '')
|
445
|
+
else
|
446
|
+
self.git.fs_write('objects/info/alternates', alts.join("\n"))
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
def config
|
451
|
+
@config ||= Config.new(self)
|
452
|
+
end
|
453
|
+
|
454
|
+
def index
|
455
|
+
Index.new(self)
|
456
|
+
end
|
457
|
+
|
458
|
+
def update_ref(head, commit_sha)
|
459
|
+
return nil if !commit_sha || (commit_sha.size != 40)
|
460
|
+
self.git.fs_write("refs/heads/#{head}", commit_sha)
|
461
|
+
commit_sha
|
462
|
+
end
|
463
|
+
|
464
|
+
# Rename the current repository directory.
|
465
|
+
# +name+ is the new name
|
466
|
+
#
|
467
|
+
# Returns nothing
|
468
|
+
def rename(name)
|
469
|
+
if @bare
|
470
|
+
self.git.fs_move('/', "../#{name}")
|
471
|
+
else
|
472
|
+
self.git.fs_move('/', "../../#{name}")
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
# Pretty object inspection
|
477
|
+
def inspect
|
478
|
+
%Q{#<Grit::Repo "#{@path}">}
|
479
|
+
end
|
480
|
+
end # Repo
|
481
|
+
|
482
|
+
end # Grit
|