git 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of git might be problematic. Click here for more details.

@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c8ae61e2cc8dfe5b4e96126181c895d68649c751
4
+ data.tar.gz: 84e328f3fee9f5eba51e60152a53f483dc0f3af1
5
+ SHA512:
6
+ metadata.gz: 4f78b935161f2e5a3d317c55886eba65240bafcc5d5543600f25d4659fc5a0d040557ed14c2a81f1d27bd81a8fbd3d2c1ff951243fb1684635320433951c7985
7
+ data.tar.gz: 6d4de38fa866933ab99af3fc5e8980a2feec5a69cf9f17612f1d394badd9dc0fd5c49597a2d1aa3d2b429409cbefd5502ba6b8aab624f8e03445b08c247a1a25
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008 Scott Chacon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,255 @@
1
+ # Git Library for Ruby
2
+
3
+ Library for using Git in Ruby.
4
+
5
+ ## Homepage
6
+
7
+ Git public hosting of the project source code is at:
8
+
9
+ http://github.com/schacon/ruby-git
10
+
11
+ ## Install
12
+
13
+ You can install Ruby/Git like this:
14
+
15
+ $ sudo gem install git
16
+
17
+ ## Code Status
18
+
19
+ * [![Build Status](https://api.travis-ci.org/schacon/ruby-git.png)](https://travis-ci.org/schacon/ruby-git)
20
+ * [![Code Climate](https://codeclimate.com/github/schacon/ruby-git.png)](https://codeclimate.com/github/schacon/ruby-git)
21
+ * [![Dependencies](https://gemnasium.com/schacon/ruby-git.png?travis)](https://gemnasium.com/schacon/ruby-git)
22
+
23
+ ## Major Objects
24
+
25
+ **Git::Base** - The object returned from a `Git.open` or `Git.clone`. Most major actions are called from this object.
26
+
27
+ **Git::Object** - The base object for your tree, blob and commit objects, returned from `@git.gtree` or `@git.object` calls. the `Git::AbstractObject` will have most of the calls in common for all those objects.
28
+
29
+ **Git::Diff** - returns from a `@git.diff` command. It is an Enumerable that returns `Git::Diff:DiffFile` objects from which you can get per file patches and insertion/deletion statistics. You can also get total statistics from the Git::Diff object directly.
30
+
31
+ **Git::Status** - returns from a `@git.status` command. It is an Enumerable that returns
32
+ `Git:Status::StatusFile` objects for each object in git, which includes files in the working
33
+ directory, in the index and in the repository. Similar to running 'git status' on the command line to determine untracked and changed files.
34
+
35
+ **Git::Branches** - Enumerable object that holds `Git::Branch objects`. You can call .local or .remote on it to filter to just your local or remote branches.
36
+
37
+ **Git::Remote**- A reference to a remote repository that is tracked by this repository.
38
+
39
+ **Git::Log** - An Enumerable object that references all the `Git::Object::Commit` objects that encompass your log query, which can be constructed through methods on the `Git::Log object`,
40
+ like:
41
+
42
+ `@git.log(20).object("some_file").since("2 weeks ago").between('v2.6', 'v2.7').each { |commit| [block] }`
43
+
44
+ ## Examples
45
+
46
+ Here are a bunch of examples of how to use the Ruby/Git package.
47
+
48
+ Ruby < 1.9 will require rubygems to be loaded.
49
+
50
+ ```ruby
51
+ require 'rubygems'
52
+ ```
53
+
54
+ Require the 'git' gem.
55
+ ```ruby
56
+ require 'git'
57
+ ```
58
+
59
+ Here are the operations that need read permission only.
60
+
61
+ ```ruby
62
+ g = Git.open(working_dir, :log => Logger.new(STDOUT))
63
+
64
+ g.index
65
+ g.index.readable?
66
+ g.index.writable?
67
+ g.repo
68
+ g.dir
69
+
70
+ g.log # returns array of Git::Commit objects
71
+ g.log.since('2 weeks ago')
72
+ g.log.between('v2.5', 'v2.6')
73
+ g.log.each {|l| puts l.sha }
74
+ g.gblob('v2.5:Makefile').log.since('2 weeks ago')
75
+
76
+ g.object('HEAD^').to_s # git show / git rev-parse
77
+ g.object('HEAD^').contents
78
+ g.object('v2.5:Makefile').size
79
+ g.object('v2.5:Makefile').sha
80
+
81
+ g.gtree(treeish)
82
+ g.gblob(treeish)
83
+ g.gcommit(treeish)
84
+
85
+
86
+ commit = g.gcommit('1cc8667014381')
87
+
88
+ commit.gtree
89
+ commit.parent.sha
90
+ commit.parents.size
91
+ commit.author.name
92
+ commit.author.email
93
+ commit.author.date.strftime("%m-%d-%y")
94
+ commit.committer.name
95
+ commit.date.strftime("%m-%d-%y")
96
+ commit.message
97
+
98
+ tree = g.gtree("HEAD^{tree}")
99
+
100
+ tree.blobs
101
+ tree.subtrees
102
+ tree.children # blobs and subtrees
103
+
104
+ g.revparse('v2.5:Makefile')
105
+
106
+ g.branches # returns Git::Branch objects
107
+ g.branches.local
108
+ g.branches.remote
109
+ g.branches[:master].gcommit
110
+ g.branches['origin/master'].gcommit
111
+
112
+ g.grep('hello') # implies HEAD
113
+ g.blob('v2.5:Makefile').grep('hello')
114
+ g.tag('v2.5').grep('hello', 'docs/')
115
+
116
+ g.diff(commit1, commit2).size
117
+ g.diff(commit1, commit2).stats
118
+ g.gtree('v2.5').diff('v2.6').insertions
119
+ g.diff('gitsearch1', 'v2.5').path('lib/')
120
+ g.diff('gitsearch1', @git.gtree('v2.5'))
121
+ g.diff('gitsearch1', 'v2.5').path('docs/').patch
122
+ g.gtree('v2.5').diff('v2.6').patch
123
+
124
+ g.gtree('v2.5').diff('v2.6').each do |file_diff|
125
+ puts file_diff.path
126
+ puts file_diff.patch
127
+ puts file_diff.blob(:src).contents
128
+ end
129
+
130
+ g.config('user.name') # returns 'Scott Chacon'
131
+ g.config # returns whole config hash
132
+
133
+ g.tag # returns array of Git::Tag objects
134
+ ```
135
+
136
+ And here are the operations that will need to write to your git repository.
137
+
138
+ ```ruby
139
+ g = Git.init
140
+ Git.init('project')
141
+ Git.init('/home/schacon/proj',
142
+ { :git_dir => '/opt/git/proj.git',
143
+ :index_file => '/tmp/index'} )
144
+
145
+ g = Git.clone(URI, NAME, :path => '/tmp/checkout')
146
+ g.config('user.name', 'Scott Chacon')
147
+ g.config('user.email', 'email@email.com')
148
+
149
+ g.add # git add -- "."
150
+ g.add(:all=>true) # git add --all -- "."
151
+ g.add('file_path') # git add -- "file_path"
152
+ g.add(['file_path_1', 'file_path_2']) # git add -- "file_path_1" "file_path_2"
153
+
154
+
155
+ g.remove('file.txt')
156
+ g.remove(['file.txt', 'file2.txt'])
157
+
158
+ g.commit('message')
159
+ g.commit_all('message')
160
+
161
+ g = Git.clone(repo, 'myrepo')
162
+ g.chdir do
163
+ new_file('test-file', 'blahblahblah')
164
+ g.status.changed.each do |file|
165
+ puts file.blob(:index).contents
166
+ end
167
+ end
168
+
169
+ g.reset # defaults to HEAD
170
+ g.reset_hard(Git::Commit)
171
+
172
+ g.branch('new_branch') # creates new or fetches existing
173
+ g.branch('new_branch').checkout
174
+ g.branch('new_branch').delete
175
+ g.branch('existing_branch').checkout
176
+
177
+ g.checkout('new_branch')
178
+ g.checkout(g.branch('new_branch'))
179
+
180
+ g.branch(name).merge(branch2)
181
+ g.branch(branch2).merge # merges HEAD with branch2
182
+
183
+ g.branch(name).in_branch(message) { # add files } # auto-commits
184
+ g.merge('new_branch')
185
+ g.merge('origin/remote_branch')
186
+ g.merge(g.branch('master'))
187
+ g.merge([branch1, branch2])
188
+
189
+ r = g.add_remote(name, uri) # Git::Remote
190
+ r = g.add_remote(name, Git::Base) # Git::Remote
191
+
192
+ g.remotes # array of Git::Remotes
193
+ g.remote(name).fetch
194
+ g.remote(name).remove
195
+ g.remote(name).merge
196
+ g.remote(name).merge(branch)
197
+
198
+ g.fetch
199
+ g.fetch(g.remotes.first)
200
+
201
+ g.pull
202
+ g.pull(Git::Repo, Git::Branch) # fetch and a merge
203
+
204
+ g.add_tag('tag_name') # returns Git::Tag
205
+
206
+ g.repack
207
+
208
+ g.push
209
+ g.push(g.remote('name'))
210
+ ```
211
+
212
+ Some examples of more low-level index and tree operations
213
+
214
+ ```ruby
215
+ g.with_temp_index do
216
+
217
+ g.read_tree(tree3) # calls self.index.read_tree
218
+ g.read_tree(tree1, :prefix => 'hi/')
219
+
220
+ c = g.commit_tree('message')
221
+ # or #
222
+ t = g.write_tree
223
+ c = g.commit_tree(t, :message => 'message', :parents => [sha1, sha2])
224
+
225
+ g.branch('branch_name').update_ref(c)
226
+ g.update_ref(branch, c)
227
+
228
+ g.with_temp_working do # new blank working directory
229
+ g.checkout
230
+ g.checkout(another_index)
231
+ g.commit # commits to temp_index
232
+ end
233
+ end
234
+
235
+ g.set_index('/path/to/index')
236
+
237
+
238
+ g.with_index(path) do
239
+ # calls set_index, then switches back after
240
+ end
241
+
242
+ g.with_working(dir) do
243
+ # calls set_working, then switches back after
244
+ end
245
+
246
+ g.with_temp_working(dir) do
247
+ g.checkout_index(:prefix => dir, :path_limiter => path)
248
+ # do file work
249
+ g.commit # commits to index
250
+ end
251
+ ```
252
+
253
+ ## License
254
+
255
+ licensed under MIT License Copyright (c) 2008 Scott Chacon. See LICENSE for further details.
data/lib/git.rb CHANGED
@@ -1,30 +1,24 @@
1
-
2
1
  # Add the directory containing this file to the start of the load path if it
3
2
  # isn't there already.
4
3
  $:.unshift(File.dirname(__FILE__)) unless
5
4
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
5
 
6
+ require 'git/author'
7
7
  require 'git/base'
8
- require 'git/path'
9
- require 'git/lib'
10
-
11
- require 'git/repository'
8
+ require 'git/branch'
9
+ require 'git/branches'
10
+ require 'git/diff'
12
11
  require 'git/index'
13
- require 'git/working_directory'
14
-
12
+ require 'git/lib'
15
13
  require 'git/log'
16
14
  require 'git/object'
17
-
18
- require 'git/branches'
19
- require 'git/branch'
15
+ require 'git/path'
20
16
  require 'git/remote'
21
-
22
- require 'git/diff'
17
+ require 'git/repository'
23
18
  require 'git/status'
24
- require 'git/author'
25
-
26
- require 'git/stashes'
27
19
  require 'git/stash'
20
+ require 'git/stashes'
21
+ require 'git/working_directory'
28
22
 
29
23
  lib = Git::Lib.new(nil, nil)
30
24
  unless lib.meets_required_version?
@@ -47,9 +41,29 @@ end
47
41
  # Author:: Scott Chacon (mailto:schacon@gmail.com)
48
42
  # License:: MIT License
49
43
  module Git
50
-
51
- VERSION = '1.0.4'
52
44
 
45
+ #g.config('user.name', 'Scott Chacon') # sets value
46
+ #g.config('user.email', 'email@email.com') # sets value
47
+ #g.config('user.name') # returns 'Scott Chacon'
48
+ #g.config # returns whole config hash
49
+ def config(name = nil, value = nil)
50
+ lib = Git::Lib.new
51
+ if(name && value)
52
+ # set value
53
+ lib.config_set(name, value)
54
+ elsif (name)
55
+ # return value
56
+ lib.config_get(name)
57
+ else
58
+ # return hash
59
+ lib.config_list
60
+ end
61
+ end
62
+
63
+ def global_config(name = nil, value = nil)
64
+ self.class.global_config(name, value)
65
+ end
66
+
53
67
  # open a bare repository
54
68
  #
55
69
  # this takes the path to a bare git repo
@@ -60,29 +74,6 @@ module Git
60
74
  Base.bare(git_dir, options)
61
75
  end
62
76
 
63
- # open an existing git working directory
64
- #
65
- # this will most likely be the most common way to create
66
- # a git reference, referring to a working directory.
67
- # if not provided in the options, the library will assume
68
- # your git_dir and index are in the default place (.git/, .git/index)
69
- #
70
- # options
71
- # :repository => '/path/to/alt_git_dir'
72
- # :index => '/path/to/alt_index_file'
73
- def self.open(working_dir, options = {})
74
- Base.open(working_dir, options)
75
- end
76
-
77
- # initialize a new git repository, defaults to the current working directory
78
- #
79
- # options
80
- # :repository => '/path/to/alt_git_dir'
81
- # :index => '/path/to/alt_index_file'
82
- def self.init(working_dir = '.', options = {})
83
- Base.init(working_dir, options)
84
- end
85
-
86
77
  # clones a remote repository
87
78
  #
88
79
  # options
@@ -96,7 +87,7 @@ module Git
96
87
  def self.clone(repository, name, options = {})
97
88
  Base.clone(repository, name, options)
98
89
  end
99
-
90
+
100
91
  # Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
101
92
  # is specified) into the +name+ directory, then remove all traces of git from the
102
93
  # directory.
@@ -110,25 +101,7 @@ module Git
110
101
  repo.checkout("origin/#{options[:branch]}") if options[:branch]
111
102
  Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
112
103
  end
113
-
114
- #g.config('user.name', 'Scott Chacon') # sets value
115
- #g.config('user.email', 'email@email.com') # sets value
116
- #g.config('user.name') # returns 'Scott Chacon'
117
- #g.config # returns whole config hash
118
- def config(name = nil, value = nil)
119
- lib = Git::Lib.new
120
- if(name && value)
121
- # set value
122
- lib.config_set(name, value)
123
- elsif (name)
124
- # return value
125
- lib.config_get(name)
126
- else
127
- # return hash
128
- lib.config_list
129
- end
130
- end
131
-
104
+
132
105
  # Same as g.config, but forces it to be at the global level
133
106
  #
134
107
  #g.config('user.name', 'Scott Chacon') # sets value
@@ -149,8 +122,27 @@ module Git
149
122
  end
150
123
  end
151
124
 
152
- def global_config(name = nil, value = nil)
153
- self.class.global_config(name, value)
125
+ # initialize a new git repository, defaults to the current working directory
126
+ #
127
+ # options
128
+ # :repository => '/path/to/alt_git_dir'
129
+ # :index => '/path/to/alt_index_file'
130
+ def self.init(working_dir = '.', options = {})
131
+ Base.init(working_dir, options)
132
+ end
133
+
134
+ # open an existing git working directory
135
+ #
136
+ # this will most likely be the most common way to create
137
+ # a git reference, referring to a working directory.
138
+ # if not provided in the options, the library will assume
139
+ # your git_dir and index are in the default place (.git/, .git/index)
140
+ #
141
+ # options
142
+ # :repository => '/path/to/alt_git_dir'
143
+ # :index => '/path/to/alt_index_file'
144
+ def self.open(working_dir, options = {})
145
+ Base.open(working_dir, options)
154
146
  end
155
147
 
156
148
  end