git 1.3.0 → 1.4.0

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
- SHA1:
3
- metadata.gz: 57559d500d07f7561f8a62e21f87fb73b0759b98
4
- data.tar.gz: 4946775180b583063b68a9fa2ca507bbe2f3242f
2
+ SHA256:
3
+ metadata.gz: 892ebb66d9ea20f8ab3f3050b53b1b06bbfc25b732367ffc89d8b9abc0f9d960
4
+ data.tar.gz: a980be3464e4dcac4fed077a8fe72a120641a788f99947bedd7b4a0644255ab0
5
5
  SHA512:
6
- metadata.gz: a5f355d639e30163b6f56c0aacfc0bd5bb441dbfcf961b22b838a25dc8e2775afa8528e90f021b750c3431c9fdcce5795e04fd8b6b5eb2e271d32bfdeb26e3ce
7
- data.tar.gz: c49b547f7c47b6f0cc522ae4f0767c1f3a86817c45fb01f1d712bee8c9e1144075ab832e8eb863263bd55caad6a38b38b3c19c7059091abb7f7fe626fc6c92d1
6
+ metadata.gz: 280443c1f27cfe14b6ac5db700a28111943e76cee25ceef42d0d18fb6fa5cc536c6f5edf66057cc7b5e602c58e97c541f4f3d226306e80c004cdebad2d4448fa
7
+ data.tar.gz: e0824c1c2874240848147b57906c811e5f74ee3f8cfd7b5d11361cb35abc6ecf86cb33b61cacc3107ee46706c103259579bccfe68dd1eca252d4629d74871ce4
data/README.md CHANGED
@@ -6,7 +6,7 @@ Library for using Git in Ruby.
6
6
 
7
7
  Git public hosting of the project source code is at:
8
8
 
9
- http://github.com/schacon/ruby-git
9
+ http://github.com/ruby-git/ruby-git
10
10
 
11
11
  ## Install
12
12
 
@@ -16,10 +16,9 @@ You can install Ruby/Git like this:
16
16
 
17
17
  ## Code Status
18
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)
19
+ * [![Build Status](https://travis-ci.org/ruby-git/ruby-git.svg?branch=master)](https://travis-ci.org/ruby-git/ruby-git)
20
+ * [![Code Climate](https://codeclimate.com/github/ruby-git/ruby-git.png)](https://codeclimate.com/github/ruby-git/ruby-git)
21
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
22
 
24
23
  ## Major Objects
25
24
 
@@ -155,7 +154,7 @@ Here are the operations that need read permission only.
155
154
  g.show('HEAD')
156
155
  g.show('v2.8', 'README.md')
157
156
 
158
- Git.ls_remote('https://github.com/schacon/ruby-git.git') # returns a hash containing the available references of the repo.
157
+ Git.ls_remote('https://github.com/ruby-git/ruby-git.git') # returns a hash containing the available references of the repo.
159
158
  Git.ls_remote('/path/to/local/repo')
160
159
  Git.ls_remote() # same as Git.ls_remote('.')
161
160
 
@@ -372,6 +372,17 @@ module Git
372
372
  Git::Remote.new(self, name)
373
373
  end
374
374
 
375
+ # sets the url for a remote
376
+ # url can be a git url or a Git::Base object if it's a local reference
377
+ #
378
+ # @git.set_remote_url('scotts_git', 'git://repo.or.cz/rubygit.git')
379
+ #
380
+ def set_remote_url(name, url)
381
+ url = url.repo.path if url.is_a?(Git::Base)
382
+ self.lib.remote_set_url(name, url)
383
+ Git::Remote.new(self, name)
384
+ end
385
+
375
386
  # removes a remote from this repository
376
387
  #
377
388
  # @git.remove_remote('scott_git')
@@ -67,6 +67,7 @@ module Git
67
67
  arr_opts << '--config' << opts[:config] if opts[:config]
68
68
  arr_opts << '--origin' << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin]
69
69
  arr_opts << '--recursive' if opts[:recursive]
70
+ arr_opts << "--mirror" if opts[:mirror]
70
71
 
71
72
  arr_opts << '--'
72
73
 
@@ -75,7 +76,7 @@ module Git
75
76
 
76
77
  command('clone', arr_opts)
77
78
 
78
- opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir}
79
+ (opts[:bare] or opts[:mirror]) ? {:repository => clone_dir} : {:working_directory => clone_dir}
79
80
  end
80
81
 
81
82
 
@@ -396,6 +397,7 @@ module Git
396
397
  end
397
398
 
398
399
  def ls_files(location=nil)
400
+ location ||= '.'
399
401
  hsh = {}
400
402
  command_lines('ls-files', ['--stage', location]).each do |line|
401
403
  (info, file) = line.split("\t")
@@ -688,6 +690,14 @@ module Git
688
690
  command('remote', arr_opts)
689
691
  end
690
692
 
693
+ def remote_set_url(name, url)
694
+ arr_opts = ['set-url']
695
+ arr_opts << name
696
+ arr_opts << url
697
+
698
+ command('remote', arr_opts)
699
+ end
700
+
691
701
  def remote_remove(name)
692
702
  command('remote', ['rm', name])
693
703
  end
@@ -736,11 +746,16 @@ module Git
736
746
  opts = {:tags => opts} if [true, false].include?(opts)
737
747
 
738
748
  arr_opts = []
749
+ arr_opts << '--mirror' if opts[:mirror]
739
750
  arr_opts << '--force' if opts[:force] || opts[:f]
740
751
  arr_opts << remote
741
752
 
742
- command('push', arr_opts + [branch])
743
- command('push', ['--tags'] + arr_opts) if opts[:tags]
753
+ if opts[:mirror]
754
+ command('push', arr_opts)
755
+ else
756
+ command('push', arr_opts + [branch])
757
+ command('push', ['--tags'] + arr_opts) if opts[:tags]
758
+ end
744
759
  end
745
760
 
746
761
  def pull(remote='origin', branch='master')
@@ -859,10 +874,14 @@ module Git
859
874
 
860
875
  def command_lines(cmd, opts = [], chdir = true, redirect = '')
861
876
  cmd_op = command(cmd, opts, chdir)
862
- op = cmd_op.encode("UTF-8", "binary", {
863
- :invalid => :replace,
864
- :undef => :replace
865
- })
877
+ if cmd_op.encoding.name != "UTF-8"
878
+ op = cmd_op.encode("UTF-8", "binary", {
879
+ :invalid => :replace,
880
+ :undef => :replace
881
+ })
882
+ else
883
+ op = cmd_op
884
+ end
866
885
  op.split("\n")
867
886
  end
868
887
 
@@ -1,32 +1,102 @@
1
1
  module Git
2
-
2
+ #
3
+ # A class for git status
4
+ #
3
5
  class Status
4
6
  include Enumerable
5
-
7
+
6
8
  def initialize(base)
7
9
  @base = base
8
10
  construct_status
9
11
  end
10
-
12
+
13
+ #
14
+ # Returns an Enumerable containing files that have changed from the
15
+ # git base directory
16
+ #
17
+ # @return [Enumerable]
11
18
  def changed
12
- @files.select { |k, f| f.type == 'M' }
19
+ @files.select { |_k, f| f.type == 'M' }
13
20
  end
14
-
21
+
22
+ #
23
+ # Determines whether the given file has been changed.
24
+ # File path starts at git base directory
25
+ #
26
+ # @param file [String] The name of the file.
27
+ # @example Check if lib/git.rb has changed.
28
+ # changed?('lib/git.rb')
29
+ # @return [Boolean]
30
+ def changed?(file)
31
+ changed.member?(file)
32
+ end
33
+
34
+ #
35
+ # Returns an Enumerable containing files that have been added.
36
+ # File path starts at git base directory
37
+ #
38
+ # @return [Enumerable]
15
39
  def added
16
- @files.select { |k, f| f.type == 'A' }
40
+ @files.select { |_k, f| f.type == 'A' }
17
41
  end
18
42
 
43
+ #
44
+ # Determines whether the given file has been added to the repository
45
+ # File path starts at git base directory
46
+ #
47
+ # @param file [String] The name of the file.
48
+ # @example Check if lib/git.rb is added.
49
+ # added?('lib/git.rb')
50
+ # @return [Boolean]
51
+ def added?(file)
52
+ added.member?(file)
53
+ end
54
+
55
+ #
56
+ # Returns an Enumerable containing files that have been deleted.
57
+ # File path starts at git base directory
58
+ #
59
+ # @return [Enumerable]
19
60
  def deleted
20
- @files.select { |k, f| f.type == 'D' }
61
+ @files.select { |_k, f| f.type == 'D' }
21
62
  end
22
-
63
+
64
+ #
65
+ # Determines whether the given file has been deleted from the repository
66
+ # File path starts at git base directory
67
+ #
68
+ # @param file [String] The name of the file.
69
+ # @example Check if lib/git.rb is deleted.
70
+ # deleted?('lib/git.rb')
71
+ # @return [Boolean]
72
+ def deleted?(file)
73
+ deleted.member?(file)
74
+ end
75
+
76
+ #
77
+ # Returns an Enumerable containing files that are not tracked in git.
78
+ # File path starts at git base directory
79
+ #
80
+ # @return [Enumerable]
23
81
  def untracked
24
- @files.select { |k, f| f.untracked }
82
+ @files.select { |_k, f| f.untracked }
25
83
  end
26
-
84
+
85
+ #
86
+ # Determines whether the given file has is tracked by git.
87
+ # File path starts at git base directory
88
+ #
89
+ # @param file [String] The name of the file.
90
+ # @example Check if lib/git.rb is an untracked file.
91
+ # untracked?('lib/git.rb')
92
+ # @return [Boolean]
93
+ def untracked?(file)
94
+ untracked.member?(file)
95
+ end
96
+
27
97
  def pretty
28
98
  out = ''
29
- self.each do |file|
99
+ each do |file|
30
100
  out << pretty_file(file)
31
101
  end
32
102
  out << "\n"
@@ -34,26 +104,27 @@ module Git
34
104
  end
35
105
 
36
106
  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
46
-
107
+ <<-FILE.strip_heredoc
108
+ #{file.path}
109
+ \tsha(r) #{file.sha_repo} #{file.mode_repo}
110
+ \tsha(i) #{file.sha_index} #{file.mode_index}
111
+ \ttype #{file.type}
112
+ \tstage #{file.stage}
113
+ \tuntrac #{file.untracked}
114
+ FILE
115
+ end
116
+
47
117
  # enumerable method
48
-
118
+
49
119
  def [](file)
50
120
  @files[file]
51
121
  end
52
-
122
+
53
123
  def each(&block)
54
124
  @files.values.each(&block)
55
125
  end
56
-
126
+
127
+ # subclass that does heavy lifting
57
128
  class StatusFile
58
129
  attr_accessor :path, :type, :stage, :untracked
59
130
  attr_accessor :mode_index, :mode_repo
@@ -70,48 +141,59 @@ FILE
70
141
  @sha_repo = hash[:sha_repo]
71
142
  @untracked = hash[:untracked]
72
143
  end
73
-
144
+
74
145
  def blob(type = :index)
75
146
  if type == :repo
76
147
  @base.object(@sha_repo)
77
148
  else
78
- @base.object(@sha_index) rescue @base.object(@sha_repo)
149
+ begin
150
+ @base.object(@sha_index)
151
+ rescue
152
+ @base.object(@sha_repo)
153
+ end
79
154
  end
80
155
  end
81
-
82
-
83
156
  end
84
-
157
+
85
158
  private
86
-
87
- def construct_status
88
- @files = @base.lib.ls_files
89
- ignore = @base.lib.ignored_files
90
-
91
- # find untracked in working dir
92
- Dir.chdir(@base.dir.path) do
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}
97
- end
98
- end
99
-
100
- # find modified in tree
101
- @base.lib.diff_files.each do |path, data|
102
- @files[path] ? @files[path].merge!(data) : @files[path] = data
103
- end
104
-
105
- # find added but not committed - new files
106
- @base.lib.diff_index('HEAD').each do |path, data|
107
- @files[path] ? @files[path].merge!(data) : @files[path] = data
108
- end
109
-
110
- @files.each do |k, file_hash|
111
- @files[k] = StatusFile.new(@base, file_hash)
159
+
160
+ def construct_status
161
+ @files = @base.lib.ls_files
162
+
163
+ fetch_untracked
164
+ fetch_modified
165
+ fetch_added
166
+
167
+ @files.each do |k, file_hash|
168
+ @files[k] = StatusFile.new(@base, file_hash)
169
+ end
170
+ end
171
+
172
+ def fetch_untracked
173
+ ignore = @base.lib.ignored_files
174
+
175
+ Dir.chdir(@base.dir.path) do
176
+ Dir.glob('**/*', File::FNM_DOTMATCH) do |file|
177
+ next if @files[file] || File.directory?(file) ||
178
+ ignore.include?(file) || file =~ %r{^.git\/.+}
179
+
180
+ @files[file] = { path: file, untracked: true }
112
181
  end
113
182
  end
114
-
183
+ end
184
+
185
+ def fetch_modified
186
+ # find modified in tree
187
+ @base.lib.diff_files.each do |path, data|
188
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
189
+ end
190
+ end
191
+
192
+ def fetch_added
193
+ # find added but not committed - new files
194
+ @base.lib.diff_index('HEAD').each do |path, data|
195
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
196
+ end
197
+ end
115
198
  end
116
-
117
199
  end
@@ -1,7 +1,5 @@
1
1
  module Git
2
-
3
2
  # The current gem version
4
3
  # @return [String] the current gem version.
5
- VERSION='1.3.0'
6
-
4
+ VERSION='1.4.0'
7
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
- - Scott Chacon
7
+ - Scott Chacon and others
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-25 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -89,7 +89,7 @@ files:
89
89
  - lib/git/status.rb
90
90
  - lib/git/version.rb
91
91
  - lib/git/working_directory.rb
92
- homepage: http://github.com/schacon/ruby-git
92
+ homepage: http://github.com/ruby-git/ruby-git
93
93
  licenses:
94
94
  - MIT
95
95
  metadata: {}
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - git 1.6.0.0, or greater
113
113
  rubyforge_project:
114
- rubygems_version: 2.5.0
114
+ rubygems_version: 2.7.6
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Ruby/Git is a Ruby library that can be used to create, read and manipulate