trans-grit 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/API.txt +101 -0
- data/History.txt +163 -0
- data/LICENSE +22 -0
- data/PURE_TODO +35 -0
- data/README.md +242 -0
- data/Rakefile +149 -0
- data/benchmarks.rb +129 -0
- data/benchmarks.txt +21 -0
- data/examples/ex_add_commit.rb +13 -0
- data/examples/ex_index.rb +21 -0
- data/grit.gemspec +74 -0
- data/lib/grit.rb +75 -0
- data/lib/grit/actor.rb +52 -0
- data/lib/grit/blame.rb +70 -0
- data/lib/grit/blob.rb +126 -0
- data/lib/grit/commit.rb +313 -0
- data/lib/grit/commit_stats.rb +128 -0
- data/lib/grit/config.rb +44 -0
- data/lib/grit/diff.rb +79 -0
- data/lib/grit/errors.rb +10 -0
- data/lib/grit/git-ruby.rb +262 -0
- data/lib/grit/git-ruby/commit_db.rb +52 -0
- data/lib/grit/git-ruby/git_object.rb +353 -0
- data/lib/grit/git-ruby/internal/file_window.rb +58 -0
- data/lib/grit/git-ruby/internal/loose.rb +137 -0
- data/lib/grit/git-ruby/internal/pack.rb +397 -0
- data/lib/grit/git-ruby/internal/raw_object.rb +44 -0
- data/lib/grit/git-ruby/repository.rb +775 -0
- data/lib/grit/git.rb +501 -0
- data/lib/grit/index.rb +222 -0
- data/lib/grit/lazy.rb +35 -0
- data/lib/grit/merge.rb +45 -0
- data/lib/grit/ref.rb +78 -0
- data/lib/grit/repo.rb +709 -0
- data/lib/grit/ruby1.9.rb +7 -0
- data/lib/grit/status.rb +153 -0
- data/lib/grit/submodule.rb +88 -0
- data/lib/grit/tag.rb +102 -0
- data/lib/grit/tree.rb +125 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af07b8f341d40f926676aad32abb11646f135740
|
4
|
+
data.tar.gz: 3ea05b13825fb1b6f82b410520a3364ad748956b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bcc64ac8c7df408f29647bb5856274123d1a986d44ec95d95f9f4aec557e43a57140866b603c611ac31e6c694b3a3542c6083c860ef2a3674a957a0c19741a56
|
7
|
+
data.tar.gz: 61e01e8d785228a935d3edf3e7d29d22dcadbbeedf6081ab29ee2984dd798dac94dbee9cd13480cdfeb04489f1e2f645f176f1d8697a87190bfedbf2854153af
|
data/API.txt
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
== TODO ==
|
2
|
+
|
3
|
+
* Add remote branch references (Grit::Remote)
|
4
|
+
* Add status - what is modified, staged
|
5
|
+
|
6
|
+
g.checkout('new_branch')
|
7
|
+
g.checkout(g.branch('new_branch'))
|
8
|
+
|
9
|
+
g.branch(name).merge(branch2)
|
10
|
+
g.branch(branch2).merge # merges HEAD with branch2
|
11
|
+
|
12
|
+
g.branch(name).in_branch(message) { # add files } # auto-commits
|
13
|
+
g.merge('new_branch')
|
14
|
+
g.merge('origin/remote_branch')
|
15
|
+
g.merge(b.branch('master'))
|
16
|
+
g.merge([branch1, branch2])
|
17
|
+
|
18
|
+
r = g.add_remote(name, uri) # Git::Remote
|
19
|
+
r = g.add_remote(name, Git::Base) # Git::Remote
|
20
|
+
|
21
|
+
g.remotes # array of Git::Remotes
|
22
|
+
g.remote(name).fetch
|
23
|
+
g.remote(name).remove
|
24
|
+
g.remote(name).merge
|
25
|
+
g.remote(name).merge(branch)
|
26
|
+
|
27
|
+
g.fetch
|
28
|
+
g.fetch(g.remotes.first)
|
29
|
+
|
30
|
+
g.pull
|
31
|
+
g.pull(Git::Repo, Git::Branch) # fetch and a merge
|
32
|
+
|
33
|
+
g.add_tag('tag_name') # returns Git::Tag
|
34
|
+
|
35
|
+
g.repack
|
36
|
+
|
37
|
+
g.push
|
38
|
+
g.push(g.remote('name'))
|
39
|
+
|
40
|
+
g.reset # defaults to HEAD
|
41
|
+
g.reset_hard(Git::Commit)
|
42
|
+
|
43
|
+
g.branch('new_branch') # creates new or fetches existing
|
44
|
+
g.branch('new_branch').checkout
|
45
|
+
g.branch('new_branch').delete
|
46
|
+
g.branch('existing_branch').checkout
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
require 'mojombo-grit'
|
53
|
+
|
54
|
+
include Grit
|
55
|
+
Grit.debug
|
56
|
+
Grit.use_pure_ruby
|
57
|
+
|
58
|
+
repo = Repo.new("/Users/tom/dev/grit")
|
59
|
+
|
60
|
+
= Commit Log
|
61
|
+
|
62
|
+
repo.commits('mybranch')
|
63
|
+
repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe')
|
64
|
+
repo.commits('v0.1')
|
65
|
+
|
66
|
+
repo.log('mybranch', 100, 20)
|
67
|
+
|
68
|
+
head = repo.commits.first
|
69
|
+
head.id
|
70
|
+
# => "e80bbd2ce67651aa18e57fb0b43618ad4baf7750"
|
71
|
+
head.parents
|
72
|
+
# => [#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">]
|
73
|
+
head.tree
|
74
|
+
# => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
|
75
|
+
head.author
|
76
|
+
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
|
77
|
+
head.authored_date
|
78
|
+
# => Wed Oct 24 22:02:31 -0700 2007
|
79
|
+
head.committer
|
80
|
+
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
|
81
|
+
head.committed_date
|
82
|
+
# => Wed Oct 24 22:02:31 -0700 2007
|
83
|
+
head.message
|
84
|
+
# => "add Actor inspect"
|
85
|
+
contents = tree.contents
|
86
|
+
# => [#<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">,
|
87
|
+
#<Grit::Blob "81d2c27608b352814cbe979a6acd678d30219678">,
|
88
|
+
#<Grit::Tree "c3d07b0083f01a6e1ac969a0f32b8d06f20c62e5">,
|
89
|
+
#<Grit::Tree "4d00fe177a8407dbbc64a24dbfc564762c0922d8">]
|
90
|
+
blob.id
|
91
|
+
# => "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666"
|
92
|
+
blob.name
|
93
|
+
# => "README.txt"
|
94
|
+
blob.mode
|
95
|
+
# => "100644"
|
96
|
+
blob.size
|
97
|
+
# => 7726
|
98
|
+
blob.data
|
99
|
+
|
100
|
+
repo.blob("4ebc8aea50e0a67e000ba29a30809d0a7b9b2666")
|
101
|
+
# => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
|
data/History.txt
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
== 2.5.0 / 2012-04-22
|
2
|
+
* Minor Enhancements
|
3
|
+
* 100% Git-compliant actor creation.
|
4
|
+
* Handle newlines in author/committer.
|
5
|
+
* Grit::Git check_applies/patch related methods take command hash.
|
6
|
+
* Tags api now resty.
|
7
|
+
* Remove all the grit jruby hacks in favor of updated posix-spawn.
|
8
|
+
* Add Grit::Commit#patch_id.
|
9
|
+
* Support large packfiles with index v2.
|
10
|
+
* Bug Fixes
|
11
|
+
* Fix Loose Objects with non-ASCII content in Ruby 1.9
|
12
|
+
* Fix bugs in Grit::Repo #objects, #commit_objects, and #diff_objects
|
13
|
+
due to passing multiple arguments in a single argv element.
|
14
|
+
* ruby rev_list passes --verify to native rev_parse in fallback.
|
15
|
+
* Git ls-tree raises on non-zero exit.
|
16
|
+
|
17
|
+
== 2.4.1 / 2011-01-13
|
18
|
+
* Minor Enhancements
|
19
|
+
* Grit::Process is used to implement Grit::Git#check_applies,
|
20
|
+
Grit::Git#get_patch, and Grit::Git#apply_patch.
|
21
|
+
|
22
|
+
== 2.4.0 / 2011-01-06
|
23
|
+
* Major Enhancements
|
24
|
+
* Add support for parsing git notes.
|
25
|
+
* Add `git cat-file --batch` support with Grit::Repo#batch.
|
26
|
+
* Grit::Process is a custom written external command invocation heavily
|
27
|
+
optimized for running git commands quickly and efficiently.
|
28
|
+
* Grit::Git#native takes an :input option for piping data into git
|
29
|
+
commands
|
30
|
+
* Grit::Git#native takes an :env option for setting the git child
|
31
|
+
process's
|
32
|
+
environment without futsing with the parent's environment.
|
33
|
+
* Grit::Git#native takes an :chdir option for setting the current working
|
34
|
+
directory (PWD) of the git child process.
|
35
|
+
* Grit::Git#native takes an :raise => true option that causes an exception
|
36
|
+
to be raised when the git child process exits non-zero.
|
37
|
+
* Minor Enhancements
|
38
|
+
* Grit::Index#commit supports custom committer/author names and dates.
|
39
|
+
* Performance enhancements with internal command output buffering.
|
40
|
+
* Reduce fork/execs needed to execute a smoke command from between 3-4
|
41
|
+
to 1.
|
42
|
+
* Git child processes are now properly parented under the grit Ruby
|
43
|
+
process instead of being dropped under init.
|
44
|
+
* Bug Fixes
|
45
|
+
* Zero-Padding issue in Grit::Index was fixed.
|
46
|
+
* Fix issue where Repo#diff skips the first diff (#42)
|
47
|
+
* Fix Repo.init_bare for repo names not ending in .git (#40)
|
48
|
+
* Fix a variety of process hangs when git stderr output or data written
|
49
|
+
to stdin exceeded PIPE_BUF bytes.
|
50
|
+
|
51
|
+
== 2.3.2 / 2011-01-06
|
52
|
+
* Erroneously released. SemVer violation and misc release screwups.
|
53
|
+
|
54
|
+
== 2.3.1
|
55
|
+
* Skipped for unknown reasons.
|
56
|
+
|
57
|
+
== 2.3.0 / 2010-09-29
|
58
|
+
* Minor Enhancements
|
59
|
+
* Add Grit::Repo.init.
|
60
|
+
* Bug Fixes
|
61
|
+
* Fix Ruby 1.9 compatibility (#24).
|
62
|
+
|
63
|
+
== 2.2.1 / 2010-08-23
|
64
|
+
* Bug Fixes
|
65
|
+
* Fix minor regression due to the changed default values in
|
66
|
+
Grit::Index#commit.
|
67
|
+
|
68
|
+
== 2.2.0 / 2010-08-19
|
69
|
+
* Minor Enhancements
|
70
|
+
* Add Grit::Index#delete to allow deletions of files from the index.
|
71
|
+
|
72
|
+
== 2.1.0 / 2010-08-04
|
73
|
+
* Major Enhancements
|
74
|
+
* Add support for parsing annotated tag objects.
|
75
|
+
* Add Grit::Repo#recent_tag_name for getting the latest tag name that is
|
76
|
+
reachable in a commit.
|
77
|
+
* Grit::Diff tracks renames properly if given the :M option.
|
78
|
+
* Grit::Commit#diffs and Grit::Commit.diffs both take a git options hash
|
79
|
+
that is passed to `git diff`.
|
80
|
+
* Minor Enhancements
|
81
|
+
* Allow diff to only take one sha
|
82
|
+
* Add merge commit diff support
|
83
|
+
* Pass along the options to Real Git on a rev-parse miss
|
84
|
+
* Raise NoSuchPath with no tree in ls_tree_path
|
85
|
+
* Make pure-ruby `ls-tree -r` work with commits
|
86
|
+
* Implement select_existing_objects
|
87
|
+
* Switch to RakeGem for build management
|
88
|
+
* Bug Fixes
|
89
|
+
* Add no_quote option for fixing tag listings.
|
90
|
+
* Raise custom exceptions on invalid tree objects.
|
91
|
+
* Fix Repo#diff (was throwing an error).
|
92
|
+
|
93
|
+
== 2.0.0 / 2009-10-27
|
94
|
+
* Major Enhancements
|
95
|
+
* All filesystem calls have been moved into Grit::Git to allow proxying
|
96
|
+
* Non-code changes
|
97
|
+
* Removed all trailing whitespace in code files
|
98
|
+
* Bug Fixes
|
99
|
+
* Repo.archive_tar_gz now passes -n option to gzip to be idempotent
|
100
|
+
* Fix RubyGit's diff to detect additions and deletions
|
101
|
+
[github.com/defunkt]
|
102
|
+
|
103
|
+
== 1.1.1 / 2009-03-31
|
104
|
+
* Changes
|
105
|
+
* Don't include test directory in gem package (it's too big)
|
106
|
+
|
107
|
+
== 1.1.0 / 2009-03-29
|
108
|
+
* Backwards breaking changes
|
109
|
+
* Diff#a_commit -> Diff#a_blob, Diff#b_commit -> Diff#b_blob
|
110
|
+
* Major Enhancments
|
111
|
+
* Ruby 1.9 compatibility [github.com/chapados, github.com/js]
|
112
|
+
* Minor Enhancements
|
113
|
+
* Convert readme to markdown
|
114
|
+
* Added a shortcut for commit_stats as Commit#stats [github.com/js]
|
115
|
+
* Add a #basename method to Submodule, Blob and Tree for retrieving the
|
116
|
+
name [github.com/js]
|
117
|
+
* Make Grit::Submodule grasp the concept of non-unix lineendings
|
118
|
+
[github.com/js]
|
119
|
+
* Added Repo#commit_deltas_from [github.com/js]
|
120
|
+
* do some mild shell escaping when running commands [github.com/js]
|
121
|
+
* Added two shortcut methods to Tree, for picking trees/blobs only
|
122
|
+
[github.com/Voker57]
|
123
|
+
* Added <=> method to Blob, needed for sorting tree [github.com/Voker57]
|
124
|
+
* Make the number of bytes to be read from git's stdout configurable
|
125
|
+
[github.com/josb]
|
126
|
+
* Repo.archive_to_file accepts extra parameters making plain zipping
|
127
|
+
possible [github.com/darwin]
|
128
|
+
* Handle commit stats that summarize commits with binary changes
|
129
|
+
[github.com/therealadam]
|
130
|
+
* Add a DiffStat class for easy access to diff stats
|
131
|
+
[github.com/therealadam]
|
132
|
+
* Don't split git logs that contain blank lines into two CommitStats
|
133
|
+
[github.com/therealadam]
|
134
|
+
* Add DiffStat#net for total change count [github.com/therealadam]
|
135
|
+
|
136
|
+
== 1.0.3 / 2009-02-13
|
137
|
+
* Minor Enhancements
|
138
|
+
* Added Grit::Commit#to_patch for plaintext formatted patches.
|
139
|
+
* Fixed Grit::Tag to work with annotated tags.
|
140
|
+
|
141
|
+
== 1.0.2 / 2009-02-10
|
142
|
+
* Minor Enhancements
|
143
|
+
* Implement Grit.version to use VERSION.yml file
|
144
|
+
|
145
|
+
== 1.0.1 / 2009-02-10
|
146
|
+
* Bug Fixes
|
147
|
+
* Add diff-lcs as a dependency
|
148
|
+
|
149
|
+
== 1.0.0 / 2009-01-27
|
150
|
+
* Tons of awesome in here. Also, we suck at updating the history.
|
151
|
+
* Let's do better at that from now on.
|
152
|
+
|
153
|
+
== 0.8.3 / 2008-07-07
|
154
|
+
* Capture stderr and log if debug is true (rsanheim)
|
155
|
+
|
156
|
+
== 0.8.2 / 2008-06-27
|
157
|
+
* Allow user provided logger (rsanheim)
|
158
|
+
|
159
|
+
== 0.8.0 / 2008-04-24
|
160
|
+
* Lots of fixes and additions
|
161
|
+
|
162
|
+
== 0.7.0 / 2008-01-07
|
163
|
+
* First public release!
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2007-2009 Tom Preston-Werner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/PURE_TODO
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
This is a listing of all the places I can find that Grit actually does a
|
2
|
+
'git' system call. My goal is to add native Ruby versions of all of them.
|
3
|
+
|
4
|
+
Completed
|
5
|
+
===========================
|
6
|
+
** lib/grit/blob.rb:36: @size ||= @repo.git.cat_file({:s => true}, id).chomp.to_i
|
7
|
+
** lib/grit/blob.rb:43: @data ||= @repo.git.cat_file({:p => true}, id)
|
8
|
+
** lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
lib/grit/commit.rb:74: repo.git.rev_list({}, ref).strip.split("\n").size
|
13
|
+
lib/grit/commit.rb:92: output = repo.git.rev_list(actual_options, ref)
|
14
|
+
lib/grit/commit.rb:94: output = repo.git.rev_list(actual_options.merge(:all => true))
|
15
|
+
|
16
|
+
|
17
|
+
Next to do
|
18
|
+
===========================
|
19
|
+
lib/grit/tag.rb:28: output = repo.git.for_each_ref(actual_options, "refs/tags")
|
20
|
+
lib/grit/head.rb:37: output = repo.git.for_each_ref(actual_options, HEAD_PREFIX)
|
21
|
+
lib/grit/head.rb:50: self.new($1, repo.git.rev_parse(options, 'HEAD'))
|
22
|
+
lib/grit/config.rb:9: @repo.git.config({}, key, value)
|
23
|
+
lib/grit/config.rb:40: @repo.git.config(:list => true).split(/\n/)
|
24
|
+
|
25
|
+
|
26
|
+
May not be fast enough
|
27
|
+
=============================
|
28
|
+
lib/grit/blob.rb:58: data = repo.git.blame({:p => true}, commit, '--', file)
|
29
|
+
|
30
|
+
|
31
|
+
More Difficult
|
32
|
+
===========================
|
33
|
+
lib/grit/commit.rb:39: @id_abbrev ||= @repo.git.rev_parse({:short => true}, self.id).chomp
|
34
|
+
lib/grit/commit.rb:150: text = repo.git.diff({:full_index => true}, *paths)
|
35
|
+
lib/grit/commit.rb:156: diff = @repo.git.show({:full_index => true, :pretty => 'raw'}, @id)
|
data/README.md
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
Grit
|
2
|
+
====
|
3
|
+
|
4
|
+
Grit gives you object oriented read/write access to Git repositories via Ruby.
|
5
|
+
The main goals are stability and performance. To this end, some of the
|
6
|
+
interactions with Git repositories are done by shelling out to the system's
|
7
|
+
`git` command, and other interactions are done with pure Ruby
|
8
|
+
reimplementations of core Git functionality. This choice, however, is
|
9
|
+
transparent to end users, and you need not know which method is being used.
|
10
|
+
|
11
|
+
This software was developed to power GitHub, and should be considered
|
12
|
+
production ready. An extensive test suite is provided to verify its
|
13
|
+
correctness.
|
14
|
+
|
15
|
+
Grit is maintained by Tom Preston-Werner, Scott Chacon, Chris Wanstrath, and
|
16
|
+
PJ Hyett.
|
17
|
+
|
18
|
+
This documentation is accurate as of Grit 2.3.
|
19
|
+
|
20
|
+
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
* git (http://git-scm.com) tested with 1.7.2.1
|
24
|
+
|
25
|
+
|
26
|
+
## Install
|
27
|
+
|
28
|
+
Easiest install is via RubyGems:
|
29
|
+
|
30
|
+
$ gem install grit
|
31
|
+
|
32
|
+
|
33
|
+
## Source
|
34
|
+
|
35
|
+
Grit's Git repo is available on GitHub, which can be browsed at:
|
36
|
+
|
37
|
+
http://github.com/mojombo/grit
|
38
|
+
|
39
|
+
and cloned with:
|
40
|
+
|
41
|
+
git clone git://github.com/mojombo/grit.git
|
42
|
+
|
43
|
+
|
44
|
+
### Development
|
45
|
+
|
46
|
+
You will need these gems to get tests to pass:
|
47
|
+
|
48
|
+
* mocha
|
49
|
+
|
50
|
+
|
51
|
+
### Contributing
|
52
|
+
|
53
|
+
If you'd like to hack on Grit, follow these instructions. To get all of the dependencies, install the gem first.
|
54
|
+
|
55
|
+
1. Fork the project to your own account
|
56
|
+
1. Clone down your fork
|
57
|
+
1. Create a thoughtfully named topic branch to contain your change
|
58
|
+
1. Hack away
|
59
|
+
1. Add tests and make sure everything still passes by running `rake`
|
60
|
+
1. If you are adding new functionality, document it in README.md
|
61
|
+
1. Do not change the version number, I will do that on my end
|
62
|
+
1. If necessary, rebase your commits into logical chunks, without errors
|
63
|
+
1. Push the branch up to GitHub
|
64
|
+
1. Send a pull request for your branch
|
65
|
+
|
66
|
+
|
67
|
+
## Usage
|
68
|
+
|
69
|
+
Grit gives you object model access to your Git repositories. Once you have
|
70
|
+
created a `Repo` object, you can traverse it to find parent commits,
|
71
|
+
trees, blobs, etc.
|
72
|
+
|
73
|
+
|
74
|
+
### Initialize a Repo object
|
75
|
+
|
76
|
+
The first step is to create a `Grit::Repo` object to represent your repo. In
|
77
|
+
this documentation I include the `Grit` module to reduce typing.
|
78
|
+
|
79
|
+
require 'grit'
|
80
|
+
repo = Grit::Repo.new("/Users/tom/dev/grit")
|
81
|
+
|
82
|
+
In the above example, the directory `/Users/tom/dev/grit` is my working
|
83
|
+
directory and contains the `.git` directory. You can also initialize Grit with
|
84
|
+
a bare repo.
|
85
|
+
|
86
|
+
repo = Repo.new("/var/git/grit.git")
|
87
|
+
|
88
|
+
|
89
|
+
### Getting a list of commits
|
90
|
+
|
91
|
+
From the `Repo` object, you can get a list of commits as an array of `Commit`
|
92
|
+
objects.
|
93
|
+
|
94
|
+
repo.commits
|
95
|
+
# => [#<Grit::Commit "e80bbd2ce67651aa18e57fb0b43618ad4baf7750">,
|
96
|
+
#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">,
|
97
|
+
#<Grit::Commit "038af8c329ef7c1bae4568b98bd5c58510465493">,
|
98
|
+
#<Grit::Commit "40d3057d09a7a4d61059bca9dca5ae698de58cbe">,
|
99
|
+
#<Grit::Commit "4ea50f4754937bf19461af58ce3b3d24c77311d9">]
|
100
|
+
|
101
|
+
Called without arguments, `Repo#commits` returns a list of up to ten commits
|
102
|
+
reachable by the **master** branch (starting at the latest commit). You can
|
103
|
+
ask for commits beginning at a different branch, commit, tag, etc.
|
104
|
+
|
105
|
+
repo.commits('mybranch')
|
106
|
+
repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe')
|
107
|
+
repo.commits('v0.1')
|
108
|
+
|
109
|
+
You can specify the maximum number of commits to return.
|
110
|
+
|
111
|
+
repo.commits('master', 100)
|
112
|
+
|
113
|
+
If you need paging, you can specify a number of commits to skip.
|
114
|
+
|
115
|
+
repo.commits('master', 10, 20)
|
116
|
+
|
117
|
+
The above will return commits 21-30 from the commit list.
|
118
|
+
|
119
|
+
|
120
|
+
### The Commit object
|
121
|
+
|
122
|
+
`Commit` objects contain information about that commit.
|
123
|
+
|
124
|
+
head = repo.commits.first
|
125
|
+
|
126
|
+
head.id
|
127
|
+
# => "e80bbd2ce67651aa18e57fb0b43618ad4baf7750"
|
128
|
+
|
129
|
+
head.parents
|
130
|
+
# => [#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">]
|
131
|
+
|
132
|
+
head.tree
|
133
|
+
# => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
|
134
|
+
|
135
|
+
head.author
|
136
|
+
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
|
137
|
+
|
138
|
+
head.authored_date
|
139
|
+
# => Wed Oct 24 22:02:31 -0700 2007
|
140
|
+
|
141
|
+
head.committer
|
142
|
+
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
|
143
|
+
|
144
|
+
head.committed_date
|
145
|
+
# => Wed Oct 24 22:02:31 -0700 2007
|
146
|
+
|
147
|
+
head.message
|
148
|
+
# => "add Actor inspect"
|
149
|
+
|
150
|
+
You can traverse a commit's ancestry by chaining calls to `#parents`.
|
151
|
+
|
152
|
+
repo.commits.first.parents[0].parents[0].parents[0]
|
153
|
+
|
154
|
+
The above corresponds to **master^^^** or **master~3** in Git parlance.
|
155
|
+
|
156
|
+
|
157
|
+
### The Tree object
|
158
|
+
|
159
|
+
A tree records pointers to the contents of a directory. Let's say you want
|
160
|
+
the root tree of the latest commit on the **master** branch.
|
161
|
+
|
162
|
+
tree = repo.commits.first.tree
|
163
|
+
# => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
|
164
|
+
|
165
|
+
tree.id
|
166
|
+
# => "3536eb9abac69c3e4db583ad38f3d30f8db4771f"
|
167
|
+
|
168
|
+
Once you have a tree, you can get the contents.
|
169
|
+
|
170
|
+
contents = tree.contents
|
171
|
+
# => [#<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">,
|
172
|
+
#<Grit::Blob "81d2c27608b352814cbe979a6acd678d30219678">,
|
173
|
+
#<Grit::Tree "c3d07b0083f01a6e1ac969a0f32b8d06f20c62e5">,
|
174
|
+
#<Grit::Tree "4d00fe177a8407dbbc64a24dbfc564762c0922d8">]
|
175
|
+
|
176
|
+
This tree contains two `Blob` objects and two `Tree` objects. The trees are
|
177
|
+
subdirectories and the blobs are files. Trees below the root have additional
|
178
|
+
attributes.
|
179
|
+
|
180
|
+
contents.last.name
|
181
|
+
# => "lib"
|
182
|
+
|
183
|
+
contents.last.mode
|
184
|
+
# => "040000"
|
185
|
+
|
186
|
+
There is a convenience method that allows you to get a named sub-object
|
187
|
+
from a tree.
|
188
|
+
|
189
|
+
tree / "lib"
|
190
|
+
# => #<Grit::Tree "e74893a3d8a25cbb1367cf241cc741bfd503c4b2">
|
191
|
+
|
192
|
+
You can also get a tree directly from the repo if you know its name.
|
193
|
+
|
194
|
+
repo.tree
|
195
|
+
# => #<Grit::Tree "master">
|
196
|
+
|
197
|
+
repo.tree("91169e1f5fa4de2eaea3f176461f5dc784796769")
|
198
|
+
# => #<Grit::Tree "91169e1f5fa4de2eaea3f176461f5dc784796769">
|
199
|
+
|
200
|
+
|
201
|
+
### The Blob object
|
202
|
+
|
203
|
+
A blob represents a file. Trees often contain blobs.
|
204
|
+
|
205
|
+
blob = tree.contents.first
|
206
|
+
# => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
|
207
|
+
|
208
|
+
A blob has certain attributes.
|
209
|
+
|
210
|
+
blob.id
|
211
|
+
# => "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666"
|
212
|
+
|
213
|
+
blob.name
|
214
|
+
# => "README.txt"
|
215
|
+
|
216
|
+
blob.mode
|
217
|
+
# => "100644"
|
218
|
+
|
219
|
+
blob.size
|
220
|
+
# => 7726
|
221
|
+
|
222
|
+
You can get the data of a blob as a string.
|
223
|
+
|
224
|
+
blob.data
|
225
|
+
# => "Grit is a library to ..."
|
226
|
+
|
227
|
+
You can also get a blob directly from the repo if you know its name.
|
228
|
+
|
229
|
+
repo.blob("4ebc8aea50e0a67e000ba29a30809d0a7b9b2666")
|
230
|
+
# => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
|
231
|
+
|
232
|
+
|
233
|
+
### Other
|
234
|
+
|
235
|
+
There are many more API methods available that are not documented here. Please
|
236
|
+
reference the code for more functionality.
|
237
|
+
|
238
|
+
|
239
|
+
Copyright
|
240
|
+
---------
|
241
|
+
|
242
|
+
Copyright (c) 2010 Tom Preston-Werner. See LICENSE for details.
|