clc-git 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: edc5ddca224078904bd029b3e80eb3c5db325d1d
4
+ data.tar.gz: 0004502da99f70453a78ee742fb9477ec65828ad
5
+ SHA512:
6
+ metadata.gz: 23f169c450c651ee9f2b18a72f1b507a7c925505775a401c05875ee528f179e02e0995cefb5d1008297bbfacbc31830bd43ebd5829ebdd503b24beaf31a27ba6
7
+ data.tar.gz: 4f4b73b65c8bef13bf4af7a0565beb18a761b3212a2bd3519ddfba220694ea7d4c44c05b6e1fb39ad2cc6d4d66b47588cc314cd9bc41b07da8f30f6a9a268753
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,268 @@
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
+ * [![Gem Version](https://badge.fury.io/rb/git.png)](http://badge.fury.io/rb/git)
22
+ * [![Dependencies](https://gemnasium.com/schacon/ruby-git.png?travis)](https://gemnasium.com/schacon/ruby-git)
23
+
24
+ ## Major Objects
25
+
26
+ **Git::Base** - The object returned from a `Git.open` or `Git.clone`. Most major actions are called from this object.
27
+
28
+ **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.
29
+
30
+ **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.
31
+
32
+ **Git::Status** - returns from a `@git.status` command. It is an Enumerable that returns
33
+ `Git:Status::StatusFile` objects for each object in git, which includes files in the working
34
+ directory, in the index and in the repository. Similar to running 'git status' on the command line to determine untracked and changed files.
35
+
36
+ **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.
37
+
38
+ **Git::Remote**- A reference to a remote repository that is tracked by this repository.
39
+
40
+ **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`,
41
+ like:
42
+
43
+ `@git.log(20).object("some_file").since("2 weeks ago").between('v2.6', 'v2.7').each { |commit| [block] }`
44
+
45
+ ## Examples
46
+
47
+ Here are a bunch of examples of how to use the Ruby/Git package.
48
+
49
+ Ruby < 1.9 will require rubygems to be loaded.
50
+
51
+ ```ruby
52
+ require 'rubygems'
53
+ ```
54
+
55
+ Require the 'git' gem.
56
+ ```ruby
57
+ require 'git'
58
+ ```
59
+
60
+ Here are the operations that need read permission only.
61
+
62
+ ```ruby
63
+ g = Git.open(working_dir, :log => Logger.new(STDOUT))
64
+
65
+ g.index
66
+ g.index.readable?
67
+ g.index.writable?
68
+ g.repo
69
+ g.dir
70
+
71
+ g.log # returns array of Git::Commit objects
72
+ g.log.since('2 weeks ago')
73
+ g.log.between('v2.5', 'v2.6')
74
+ g.log.each {|l| puts l.sha }
75
+ g.gblob('v2.5:Makefile').log.since('2 weeks ago')
76
+
77
+ g.object('HEAD^').to_s # git show / git rev-parse
78
+ g.object('HEAD^').contents
79
+ g.object('v2.5:Makefile').size
80
+ g.object('v2.5:Makefile').sha
81
+
82
+ g.gtree(treeish)
83
+ g.gblob(treeish)
84
+ g.gcommit(treeish)
85
+
86
+
87
+ commit = g.gcommit('1cc8667014381')
88
+
89
+ commit.gtree
90
+ commit.parent.sha
91
+ commit.parents.size
92
+ commit.author.name
93
+ commit.author.email
94
+ commit.author.date.strftime("%m-%d-%y")
95
+ commit.committer.name
96
+ commit.date.strftime("%m-%d-%y")
97
+ commit.message
98
+
99
+ tree = g.gtree("HEAD^{tree}")
100
+
101
+ tree.blobs
102
+ tree.subtrees
103
+ tree.children # blobs and subtrees
104
+
105
+ g.revparse('v2.5:Makefile')
106
+
107
+ g.branches # returns Git::Branch objects
108
+ g.branches.local
109
+ g.branches.remote
110
+ g.branches[:master].gcommit
111
+ g.branches['origin/master'].gcommit
112
+
113
+ g.grep('hello') # implies HEAD
114
+ g.blob('v2.5:Makefile').grep('hello')
115
+ g.tag('v2.5').grep('hello', 'docs/')
116
+
117
+ g.diff(commit1, commit2).size
118
+ g.diff(commit1, commit2).stats
119
+ g.gtree('v2.5').diff('v2.6').insertions
120
+ g.diff('gitsearch1', 'v2.5').path('lib/')
121
+ g.diff('gitsearch1', @git.gtree('v2.5'))
122
+ g.diff('gitsearch1', 'v2.5').path('docs/').patch
123
+ g.gtree('v2.5').diff('v2.6').patch
124
+
125
+ g.gtree('v2.5').diff('v2.6').each do |file_diff|
126
+ puts file_diff.path
127
+ puts file_diff.patch
128
+ puts file_diff.blob(:src).contents
129
+ end
130
+
131
+ g.config('user.name') # returns 'Scott Chacon'
132
+ g.config # returns whole config hash
133
+
134
+ g.tags # returns array of Git::Tag objects
135
+ ```
136
+
137
+ And here are the operations that will need to write to your git repository.
138
+
139
+ ```ruby
140
+ g = Git.init
141
+ Git.init('project')
142
+ Git.init('/home/schacon/proj',
143
+ { :repository => '/opt/git/proj.git',
144
+ :index => '/tmp/index'} )
145
+
146
+ g = Git.clone(URI, NAME, :path => '/tmp/checkout')
147
+ g.config('user.name', 'Scott Chacon')
148
+ g.config('user.email', 'email@email.com')
149
+
150
+ g.add # git add -- "."
151
+ g.add(:all=>true) # git add --all -- "."
152
+ g.add('file_path') # git add -- "file_path"
153
+ g.add(['file_path_1', 'file_path_2']) # git add -- "file_path_1" "file_path_2"
154
+
155
+
156
+ g.remove('file.txt')
157
+ g.remove(['file.txt', 'file2.txt'])
158
+
159
+ g.commit('message')
160
+ g.commit_all('message')
161
+
162
+ g = Git.clone(repo, 'myrepo')
163
+ g.chdir do
164
+ new_file('test-file', 'blahblahblah')
165
+ g.status.changed.each do |file|
166
+ puts file.blob(:index).contents
167
+ end
168
+ end
169
+
170
+ g.reset # defaults to HEAD
171
+ g.reset_hard(Git::Commit)
172
+
173
+ g.branch('new_branch') # creates new or fetches existing
174
+ g.branch('new_branch').checkout
175
+ g.branch('new_branch').delete
176
+ g.branch('existing_branch').checkout
177
+
178
+ g.checkout('new_branch')
179
+ g.checkout(g.branch('new_branch'))
180
+
181
+ g.branch(name).merge(branch2)
182
+ g.branch(branch2).merge # merges HEAD with branch2
183
+
184
+ g.branch(name).in_branch(message) { # add files } # auto-commits
185
+ g.merge('new_branch')
186
+ g.merge('origin/remote_branch')
187
+ g.merge(g.branch('master'))
188
+ g.merge([branch1, branch2])
189
+
190
+ r = g.add_remote(name, uri) # Git::Remote
191
+ r = g.add_remote(name, Git::Base) # Git::Remote
192
+
193
+ g.remotes # array of Git::Remotes
194
+ g.remote(name).fetch
195
+ g.remote(name).remove
196
+ g.remote(name).merge
197
+ g.remote(name).merge(branch)
198
+
199
+ g.fetch
200
+ g.fetch(g.remotes.first)
201
+
202
+ g.pull
203
+ g.pull(Git::Repo, Git::Branch) # fetch and a merge
204
+
205
+ g.add_tag('tag_name') # returns Git::Tag
206
+ g.add_tag('tag_name', 'object_reference')
207
+ g.add_tag('tag_name', 'object_reference', {:options => 'here'})
208
+ g.add_tag('tag_name', {:options => 'here'})
209
+
210
+ Options:
211
+ :a | :annotate
212
+ :d
213
+ :f
214
+ :m | :message
215
+ :s
216
+
217
+ g.delete_tag('tag_name')
218
+
219
+ g.repack
220
+
221
+ g.push
222
+ g.push(g.remote('name'))
223
+ ```
224
+
225
+ Some examples of more low-level index and tree operations
226
+
227
+ ```ruby
228
+ g.with_temp_index do
229
+
230
+ g.read_tree(tree3) # calls self.index.read_tree
231
+ g.read_tree(tree1, :prefix => 'hi/')
232
+
233
+ c = g.commit_tree('message')
234
+ # or #
235
+ t = g.write_tree
236
+ c = g.commit_tree(t, :message => 'message', :parents => [sha1, sha2])
237
+
238
+ g.branch('branch_name').update_ref(c)
239
+ g.update_ref(branch, c)
240
+
241
+ g.with_temp_working do # new blank working directory
242
+ g.checkout
243
+ g.checkout(another_index)
244
+ g.commit # commits to temp_index
245
+ end
246
+ end
247
+
248
+ g.set_index('/path/to/index')
249
+
250
+
251
+ g.with_index(path) do
252
+ # calls set_index, then switches back after
253
+ end
254
+
255
+ g.with_working(dir) do
256
+ # calls set_working, then switches back after
257
+ end
258
+
259
+ g.with_temp_working(dir) do
260
+ g.checkout_index(:prefix => dir, :path_limiter => path)
261
+ # do file work
262
+ g.commit # commits to index
263
+ end
264
+ ```
265
+
266
+ ## License
267
+
268
+ licensed under MIT License Copyright (c) 2008 Scott Chacon. See LICENSE for further details.
@@ -0,0 +1,148 @@
1
+ # Add the directory containing this file to the start of the load path if it
2
+ # isn't there already.
3
+ $:.unshift(File.dirname(__FILE__)) unless
4
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
+
6
+ require 'git/author'
7
+ require 'git/base'
8
+ require 'git/branch'
9
+ require 'git/branches'
10
+ require 'git/diff'
11
+ require 'git/index'
12
+ require 'git/lib'
13
+ require 'git/log'
14
+ require 'git/object'
15
+ require 'git/path'
16
+ require 'git/remote'
17
+ require 'git/repository'
18
+ require 'git/status'
19
+ require 'git/stash'
20
+ require 'git/stashes'
21
+ require 'git/working_directory'
22
+
23
+ lib = Git::Lib.new(nil, nil)
24
+ unless lib.meets_required_version?
25
+ $stderr.puts "[WARNING] The git gem requires git #{lib.required_command_version.join('.')} or later, but only found #{lib.current_command_version.join('.')}. You should probably upgrade."
26
+ end
27
+
28
+ # Git/Ruby Library
29
+ #
30
+ # This provides bindings for working with git in complex
31
+ # interactions, including branching and merging, object
32
+ # inspection and manipulation, history, patch generation
33
+ # and more. You should be able to do most fundamental git
34
+ # operations with this library.
35
+ #
36
+ # This module provides the basic functions to open a git
37
+ # reference to work with. You can open a working directory,
38
+ # open a bare repository, initialize a new repo or clone an
39
+ # existing remote repository.
40
+ #
41
+ # Author:: Scott Chacon (mailto:schacon@gmail.com)
42
+ # License:: MIT License
43
+ module Git
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
+
67
+ # open a bare repository
68
+ #
69
+ # this takes the path to a bare git repo
70
+ # it expects not to be able to use a working directory
71
+ # so you can't checkout stuff, commit things, etc.
72
+ # but you can do most read operations
73
+ def self.bare(git_dir, options = {})
74
+ Base.bare(git_dir, options)
75
+ end
76
+
77
+ # clones a remote repository
78
+ #
79
+ # options
80
+ # :bare => true (does a bare clone)
81
+ # :repository => '/path/to/alt_git_dir'
82
+ # :index => '/path/to/alt_index_file'
83
+ #
84
+ # example
85
+ # Git.clone('git://repo.or.cz/rubygit.git', 'clone.git', :bare => true)
86
+ #
87
+ def self.clone(repository, name, options = {})
88
+ Base.clone(repository, name, options)
89
+ end
90
+
91
+ # Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
92
+ # is specified) into the +name+ directory, then remove all traces of git from the
93
+ # directory.
94
+ #
95
+ # See +clone+ for options. Does not obey the <tt>:remote</tt> option,
96
+ # since the .git info will be deleted anyway; always uses the default
97
+ # remote, 'origin.'
98
+ def self.export(repository, name, options = {})
99
+ options.delete(:remote)
100
+ repo = clone(repository, name, {:depth => 1}.merge(options))
101
+ repo.checkout("origin/#{options[:branch]}") if options[:branch]
102
+ Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
103
+ end
104
+
105
+ # Same as g.config, but forces it to be at the global level
106
+ #
107
+ #g.config('user.name', 'Scott Chacon') # sets value
108
+ #g.config('user.email', 'email@email.com') # sets value
109
+ #g.config('user.name') # returns 'Scott Chacon'
110
+ #g.config # returns whole config hash
111
+ def self.global_config(name = nil, value = nil)
112
+ lib = Git::Lib.new(nil, nil)
113
+ if(name && value)
114
+ # set value
115
+ lib.global_config_set(name, value)
116
+ elsif (name)
117
+ # return value
118
+ lib.global_config_get(name)
119
+ else
120
+ # return hash
121
+ lib.global_config_list
122
+ end
123
+ end
124
+
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)
146
+ end
147
+
148
+ end
@@ -0,0 +1,14 @@
1
+ module Git
2
+ class Author
3
+ attr_accessor :name, :email, :date
4
+
5
+ def initialize(author_string)
6
+ if m = /(.*?) <(.*?)> (\d+) (.*)/.match(author_string)
7
+ @name = m[1]
8
+ @email = m[2]
9
+ @date = Time.at(m[3].to_i)
10
+ end
11
+ end
12
+
13
+ end
14
+ end