| Class | Grit::Repo |
| In: |
lib/grit/repo.rb
|
| Parent: | Object |
| DAEMON_EXPORT_FILE | = | 'git-daemon-export-ok' |
| bare | [R] | |
| git | [RW] | The git command line interface object |
| path | [RW] | The path of the git repo as a String |
| working_dir | [RW] |
Does nothing yet…
# File lib/grit/repo.rb, line 43
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
Initialize a bare git repository at the given path
+path+ is the full path to the repo (traditionally ends with /<name>.git) +options+ is any additional options to the git init command
Examples
Grit::Repo.init_bare('/var/git/myrepo.git')
Returns Grit::Repo (the newly created repo)
# File lib/grit/repo.rb, line 281
281: def self.init_bare(path, git_options = {}, repo_options = {})
282: git = Git.new(path)
283: git.init(git_options)
284: self.new(path, repo_options)
285: end
+path+ is the path to either the root git directory or the bare git repo +options+ :is_bare force to load a bare repo
Examples
g = Repo.new("/Users/tom/dev/grit")
g = Repo.new("/Users/tom/public/grit.git")
Returns Grit::Repo
# File lib/grit/repo.rb, line 23
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
The list of alternates for this repo
Returns Array[String] (pathnames of alternates)
# File lib/grit/repo.rb, line 379
379: def alternates
380: alternates_path = File.join(self.path, *%w{objects info alternates})
381:
382: if File.exist?(alternates_path)
383: File.read(alternates_path).strip.split("\n")
384: else
385: []
386: end
387: end
Sets the alternates
+alts+ is the Array of String paths representing the alternates
Returns nothing
# File lib/grit/repo.rb, line 393
393: def alternates=(alts)
394: alts.each do |alt|
395: unless File.exist?(alt)
396: raise "Could not set alternates. Alternate path #{alt} must exist"
397: end
398: end
399:
400: if alts.empty?
401: File.open(File.join(self.path, *%w{objects info alternates}), 'w') do |f|
402: f.write ''
403: end
404: else
405: File.open(File.join(self.path, *%w{objects info alternates}), 'w') do |f|
406: f.write alts.join("\n")
407: end
408: end
409: end
Archive the given treeish
+treeish+ is the treeish name/id (default 'master') +prefix+ is the optional prefix
Examples
repo.archive_tar
# => <String containing tar archive>
repo.archive_tar('a87ff14')
# => <String containing tar archive for commit a87ff14>
repo.archive_tar('master', 'myproject/')
# => <String containing tar archive and prefixed with 'myproject/'>
Returns String (containing tar archive)
# File lib/grit/repo.rb, line 314
314: def archive_tar(treeish = 'master', prefix = nil)
315: options = {}
316: options[:prefix] = prefix if prefix
317: self.git.archive(options, treeish)
318: end
Archive and gzip the given treeish
+treeish+ is the treeish name/id (default 'master') +prefix+ is the optional prefix
Examples
repo.archive_tar_gz
# => <String containing tar.gz archive>
repo.archive_tar_gz('a87ff14')
# => <String containing tar.gz archive for commit a87ff14>
repo.archive_tar_gz('master', 'myproject/')
# => <String containing tar.gz archive and prefixed with 'myproject/'>
Returns String (containing tar.gz archive)
# File lib/grit/repo.rb, line 335
335: def archive_tar_gz(treeish = 'master', prefix = nil)
336: options = {}
337: options[:prefix] = prefix if prefix
338: self.git.archive(options, treeish, "| gzip")
339: end
Write an archive directly to a file
+treeish+ is the treeish name/id (default 'master') +prefix+ is the optional prefix (default nil) +filename+ is the name of the file (default 'archive.tar.gz') +format+ is the optional format (default nil) +pipe+ is the command to run the output through (default 'gzip')
Returns nothing
# File lib/grit/repo.rb, line 349
349: def archive_to_file(treeish = 'master', prefix = nil, filename = 'archive.tar.gz', format = nil, pipe = "gzip")
350: options = {}
351: options[:prefix] = prefix if prefix
352: options[:format] = format if format
353: self.git.archive(options, treeish, "| #{pipe} > #{filename}")
354: end
# File lib/grit/repo.rb, line 57
57: def blame(file, commit = nil)
58: Blame.new(self, file, commit)
59: end
# File lib/grit/repo.rb, line 113
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
The Blob object for the given id
+id+ is the SHA1 id of the blob
Returns Grit::Blob (unbaked)
# File lib/grit/repo.rb, line 242
242: def blob(id)
243: Blob.create(self, :id => id)
244: end
The Commit object for the specified id
+id+ is the SHA1 identifier of the commit
Returns Grit::Commit (baked)
# File lib/grit/repo.rb, line 206
206: def commit(id)
207: options = {:max_count => 1}
208:
209: Commit.find_all(self, id, options).first
210: end
Returns a list of commits that is in other_repo but not in self
Returns Grit::Commit[]
# File lib/grit/repo.rb, line 215
215: def commit_deltas_from(other_repo, ref = "master", other_ref = "master")
216: # TODO: we should be able to figure out the branch point, rather than
217: # rev-list'ing the whole thing
218: repo_refs = self.git.rev_list({}, ref).strip.split("\n")
219: other_repo_refs = other_repo.git.rev_list({}, other_ref).strip.split("\n")
220:
221: (other_repo_refs - repo_refs).map do |ref|
222: Commit.find_all(other_repo, ref, {:max_count => 1}).first
223: end
224: end
The commit diff for the given commit
+commit+ is the commit name/id
Returns Grit::Diff[]
# File lib/grit/repo.rb, line 269
269: def commit_diff(commit)
270: Commit.diff(self, commit)
271: end
# File lib/grit/repo.rb, line 151
151: def commit_stats(start = 'master', max_count = 10, skip = 0)
152: options = {:max_count => max_count,
153: :skip => skip}
154:
155: CommitStats.find_all(self, start, options)
156: end
An array of Commit objects representing the history of a given ref/commit
+start+ is the branch/commit name (default 'master') +max_count+ is the maximum number of commits to return (default 10, use +false+ for all) +skip+ is the number of commits to skip (default 0)
Returns Grit::Commit[] (baked)
# File lib/grit/repo.rb, line 164
164: def commits(start = 'master', max_count = 10, skip = 0)
165: options = {:max_count => max_count,
166: :skip => skip}
167:
168: Commit.find_all(self, start, options)
169: end
The Commits objects that are reachable via to but not via from Commits are returned in chronological order.
+from+ is the branch/commit name of the younger item +to+ is the branch/commit name of the older item
Returns Grit::Commit[] (baked)
# File lib/grit/repo.rb, line 177
177: def commits_between(from, to)
178: Commit.find_all(self, "#{from}..#{to}").reverse
179: end
The Commits objects that are newer than the specified date. Commits are returned in chronological order.
+start+ is the branch/commit name (default 'master') +since+ is a string represeting a date/time +extra_options+ is a hash of extra options
Returns Grit::Commit[] (baked)
# File lib/grit/repo.rb, line 188
188: def commits_since(start = 'master', since = '1970-01-01', extra_options = {})
189: options = {:since => since}.merge(extra_options)
190:
191: Commit.find_all(self, start, options)
192: end
The project‘s description. Taken verbatim from GIT_REPO/description
Returns String
# File lib/grit/repo.rb, line 53
53: def description
54: File.open(File.join(self.path, 'description')).read.chomp
55: end
The diff from commit a to commit b, optionally restricted to the given file(s)
+a+ is the base commit +b+ is the other commit +paths+ is an optional list of file paths on which to restrict the diff
# File lib/grit/repo.rb, line 261
261: def diff(a, b, *paths)
262: self.git.diff({}, a, b, '--', *paths)
263: end
Disable git-daemon serving of this repository by ensuring there is no git-daemon-export-ok file in its git directory
Returns nothing
# File lib/grit/repo.rb, line 368
368: def disable_daemon_serve
369: FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE))
370: end
Enable git-daemon serving of this repository by writing the git-daemon-export-ok file to its git directory
Returns nothing
# File lib/grit/repo.rb, line 360
360: def enable_daemon_serve
361: FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE))
362: end
Fork a bare git repository from this repo
+path+ is the full path of the new repo (traditionally ends with /<name>.git) +options+ is any additional options to the git clone command (:bare and :shared are true by default)
Returns Grit::Repo (the newly forked repo)
# File lib/grit/repo.rb, line 292
292: def fork_bare(path, options = {})
293: default_options = {:bare => true, :shared => true}
294: real_options = default_options.merge(options)
295: self.git.clone(real_options, self.path, path)
296: Repo.new(path)
297: end
# File lib/grit/repo.rb, line 72
72: def get_head(head_name)
73: heads.find { |h| h.name == head_name }
74: end
Object reprsenting the current repo head.
Returns Grit::Head (baked)
# File lib/grit/repo.rb, line 83
83: def head
84: Head.current(self)
85: end
An array of Head objects representing the branch heads in this repo
Returns Grit::Head[] (baked)
# File lib/grit/repo.rb, line 66
66: def heads
67: Head.find_all(self)
68: end
Pretty object inspection
# File lib/grit/repo.rb, line 432
432: def inspect
433: %Q{#<Grit::Repo "#{@path}">}
434: end
Returns Grit::Commit[]
# File lib/grit/repo.rb, line 249
249: def log(commit = 'master', path = nil, options = {})
250: default_options = {:pretty => "raw"}
251: actual_options = default_options.merge(options)
252: arg = path ? [commit, '--', path] : [commit]
253: commits = self.git.log(actual_options, *arg)
254: Commit.list_from_string(self, commits)
255: end
An array of Remote objects representing the remote branches in this repo
Returns Grit::Remote[] (baked)
# File lib/grit/repo.rb, line 139
139: def remotes
140: Remote.find_all(self)
141: end
The Tree object for the given treeish reference
+treeish+ is the reference (default 'master') +paths+ is an optional Array of directory paths to restrict the tree (deafult [])
Examples
repo.tree('master', ['lib/'])
Returns Grit::Tree (baked)
# File lib/grit/repo.rb, line 234
234: def tree(treeish = 'master', paths = [])
235: Tree.construct(self, treeish, paths)
236: end
# File lib/grit/repo.rb, line 419
419: def update_ref(head, commit_sha)
420: return nil if !commit_sha || (commit_sha.size != 40)
421:
422: ref_heads = File.join(self.path, 'refs', 'heads')
423: FileUtils.mkdir_p(ref_heads)
424: File.open(File.join(ref_heads, head), 'w') do |f|
425: f.write(commit_sha)
426: end
427: commit_sha
428:
429: end