robinluckey-grit 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/API.txt +101 -0
- data/History.txt +49 -0
- data/README.md +210 -0
- data/VERSION.yml +4 -0
- data/lib/grit.rb +68 -0
- data/lib/grit/actor.rb +36 -0
- data/lib/grit/blame.rb +61 -0
- data/lib/grit/blob.rb +126 -0
- data/lib/grit/commit.rb +252 -0
- data/lib/grit/commit_stats.rb +128 -0
- data/lib/grit/config.rb +44 -0
- data/lib/grit/diff.rb +70 -0
- data/lib/grit/errors.rb +7 -0
- data/lib/grit/git-ruby.rb +186 -0
- data/lib/grit/git-ruby/commit_db.rb +52 -0
- data/lib/grit/git-ruby/file_index.rb +193 -0
- data/lib/grit/git-ruby/git_object.rb +350 -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 +382 -0
- data/lib/grit/git-ruby/internal/raw_object.rb +37 -0
- data/lib/grit/git-ruby/object.rb +325 -0
- data/lib/grit/git-ruby/repository.rb +736 -0
- data/lib/grit/git.rb +140 -0
- data/lib/grit/index.rb +122 -0
- data/lib/grit/lazy.rb +33 -0
- data/lib/grit/merge.rb +45 -0
- data/lib/grit/ref.rb +99 -0
- data/lib/grit/repo.rb +437 -0
- data/lib/grit/ruby1.9.rb +7 -0
- data/lib/grit/status.rb +151 -0
- data/lib/grit/submodule.rb +88 -0
- data/lib/grit/tag.rb +66 -0
- data/lib/grit/tree.rb +123 -0
- data/lib/open3_detach.rb +46 -0
- metadata +111 -0
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,49 @@
|
|
1
|
+
== 1.1.0 / 2009-03-29
|
2
|
+
* Backwards breaking changes
|
3
|
+
* Diff#a_commit -> Diff#a_blob, Diff#b_commit -> Diff#b_blob
|
4
|
+
* Major Enhancments
|
5
|
+
* Ruby 1.9 compatibility [github.com/chapados, github.com/js]
|
6
|
+
* Minor Enhancements
|
7
|
+
* Convert readme to markdown
|
8
|
+
* Added a shortcut for commit_stats as Commit#stats [github.com/js]
|
9
|
+
* Add a #basename method to Submodule, Blob and Tree for retrieving the name [github.com/js]
|
10
|
+
* Make Grit::Submodule grasp the concept of non-unix lineendings [github.com/js]
|
11
|
+
* Added Repo#commit_deltas_from [github.com/js]
|
12
|
+
* do some mild shell escaping when running commands [github.com/js]
|
13
|
+
* Added two shortcut methods to Tree, for picking trees/blobs only [github.com/Voker57]
|
14
|
+
* Added <=> method to Blob, needed for sorting tree [github.com/Voker57]
|
15
|
+
* Make the number of bytes to be read from git's stdout configurable [github.com/josb]
|
16
|
+
* Repo.archive_to_file accepts extra parameters making plain zipping possible [github.com/darwin]
|
17
|
+
* Handle commit stats that summarize commits with binary changes [github.com/therealadam]
|
18
|
+
* Add a DiffStat class for easy access to diff stats [github.com/therealadam]
|
19
|
+
* Don't split git logs that contain blank lines into two CommitStats [github.com/therealadam]
|
20
|
+
* Add DiffStat#net for total change count [github.com/therealadam]
|
21
|
+
|
22
|
+
== 1.0.3 / 2009-02-13
|
23
|
+
* Minor Enhancements
|
24
|
+
* Added Grit::Commit#to_patch for plaintext formatted patches.
|
25
|
+
* Fixed Grit::Tag to work with annotated tags.
|
26
|
+
|
27
|
+
== 1.0.2 / 2009-02-10
|
28
|
+
* Minor Enhancements
|
29
|
+
* Implement Grit.version to use VERSION.yml file
|
30
|
+
|
31
|
+
== 1.0.1 / 2009-02-10
|
32
|
+
* Bug Fixes
|
33
|
+
* Add diff-lcs as a dependency
|
34
|
+
|
35
|
+
== 1.0.0 / 2009-01-27
|
36
|
+
* Tons of awesome in here. Also, we suck at updating the history.
|
37
|
+
* Let's do better at that from now on.
|
38
|
+
|
39
|
+
== 0.8.3 / 2008-07-07
|
40
|
+
* Capture stderr and log if debug is true (rsanheim)
|
41
|
+
|
42
|
+
== 0.8.2 / 2008-06-27
|
43
|
+
* Allow user provided logger (rsanheim)
|
44
|
+
|
45
|
+
== 0.8.0 / 2008-04-24
|
46
|
+
* Lots of fixes and additions
|
47
|
+
|
48
|
+
== 0.7.0 / 2008-01-07
|
49
|
+
* First public release!
|
data/README.md
ADDED
@@ -0,0 +1,210 @@
|
|
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 correctness.
|
13
|
+
|
14
|
+
Grit is maintained by Tom Preston-Werner, Scott Chacon, Chris Wanstrath, and
|
15
|
+
PJ Hyett.
|
16
|
+
|
17
|
+
This documentation is accurate as of Grit 1.0.2.
|
18
|
+
|
19
|
+
|
20
|
+
## Requirements #############################################################
|
21
|
+
|
22
|
+
* git (http://git-scm.com) tested with 1.6.0.2
|
23
|
+
|
24
|
+
|
25
|
+
## Install ##################################################################
|
26
|
+
|
27
|
+
Easiest install is via RubyGems:
|
28
|
+
|
29
|
+
$ gem install grit
|
30
|
+
|
31
|
+
or
|
32
|
+
|
33
|
+
$ gem sources -a http://gems.github.com/ (you only need to do this once)
|
34
|
+
$ gem install mojombo-grit
|
35
|
+
|
36
|
+
The gem from GitHub will generally be available sooner than the gem from
|
37
|
+
Rubyforge. Both sources will eventually contain the same releases.
|
38
|
+
|
39
|
+
|
40
|
+
## Source ###################################################################
|
41
|
+
|
42
|
+
Grit's Git repo is available on GitHub, which can be browsed at:
|
43
|
+
|
44
|
+
http://github.com/mojombo/grit
|
45
|
+
|
46
|
+
and cloned with:
|
47
|
+
|
48
|
+
git clone git://github.com/mojombo/grit.git
|
49
|
+
|
50
|
+
|
51
|
+
## Usage ####################################################################
|
52
|
+
|
53
|
+
Grit gives you object model access to your Git repositories. Once you have
|
54
|
+
created a `Repo` object, you can traverse it to find parent commits,
|
55
|
+
trees, blobs, etc.
|
56
|
+
|
57
|
+
### Initialize a Repo object
|
58
|
+
|
59
|
+
The first step is to create a `Grit::Repo` object to represent your repo. In
|
60
|
+
this documentation I include the `Grit` module to reduce typing.
|
61
|
+
|
62
|
+
require 'grit'
|
63
|
+
include Grit
|
64
|
+
repo = Repo.new("/Users/tom/dev/grit")
|
65
|
+
|
66
|
+
In the above example, the directory `/Users/tom/dev/grit` is my working
|
67
|
+
directory and contains the `.git` directory. You can also initialize Grit with
|
68
|
+
a bare repo.
|
69
|
+
|
70
|
+
repo = Repo.new("/var/git/grit.git")
|
71
|
+
|
72
|
+
### Getting a list of commits
|
73
|
+
|
74
|
+
From the `Repo` object, you can get a list of commits as an array of `Commit`
|
75
|
+
objects.
|
76
|
+
|
77
|
+
repo.commits
|
78
|
+
# => [#<Grit::Commit "e80bbd2ce67651aa18e57fb0b43618ad4baf7750">,
|
79
|
+
#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">,
|
80
|
+
#<Grit::Commit "038af8c329ef7c1bae4568b98bd5c58510465493">,
|
81
|
+
#<Grit::Commit "40d3057d09a7a4d61059bca9dca5ae698de58cbe">,
|
82
|
+
#<Grit::Commit "4ea50f4754937bf19461af58ce3b3d24c77311d9">]
|
83
|
+
|
84
|
+
Called without arguments, `Repo#commits` returns a list of up to ten commits
|
85
|
+
reachable by the **master** branch (starting at the latest commit). You can
|
86
|
+
ask for commits beginning at a different branch, commit, tag, etc.
|
87
|
+
|
88
|
+
repo.commits('mybranch')
|
89
|
+
repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe')
|
90
|
+
repo.commits('v0.1')
|
91
|
+
|
92
|
+
You can specify the maximum number of commits to return.
|
93
|
+
|
94
|
+
repo.commits('master', 100)
|
95
|
+
|
96
|
+
If you need paging, you can specify a number of commits to skip.
|
97
|
+
|
98
|
+
repo.commits('master', 10, 20)
|
99
|
+
|
100
|
+
The above will return commits 21-30 from the commit list.
|
101
|
+
|
102
|
+
### The Commit object
|
103
|
+
|
104
|
+
`Commit` objects contain information about that commit.
|
105
|
+
|
106
|
+
head = repo.commits.first
|
107
|
+
|
108
|
+
head.id
|
109
|
+
# => "e80bbd2ce67651aa18e57fb0b43618ad4baf7750"
|
110
|
+
|
111
|
+
head.parents
|
112
|
+
# => [#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">]
|
113
|
+
|
114
|
+
head.tree
|
115
|
+
# => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
|
116
|
+
|
117
|
+
head.author
|
118
|
+
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
|
119
|
+
|
120
|
+
head.authored_date
|
121
|
+
# => Wed Oct 24 22:02:31 -0700 2007
|
122
|
+
|
123
|
+
head.committer
|
124
|
+
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
|
125
|
+
|
126
|
+
head.committed_date
|
127
|
+
# => Wed Oct 24 22:02:31 -0700 2007
|
128
|
+
|
129
|
+
head.message
|
130
|
+
# => "add Actor inspect"
|
131
|
+
|
132
|
+
You can traverse a commit's ancestry by chaining calls to `#parents`.
|
133
|
+
|
134
|
+
repo.commits.first.parents[0].parents[0].parents[0]
|
135
|
+
|
136
|
+
The above corresponds to **master^^^** or **master~3** in Git parlance.
|
137
|
+
|
138
|
+
### The Tree object
|
139
|
+
|
140
|
+
A tree records pointers to the contents of a directory. Let's say you want
|
141
|
+
the root tree of the latest commit on the **master** branch.
|
142
|
+
|
143
|
+
tree = repo.commits.first.tree
|
144
|
+
# => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
|
145
|
+
|
146
|
+
tree.id
|
147
|
+
# => "3536eb9abac69c3e4db583ad38f3d30f8db4771f"
|
148
|
+
|
149
|
+
Once you have a tree, you can get the contents.
|
150
|
+
|
151
|
+
contents = tree.contents
|
152
|
+
# => [#<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">,
|
153
|
+
#<Grit::Blob "81d2c27608b352814cbe979a6acd678d30219678">,
|
154
|
+
#<Grit::Tree "c3d07b0083f01a6e1ac969a0f32b8d06f20c62e5">,
|
155
|
+
#<Grit::Tree "4d00fe177a8407dbbc64a24dbfc564762c0922d8">]
|
156
|
+
|
157
|
+
This tree contains two `Blob` objects and two `Tree` objects. The trees are
|
158
|
+
subdirectories and the blobs are files. Trees below the root have additional
|
159
|
+
attributes.
|
160
|
+
|
161
|
+
contents.last.name
|
162
|
+
# => "lib"
|
163
|
+
|
164
|
+
contents.last.mode
|
165
|
+
# => "040000"
|
166
|
+
|
167
|
+
There is a convenience method that allows you to get a named sub-object
|
168
|
+
from a tree.
|
169
|
+
|
170
|
+
tree / "lib"
|
171
|
+
# => #<Grit::Tree "e74893a3d8a25cbb1367cf241cc741bfd503c4b2">
|
172
|
+
|
173
|
+
You can also get a tree directly from the repo if you know its name.
|
174
|
+
|
175
|
+
repo.tree
|
176
|
+
# => #<Grit::Tree "master">
|
177
|
+
|
178
|
+
repo.tree("91169e1f5fa4de2eaea3f176461f5dc784796769")
|
179
|
+
# => #<Grit::Tree "91169e1f5fa4de2eaea3f176461f5dc784796769">
|
180
|
+
|
181
|
+
### The Blob object
|
182
|
+
|
183
|
+
A blob represents a file. Trees often contain blobs.
|
184
|
+
|
185
|
+
blob = tree.contents.first
|
186
|
+
# => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
|
187
|
+
|
188
|
+
A blob has certain attributes.
|
189
|
+
|
190
|
+
blob.id
|
191
|
+
# => "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666"
|
192
|
+
|
193
|
+
blob.name
|
194
|
+
# => "README.txt"
|
195
|
+
|
196
|
+
blob.mode
|
197
|
+
# => "100644"
|
198
|
+
|
199
|
+
blob.size
|
200
|
+
# => 7726
|
201
|
+
|
202
|
+
You can get the data of a blob as a string.
|
203
|
+
|
204
|
+
blob.data
|
205
|
+
# => "Grit is a library to ..."
|
206
|
+
|
207
|
+
You can also get a blob directly from the repo if you know its name.
|
208
|
+
|
209
|
+
repo.blob("4ebc8aea50e0a67e000ba29a30809d0a7b9b2666")
|
210
|
+
# => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
|
data/VERSION.yml
ADDED
data/lib/grit.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
|
2
|
+
|
3
|
+
# core
|
4
|
+
require 'fileutils'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
# stdlib
|
8
|
+
require 'timeout'
|
9
|
+
require 'logger'
|
10
|
+
require 'digest/sha1'
|
11
|
+
|
12
|
+
if defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby'
|
13
|
+
require 'open3'
|
14
|
+
else
|
15
|
+
require 'open3_detach'
|
16
|
+
end
|
17
|
+
|
18
|
+
# third party
|
19
|
+
require 'rubygems'
|
20
|
+
gem "mime-types", ">=0"
|
21
|
+
require 'mime/types'
|
22
|
+
|
23
|
+
# ruby 1.9 compatibility
|
24
|
+
require 'grit/ruby1.9'
|
25
|
+
|
26
|
+
# internal requires
|
27
|
+
require 'grit/lazy'
|
28
|
+
require 'grit/errors'
|
29
|
+
require 'grit/git-ruby'
|
30
|
+
require 'grit/git'
|
31
|
+
require 'grit/ref'
|
32
|
+
require 'grit/tag'
|
33
|
+
require 'grit/commit'
|
34
|
+
require 'grit/commit_stats'
|
35
|
+
require 'grit/tree'
|
36
|
+
require 'grit/blob'
|
37
|
+
require 'grit/actor'
|
38
|
+
require 'grit/diff'
|
39
|
+
require 'grit/config'
|
40
|
+
require 'grit/repo'
|
41
|
+
require 'grit/index'
|
42
|
+
require 'grit/status'
|
43
|
+
require 'grit/submodule'
|
44
|
+
require 'grit/blame'
|
45
|
+
require 'grit/merge'
|
46
|
+
|
47
|
+
|
48
|
+
module Grit
|
49
|
+
class << self
|
50
|
+
# Set +debug+ to true to log all git calls and responses
|
51
|
+
attr_accessor :debug
|
52
|
+
attr_accessor :use_git_ruby
|
53
|
+
# The standard +logger+ for debugging git calls - this defaults to a plain STDOUT logger
|
54
|
+
attr_accessor :logger
|
55
|
+
def log(str)
|
56
|
+
logger.debug { str }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
self.debug = false
|
60
|
+
self.use_git_ruby = true
|
61
|
+
|
62
|
+
@logger ||= ::Logger.new(STDOUT)
|
63
|
+
|
64
|
+
def self.version
|
65
|
+
yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
|
66
|
+
"#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
|
67
|
+
end
|
68
|
+
end
|
data/lib/grit/actor.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Grit
|
2
|
+
|
3
|
+
class Actor
|
4
|
+
attr_reader :name
|
5
|
+
attr_reader :email
|
6
|
+
|
7
|
+
def initialize(name, email)
|
8
|
+
@name = name
|
9
|
+
@email = email
|
10
|
+
end
|
11
|
+
alias_method :to_s, :name
|
12
|
+
|
13
|
+
# Create an Actor from a string.
|
14
|
+
# +str+ is the string, which is expected to be in regular git format
|
15
|
+
#
|
16
|
+
# Format
|
17
|
+
# John Doe <jdoe@example.com>
|
18
|
+
#
|
19
|
+
# Returns Actor
|
20
|
+
def self.from_string(str)
|
21
|
+
case str
|
22
|
+
when /<.+>/
|
23
|
+
m, name, email = *str.match(/(.*) <(.+?)>/)
|
24
|
+
return self.new(name, email)
|
25
|
+
else
|
26
|
+
return self.new(str, nil)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Pretty object inspection
|
31
|
+
def inspect
|
32
|
+
%Q{#<Grit::Actor "#{@name} <#{@email}>">}
|
33
|
+
end
|
34
|
+
end # Actor
|
35
|
+
|
36
|
+
end # Grit
|