git 1.2.6 → 1.2.7

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8ae61e2cc8dfe5b4e96126181c895d68649c751
4
- data.tar.gz: 84e328f3fee9f5eba51e60152a53f483dc0f3af1
3
+ metadata.gz: e73a59980e39d1594016c2f8964e0455ef7c25d3
4
+ data.tar.gz: 2e33fbe0fb5bb3174b3e79bbc86ecf343576dfb5
5
5
  SHA512:
6
- metadata.gz: 4f78b935161f2e5a3d317c55886eba65240bafcc5d5543600f25d4659fc5a0d040557ed14c2a81f1d27bd81a8fbd3d2c1ff951243fb1684635320433951c7985
7
- data.tar.gz: 6d4de38fa866933ab99af3fc5e8980a2feec5a69cf9f17612f1d394badd9dc0fd5c49597a2d1aa3d2b429409cbefd5502ba6b8aab624f8e03445b08c247a1a25
6
+ metadata.gz: 0a833f95f5c969ba1c9b71320037cb9b9ba885daaace2a9aa99bbcd545e8887f997904cf592e4c4ee384c01b537623220e5ad5c3d1265845d6a3ec04167128b1
7
+ data.tar.gz: 463f0488b4ea9691599983646e18c6f96d593ed262b83b175307477e91f03b9b8fd79ab55c4088247391c2faba607b45e91a7e735f44c3ae7e40e9fbda75fa51
data/README.md CHANGED
@@ -18,6 +18,7 @@ You can install Ruby/Git like this:
18
18
 
19
19
  * [![Build Status](https://api.travis-ci.org/schacon/ruby-git.png)](https://travis-ci.org/schacon/ruby-git)
20
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)
21
22
  * [![Dependencies](https://gemnasium.com/schacon/ruby-git.png?travis)](https://gemnasium.com/schacon/ruby-git)
22
23
 
23
24
  ## Major Objects
@@ -130,7 +131,7 @@ Here are the operations that need read permission only.
130
131
  g.config('user.name') # returns 'Scott Chacon'
131
132
  g.config # returns whole config hash
132
133
 
133
- g.tag # returns array of Git::Tag objects
134
+ g.tags # returns array of Git::Tag objects
134
135
  ```
135
136
 
136
137
  And here are the operations that will need to write to your git repository.
@@ -139,8 +140,8 @@ And here are the operations that will need to write to your git repository.
139
140
  g = Git.init
140
141
  Git.init('project')
141
142
  Git.init('/home/schacon/proj',
142
- { :git_dir => '/opt/git/proj.git',
143
- :index_file => '/tmp/index'} )
143
+ { :repository => '/opt/git/proj.git',
144
+ :index => '/tmp/index'} )
144
145
 
145
146
  g = Git.clone(URI, NAME, :path => '/tmp/checkout')
146
147
  g.config('user.name', 'Scott Chacon')
@@ -202,6 +203,18 @@ And here are the operations that will need to write to your git repository.
202
203
  g.pull(Git::Repo, Git::Branch) # fetch and a merge
203
204
 
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')
205
218
 
206
219
  g.repack
207
220
 
@@ -332,8 +332,8 @@ module Git
332
332
 
333
333
  # fetches changes from a remote branch - this does not modify the working directory,
334
334
  # it just gets the changes from the remote if there are any
335
- def fetch(remote = 'origin')
336
- self.lib.fetch(remote)
335
+ def fetch(remote = 'origin', opts={})
336
+ self.lib.fetch(remote, opts)
337
337
  end
338
338
 
339
339
  # pushes changes to a remote repository - easiest if this is a cloned repository,
@@ -341,8 +341,11 @@ module Git
341
341
  #
342
342
  # @git.config('remote.remote-name.push', 'refs/heads/master:refs/heads/master')
343
343
  #
344
- def push(remote = 'origin', branch = 'master', tags = false)
345
- self.lib.push(remote, branch, tags)
344
+ def push(remote = 'origin', branch = 'master', opts = {})
345
+ # Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
346
+ opts = {:tags => opts} if [true, false].include?(opts)
347
+
348
+ self.lib.push(remote, branch, opts)
346
349
  end
347
350
 
348
351
  # merges one or more branches into the current working branch
@@ -405,10 +408,27 @@ module Git
405
408
  Git::Object.new(self, tag_name, 'tag', true)
406
409
  end
407
410
 
408
- # creates a new git tag (Git::Tag)
409
- def add_tag(tag_name)
410
- self.lib.tag(tag_name)
411
- tag(tag_name)
411
+ # Creates a new git tag (Git::Tag)
412
+ # Usage:
413
+ # repo.add_tag('tag_name', object_reference)
414
+ # repo.add_tag('tag_name', object_reference, {:options => 'here'})
415
+ # repo.add_tag('tag_name', {:options => 'here'})
416
+ #
417
+ # Options:
418
+ # :a | :annotate -> true
419
+ # :d -> true
420
+ # :f -> true
421
+ # :m | :message -> String
422
+ # :s -> true
423
+ #
424
+ def add_tag(name, *opts)
425
+ self.lib.tag(name, *opts)
426
+ tag(name)
427
+ end
428
+
429
+ # deletes a tag
430
+ def delete_tag(name)
431
+ self.lib.tag(name, {:d => true})
412
432
  end
413
433
 
414
434
  # creates an archive file of the given tree-ish
@@ -93,10 +93,9 @@ module Git
93
93
  arr_opts += log_path_options(opts)
94
94
 
95
95
  full_log = command_lines('log', arr_opts, true)
96
- process_commit_data(full_log)
97
- end
98
-
99
96
 
97
+ process_commit_log_data(full_log)
98
+ end
100
99
 
101
100
  def revparse(string)
102
101
  return string if string =~ /[A-Fa-f0-9]{40}/ # passing in a sha - just no-op it
@@ -129,43 +128,66 @@ module Git
129
128
  end
130
129
 
131
130
  def process_commit_data(data, sha = nil, indent = 4)
131
+ hsh = {
132
+ 'sha' => sha,
133
+ 'message' => '',
134
+ 'parent' => []
135
+ }
136
+
137
+ loop do
138
+ key, *value = data.shift.split
139
+
140
+ break if key.nil?
141
+
142
+ if key == 'parent'
143
+ hsh['parent'] << value.join(' ')
144
+ else
145
+ hsh[key] = value.join(' ')
146
+ end
147
+ end
148
+
149
+ hsh['message'] = data.collect {|line| line[indent..-1]}.join("\n") + "\n"
150
+
151
+ return hsh
152
+ end
153
+
154
+ def process_commit_log_data(data)
132
155
  in_message = false
133
156
 
134
- if sha
135
- hsh = {'sha' => sha, 'message' => '', 'parent' => []}
136
- else
137
- hsh_array = []
138
- end
157
+ hsh_array = []
158
+
159
+ hsh = nil
139
160
 
140
161
  data.each do |line|
141
162
  line = line.chomp
142
- if line == ''
143
- in_message = !in_message
144
- elsif in_message
145
- hsh['message'] << line[indent..-1] << "\n"
146
- else
147
- data = line.split
148
- key = data.shift
149
- value = data.join(' ')
150
- if key == 'commit'
151
- sha = value
163
+
164
+ if line[0].nil?
165
+ in_message = !in_message
166
+ next
167
+ end
168
+
169
+ if in_message
170
+ hsh['message'] << "#{line[4..-1]}\n"
171
+ next
172
+ end
173
+
174
+ key, *value = line.split
175
+ value = value.join(' ')
176
+
177
+ case key
178
+ when 'commit'
152
179
  hsh_array << hsh if hsh
153
- hsh = {'sha' => sha, 'message' => '', 'parent' => []}
154
- end
155
- if key == 'parent'
156
- hsh[key] << value
180
+ hsh = {'sha' => value, 'message' => '', 'parent' => []}
181
+ when 'parent'
182
+ hsh['parent'] << value
157
183
  else
158
184
  hsh[key] = value
159
- end
160
185
  end
161
186
  end
162
187
 
163
- if hsh_array
164
- hsh_array << hsh if hsh
165
- hsh_array
166
- else
167
- hsh
168
- end
188
+ hsh_array << hsh if hsh
189
+
190
+ return hsh_array
169
191
  end
170
192
 
171
193
  def object_contents(sha, &block)
@@ -428,7 +450,8 @@ module Git
428
450
  arr_opts = []
429
451
  arr_opts << '--force' if opts[:force]
430
452
  arr_opts << '-d' if opts[:d]
431
-
453
+ arr_opts << '-x' if opts[:x]
454
+
432
455
  command('clean', arr_opts)
433
456
  end
434
457
 
@@ -561,23 +584,51 @@ module Git
561
584
  command_lines('tag')
562
585
  end
563
586
 
564
- def tag(tag)
565
- command('tag', tag)
587
+ def tag(name, *opts)
588
+ target = opts[0].instance_of?(String) ? opts[0] : nil
589
+
590
+ opts = opts.last.instance_of?(Hash) ? opts.last : {}
591
+
592
+ if (opts[:a] || opts[:annotate]) && !(opts[:m] || opts[:message])
593
+ raise "Can not create an [:a|:annotate] tag without the precense of [:m|:message]."
594
+ end
595
+
596
+ arr_opts = []
597
+
598
+ arr_opts << '-f' if opts[:force] || opts[:f]
599
+ arr_opts << '-a' if opts[:a] || opts[:annotate]
600
+ arr_opts << '-s' if opts[:s] || opts[:sign]
601
+ arr_opts << '-d' if opts[:d] || opts[:delete]
602
+ arr_opts << name
603
+ arr_opts << target if target
604
+ arr_opts << "-m #{opts[:m] || opts[:message]}" if opts[:m] || opts[:message]
605
+
606
+ command('tag', arr_opts)
566
607
  end
567
608
 
568
609
 
569
- def fetch(remote)
570
- command('fetch', remote)
610
+ def fetch(remote, opts)
611
+ arr_opts = [remote]
612
+ arr_opts << '--tags' if opts[:t] || opts[:tags]
613
+
614
+ command('fetch', arr_opts)
571
615
  end
572
616
 
573
- def push(remote, branch = 'master', tags = false)
574
- command('push', [remote, branch])
575
- command('push', ['--tags', remote]) if tags
617
+ def push(remote, branch = 'master', opts = {})
618
+ # Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
619
+ opts = {:tags => opts} if [true, false].include?(opts)
620
+
621
+ arr_opts = []
622
+ arr_opts << '--force' if opts[:force] || opts[:f]
623
+ arr_opts << remote
624
+
625
+ command('push', arr_opts + [branch])
626
+ command('push', ['--tags'] + arr_opts) if opts[:tags]
576
627
  end
577
628
 
578
- def pull(remote='origin', branch='master')
579
- command('pull', [remote, branch])
580
- end
629
+ def pull(remote='origin', branch='master')
630
+ command('pull', [remote, branch])
631
+ end
581
632
 
582
633
  def tag_sha(tag_name)
583
634
  head = File.join(@git_dir, 'refs', 'tags', tag_name)
@@ -668,17 +719,11 @@ module Git
668
719
  end
669
720
 
670
721
  def required_command_version
671
- [1, 6, 0, 0]
722
+ [1, 6]
672
723
  end
673
724
 
674
725
  def meets_required_version?
675
- current_version = self.current_command_version
676
- required_version = self.required_command_version
677
-
678
- return current_version[0] >= required_version[0] &&
679
- current_version[1] >= required_version[1] &&
680
- (current_version[2] ? current_version[2] >= required_version[2] : true) &&
681
- (current_version[3] ? current_version[3] >= required_version[3] : true)
726
+ (self.current_command_version <=> self.required_command_version) >= 0
682
727
  end
683
728
 
684
729
 
@@ -703,6 +748,7 @@ module Git
703
748
  if chdir && (Dir.getwd != path)
704
749
  Dir.chdir(path) { out = run_command(git_cmd, &block) }
705
750
  else
751
+
706
752
  out = run_command(git_cmd, &block)
707
753
  end
708
754
 
@@ -783,8 +829,7 @@ module Git
783
829
  end
784
830
 
785
831
  def escape(s)
786
- escaped = s.to_s.gsub('\'', '\'\\\'\'')
787
- %Q{"#{escaped}"}
832
+ "'#{s && s.to_s.gsub('\'','\'"\'"\'')}'"
788
833
  end
789
834
 
790
835
  end
@@ -94,12 +94,11 @@ module Git
94
94
 
95
95
  class Tree < AbstractObject
96
96
 
97
- @trees = nil
98
- @blobs = nil
99
-
100
97
  def initialize(base, sha, mode = nil)
101
98
  super(base, sha)
102
99
  @mode = mode
100
+ @trees = nil
101
+ @blobs = nil
103
102
  end
104
103
 
105
104
  def children
@@ -107,14 +106,12 @@ module Git
107
106
  end
108
107
 
109
108
  def blobs
110
- check_tree
111
- @blobs
109
+ @blobs ||= check_tree[:blobs]
112
110
  end
113
111
  alias_method :files, :blobs
114
112
 
115
113
  def trees
116
- check_tree
117
- @trees
114
+ @trees ||= check_tree[:trees]
118
115
  end
119
116
  alias_method :subtrees, :trees
120
117
  alias_method :subdirectories, :trees
@@ -135,13 +132,23 @@ module Git
135
132
 
136
133
  # actually run the git command
137
134
  def check_tree
138
- unless @trees
139
- @trees = {}
140
- @blobs = {}
141
- data = @base.lib.ls_tree(@objectish)
142
- data['tree'].each { |k, d| @trees[k] = Git::Object::Tree.new(@base, d[:sha], d[:mode]) }
143
- data['blob'].each { |k, d| @blobs[k] = Git::Object::Blob.new(@base, d[:sha], d[:mode]) }
135
+ @trees = {}
136
+ @blobs = {}
137
+
138
+ data = @base.lib.ls_tree(@objectish)
139
+
140
+ data['tree'].each do |key, tree|
141
+ @trees[key] = Git::Object::Tree.new(@base, tree[:sha], tree[:mode])
144
142
  end
143
+
144
+ data['blob'].each do |key, blob|
145
+ @blobs[key] = Git::Object::Blob.new(@base, blob[:sha], blob[:mode])
146
+ end
147
+
148
+ {
149
+ :trees => @trees,
150
+ :blobs => @blobs
151
+ }
145
152
  end
146
153
 
147
154
  end
@@ -11,8 +11,8 @@ module Git
11
11
  @fetch_opts = config['fetch']
12
12
  end
13
13
 
14
- def fetch
15
- @base.fetch(@name)
14
+ def fetch(opts={})
15
+ @base.fetch(@name, opts)
16
16
  end
17
17
 
18
18
  # merge this remote locally
@@ -27,17 +27,22 @@ module Git
27
27
  def pretty
28
28
  out = ''
29
29
  self.each do |file|
30
- out << file.path
31
- out << "\n\tsha(r) " + file.sha_repo.to_s + ' ' + file.mode_repo.to_s
32
- out << "\n\tsha(i) " + file.sha_index.to_s + ' ' + file.mode_index.to_s
33
- out << "\n\ttype " + file.type.to_s
34
- out << "\n\tstage " + file.stage.to_s
35
- out << "\n\tuntrac " + file.untracked.to_s
36
- out << "\n"
30
+ out << pretty_file(file)
37
31
  end
38
32
  out << "\n"
39
33
  out
40
34
  end
35
+
36
+ def pretty_file(file)
37
+ <<FILE
38
+ #{file.path}
39
+ \tsha(r) #{file.sha_repo.to_s} #{file.mode_repo.to_s}
40
+ \tsha(i) #{file.sha_index.to_s} #{file.mode_index.to_s}
41
+ \ttype #{file.type.to_s}
42
+ \tstage #{file.stage.to_s}
43
+ \tuntrac #{file.untracked.to_s}
44
+ FILE
45
+ end
41
46
 
42
47
  # enumerable method
43
48
 
@@ -85,8 +90,10 @@ module Git
85
90
 
86
91
  # find untracked in working dir
87
92
  Dir.chdir(@base.dir.path) do
88
- Dir.glob('**/*') do |file|
89
- @files[file] = {:path => file, :untracked => true} unless @files[file] || File.directory?(file) || ignore.include?(file)
93
+ Dir.glob('**/*', File::FNM_DOTMATCH) do |file|
94
+ next if @files[file] || File.directory?(file) || ignore.include?(file) || file =~ /^.git\/.+/
95
+
96
+ @files[file] = {:path => file, :untracked => true}
90
97
  end
91
98
  end
92
99
 
@@ -2,6 +2,6 @@ module Git
2
2
 
3
3
  # The current gem version
4
4
  # @return [String] the current gem version.
5
- VERSION='1.2.6'
5
+ VERSION='1.2.7'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-17 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description:
@@ -60,6 +60,7 @@ extra_rdoc_files:
60
60
  - README.md
61
61
  files:
62
62
  - LICENSE
63
+ - README.md
63
64
  - lib/git.rb
64
65
  - lib/git/author.rb
65
66
  - lib/git/base.rb
@@ -78,33 +79,31 @@ files:
78
79
  - lib/git/status.rb
79
80
  - lib/git/version.rb
80
81
  - lib/git/working_directory.rb
81
- - README.md
82
82
  homepage: http://github.com/schacon/ruby-git
83
83
  licenses:
84
84
  - MIT
85
85
  metadata: {}
86
86
  post_install_message:
87
87
  rdoc_options:
88
- - --charset=UTF-8
88
+ - "--charset=UTF-8"
89
89
  require_paths:
90
90
  - lib
91
91
  required_ruby_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - '>='
98
+ - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements:
102
102
  - git 1.6.0.0, or greater
103
103
  rubyforge_project:
104
- rubygems_version: 2.0.6
104
+ rubygems_version: 2.2.2
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: Ruby/Git is a Ruby library that can be used to create, read and manipulate
108
108
  Git repositories by wrapping system calls to the git binary.
109
109
  test_files: []
110
- has_rdoc: