rjgit 4.2.0.0 → 4.2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/lib/git.rb +92 -19
  3. data/lib/repo.rb +10 -2
  4. data/lib/tree.rb +5 -1
  5. data/lib/version.rb +1 -1
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d56351d6b926d22b1eebd8c8c958b638cb1aef80
4
- data.tar.gz: 6c5a3308f8fb57d5be9e80617835ab60f84a5ca6
3
+ metadata.gz: 738fc495773f62915e0f17f7266abd3de241ae7f
4
+ data.tar.gz: 9c7edfdc17e0439e98ecd254a184292ea0cde524
5
5
  SHA512:
6
- metadata.gz: 07703d7678e79653a27b6d6e605c056b45eb9181fbee56bfe098d889802af1e52a64611786f7c1c43da9e45fb9a2a722344d84aaaf7dd2860164ec2065345fe5
7
- data.tar.gz: 16fb0eab317a868eb2239e3194d93a8727ead62d8be8e34b7bb0381e9bf66197d37afb4806804f2357e8e83efd0e5eae6b75c93f7354070fd051e8a943ff81eb
6
+ metadata.gz: 3a6e9c6bc9db3594325b28eca28fd9f9ba00b3a0ee9f9932e8a50b3e45addb77df14418bdd15b56138c44d9e621fc6fa5c7361de54e25328f19422063ffbd304
7
+ data.tar.gz: f91fcfcd0749fa320bc736c480a1fef73e8daf68ab4dc421349fedca2a00cf72706143cbf9fa2858e00fce4356c47199cc5e6dde3208827235365ca5880d914b
data/lib/git.rb CHANGED
@@ -12,6 +12,9 @@ module RJGit
12
12
  import 'org.eclipse.jgit.diff.RenameDetector'
13
13
  import 'org.eclipse.jgit.diff.DiffEntry'
14
14
  import 'org.eclipse.jgit.treewalk.filter.PathFilter'
15
+ import 'org.eclipse.jgit.api.TransportConfigCallback'
16
+ import 'org.eclipse.jgit.transport.JschConfigSessionFactory'
17
+ import 'org.eclipse.jgit.transport.SshTransport'
15
18
 
16
19
  class RubyGit
17
20
 
@@ -19,6 +22,10 @@ module RJGit
19
22
  attr_accessor :jrepo
20
23
 
21
24
  RESET_MODES = ["HARD", "SOFT", "KEEP", "MERGE", "MIXED"]
25
+ SSH_TRANSPORTS = ["ssh"]
26
+ HTTP_TRANSPORTS = ["http", "https"]
27
+ FILE_TRANSPORTS = ["file"]
28
+ VALID_TRANSPORTS = SSH_TRANSPORTS + HTTP_TRANSPORTS + FILE_TRANSPORTS
22
29
 
23
30
  RJGit.delegate_to(Git, :@jgit)
24
31
 
@@ -34,14 +41,14 @@ module RJGit
34
41
  end
35
42
  logs
36
43
  end
37
-
44
+
38
45
  def log(path = nil, revstring = Constants::HEAD, options = {})
39
46
  ref = jrepo.resolve(revstring)
40
47
  return [] unless ref
41
48
  jcommits = Array.new
42
-
49
+
43
50
  if path && options[:follow]
44
- current_path = path
51
+ current_path = path
45
52
  start = nil
46
53
  loop do
47
54
  logs = @jgit.log.add(ref).addPath(current_path).call
@@ -53,8 +60,8 @@ module RJGit
53
60
  current_path = follow_renames(start, current_path) if start
54
61
  break if current_path.nil?
55
62
  end
56
-
57
- else
63
+
64
+ else
58
65
  logs = @jgit.log
59
66
  logs.add(ref)
60
67
  logs.addPath(path) if path
@@ -65,7 +72,7 @@ module RJGit
65
72
  revwalk = RevWalk.new(jrepo)
66
73
  since_commit = revwalk.parseCommit(jrepo.resolve(options[:since]))
67
74
  until_commit = revwalk.parseCommit(jrepo.resolve(options[:until]))
68
- logs.addRange(since_commit, until_commit)
75
+ logs.addRange(since_commit, until_commit)
69
76
  end
70
77
  if options[:not]
71
78
  revwalk = RevWalk.new(jrepo)
@@ -75,7 +82,7 @@ module RJGit
75
82
  end
76
83
  jcommits = logs.call
77
84
  end
78
-
85
+
79
86
  jcommits.map{ |jcommit| Commit.new(jrepo, jcommit) }
80
87
  end
81
88
 
@@ -127,6 +134,66 @@ module RJGit
127
134
  RubyGit.clone(remote, local, options)
128
135
  end
129
136
 
137
+ class RJGitSSHConfigCallback
138
+ include TransportConfigCallback
139
+ def initialize(options = {})
140
+ @sshSessionFactory = Class.new(JschConfigSessionFactory) {
141
+ def initialize(options)
142
+ super()
143
+ @private_key_file = options[:private_key_file]
144
+ @private_key_passphrase = options[:private_key_passphrase]
145
+ @username = options[:username]
146
+ @password = options[:password]
147
+ @known_hosts_file = options[:known_hosts_file]
148
+ end
149
+
150
+ def configure(host, session)
151
+ session.setUserName(@username) if @username
152
+ session.setPassword(@password) if @password
153
+ end
154
+
155
+ def createDefaultJSch(fs)
156
+ default_j_sch = super(fs)
157
+ if @private_key_file
158
+ default_j_sch.removeAllIdentity()
159
+ if @private_key_passphrase
160
+ default_j_sch.addIdentity(@private_key_file, @private_key_passphrase)
161
+ else
162
+ default_j_sch.addIdentity(@private_key_file)
163
+ end
164
+ end
165
+ if @known_hosts_file
166
+ default_j_sch.setKnownHosts(@known_hosts_file)
167
+ end
168
+
169
+ return default_j_sch
170
+ end
171
+ }.new(options)
172
+ end
173
+
174
+ def configure(ssh_transport)
175
+ ssh_transport.setSshSessionFactory(@sshSessionFactory)
176
+ end
177
+ end
178
+
179
+ def self.set_command_transport(command, remote, options = {})
180
+ uri = nil
181
+ begin
182
+ uri = URI.parse(remote) if remote
183
+ rescue URI::InvalidURIError
184
+ end
185
+
186
+ if uri && (VALID_TRANSPORTS.include? uri.scheme)
187
+ transport_protocol = uri.scheme
188
+ end
189
+
190
+ if (SSH_TRANSPORTS.include? transport_protocol.to_s) || (options[:transport_protocol] == :ssh) || options[:private_key_file]
191
+ command.set_transport_config_callback(RJGitSSHConfigCallback.new(options))
192
+ elsif (HTTP_TRANSPORTS.include? transport_protocol.to_s) || options[:username]
193
+ command.set_credentials_provider(UsernamePasswordCredentialsProvider.new(options[:username], options[:password]))
194
+ end
195
+ end
196
+
130
197
  def self.clone(remote, local, options = {})
131
198
  clone_command = Git.clone_repository
132
199
  clone_command.setURI(remote)
@@ -139,9 +206,8 @@ module RJGit
139
206
  clone_command.set_branch(options[:branch])
140
207
  end
141
208
  end
142
- if options[:username]
143
- clone_command.set_credentials_provider(UsernamePasswordCredentialsProvider.new(options[:username], options[:password]))
144
- end
209
+
210
+ set_command_transport(clone_command, remote, options)
145
211
  clone_command.call
146
212
  Repo.new(local)
147
213
  end
@@ -275,9 +341,8 @@ module RJGit
275
341
  push_command.set_remote(remote)
276
342
  push_command.set_push_all
277
343
  push_command.set_push_tags
278
- if options[:username]
279
- push_command.set_credentials_provider(UsernamePasswordCredentialsProvider.new(options[:username], options[:password]))
280
- end
344
+
345
+ self.class.set_command_transport(push_command, remote, options)
281
346
  push_command.call
282
347
  end
283
348
 
@@ -289,9 +354,7 @@ module RJGit
289
354
  refs.map!{|ref| RefSpec.new(ref)}
290
355
  push_command.set_ref_specs(refs)
291
356
  end
292
- if options[:username]
293
- push_command.set_credentials_provider(UsernamePasswordCredentialsProvider.new(options[:username], options[:password]))
294
- end
357
+ self.class.set_command_transport(push_command, remote, options)
295
358
  push_command.call
296
359
  end
297
360
 
@@ -301,11 +364,21 @@ module RJGit
301
364
  pull_command.set_rebase(options[:rebase]) if options[:rebase]
302
365
  pull_command.set_remote(remote) if remote
303
366
  pull_command.set_remote_branch_name(remote_ref) if remote_ref
304
- if options[:username]
305
- pull_command.set_credentials_provider(UsernamePasswordCredentialsProvider.new(options[:username], options[:password]))
306
- end
367
+ self.class.set_command_transport(pull_command, remote, options)
307
368
  pull_command.call
308
369
  end
309
370
 
371
+ def fetch(remote = nil, options = {})
372
+ fetch_command = @jgit.fetch
373
+ fetch_command.set_dry_run(true) if options[:dryrun]
374
+ fetch_command.set_thin(true) if options[:thin]
375
+ fetch_command.set_check_fetched_objects(true) if options[:check_fetched_objects]
376
+ fetch_command.set_remove_deleted_refs(true) if options[:remove_deleted_refs]
377
+ fetch_command.set_ref_specs(RefSpec.new(options[:refspecs])) if options[:refspecs]
378
+ fetch_command.set_remote(remote) if remote
379
+ self.class.set_command_transport(fetch_command, remote, options)
380
+ fetch_command.call
381
+ end
382
+
310
383
  end
311
384
  end
@@ -42,7 +42,15 @@ module RJGit
42
42
 
43
43
  def initialize(path, options = {})
44
44
  epath = File.expand_path(path)
45
- gitpath = File.join(epath, '.git')
45
+ if options[:git_dir]
46
+ if (Pathname.new options[:git_dir]).absolute?
47
+ gitpath = options[:git_dir]
48
+ else
49
+ gitpath = File.expand_path(options[:git_dir])
50
+ end
51
+ else
52
+ gitpath = File.join(epath, '.git')
53
+ end
46
54
 
47
55
  # Default value for bare
48
56
  bare = false
@@ -61,7 +69,7 @@ module RJGit
61
69
  @path = bare ? epath : gitpath
62
70
  @config = RJGit::Configuration.new(File.join(@path, 'config'))
63
71
  repo_path = java.io.File.new(@path)
64
- @jrepo = bare ? RepositoryBuilder.new().set_bare.set_git_dir(repo_path).build() : RepositoryBuilder.new().set_git_dir(repo_path).build()
72
+ @jrepo = bare ? RepositoryBuilder.new().set_bare.set_git_dir(repo_path).build() : RepositoryBuilder.new().set_git_dir(repo_path).set_work_tree(java.io.File.new(epath)).build()
65
73
  @jrepo.create(bare) if options[:create]
66
74
  @git = RubyGit.new(@jrepo)
67
75
  end
@@ -60,7 +60,11 @@ module RJGit
60
60
  end
61
61
 
62
62
  def /(file)
63
- treewalk = TreeWalk.forPath(@jrepo, file, @jtree)
63
+ begin
64
+ treewalk = TreeWalk.forPath(@jrepo, file, @jtree)
65
+ rescue Java::JavaLang::IllegalArgumentException
66
+ return self
67
+ end
64
68
  treewalk.nil? ? nil :
65
69
  wrap_tree_or_blob(treewalk.get_file_mode(0), treewalk.get_path_string, treewalk.get_object_id(0))
66
70
  end
@@ -1,3 +1,3 @@
1
1
  module RJGit
2
- VERSION = "4.2.0.0"
2
+ VERSION = "4.2.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0.0
4
+ version: 4.2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Engelen
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-01-25 00:00:00.000000000 Z
15
+ date: 2016-02-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: mime-types