lg_pod_plugin 1.0.8 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/bin/lg +5 -0
  3. data/lib/command/cache.rb +22 -18
  4. data/lib/command/command.rb +27 -35
  5. data/lib/command/install.rb +52 -0
  6. data/lib/command/update.rb +39 -0
  7. data/lib/lg_pod_plugin/downloader.rb +12 -17
  8. data/lib/lg_pod_plugin/git_util.rb +150 -106
  9. data/lib/lg_pod_plugin/install.rb +74 -88
  10. data/lib/lg_pod_plugin/l_cache.rb +11 -77
  11. data/lib/lg_pod_plugin/l_util.rb +6 -2
  12. data/lib/lg_pod_plugin/request.rb +90 -82
  13. data/lib/lg_pod_plugin/version.rb +1 -1
  14. data/lib/lg_pod_plugin.rb +9 -5
  15. metadata +57 -118
  16. data/lib/git/author.rb +0 -14
  17. data/lib/git/base/factory.rb +0 -101
  18. data/lib/git/base.rb +0 -670
  19. data/lib/git/branch.rb +0 -126
  20. data/lib/git/branches.rb +0 -71
  21. data/lib/git/config.rb +0 -22
  22. data/lib/git/diff.rb +0 -155
  23. data/lib/git/encoding_utils.rb +0 -33
  24. data/lib/git/escaped_path.rb +0 -77
  25. data/lib/git/index.rb +0 -5
  26. data/lib/git/lib.rb +0 -1215
  27. data/lib/git/log.rb +0 -135
  28. data/lib/git/object.rb +0 -312
  29. data/lib/git/path.rb +0 -31
  30. data/lib/git/remote.rb +0 -36
  31. data/lib/git/repository.rb +0 -6
  32. data/lib/git/stash.rb +0 -27
  33. data/lib/git/stashes.rb +0 -55
  34. data/lib/git/status.rb +0 -199
  35. data/lib/git/url.rb +0 -127
  36. data/lib/git/version.rb +0 -5
  37. data/lib/git/working_directory.rb +0 -4
  38. data/lib/git/worktree.rb +0 -38
  39. data/lib/git/worktrees.rb +0 -47
  40. data/lib/git.rb +0 -326
  41. data/lib/rchardet/big5freq.rb +0 -927
  42. data/lib/rchardet/big5prober.rb +0 -42
  43. data/lib/rchardet/chardistribution.rb +0 -250
  44. data/lib/rchardet/charsetgroupprober.rb +0 -110
  45. data/lib/rchardet/charsetprober.rb +0 -70
  46. data/lib/rchardet/codingstatemachine.rb +0 -67
  47. data/lib/rchardet/constants.rb +0 -42
  48. data/lib/rchardet/escprober.rb +0 -90
  49. data/lib/rchardet/escsm.rb +0 -245
  50. data/lib/rchardet/eucjpprober.rb +0 -88
  51. data/lib/rchardet/euckrfreq.rb +0 -597
  52. data/lib/rchardet/euckrprober.rb +0 -42
  53. data/lib/rchardet/euctwfreq.rb +0 -431
  54. data/lib/rchardet/euctwprober.rb +0 -42
  55. data/lib/rchardet/gb18030freq.rb +0 -474
  56. data/lib/rchardet/gb18030prober.rb +0 -42
  57. data/lib/rchardet/hebrewprober.rb +0 -289
  58. data/lib/rchardet/jisfreq.rb +0 -571
  59. data/lib/rchardet/jpcntx.rb +0 -229
  60. data/lib/rchardet/langbulgarianmodel.rb +0 -229
  61. data/lib/rchardet/langcyrillicmodel.rb +0 -330
  62. data/lib/rchardet/langgreekmodel.rb +0 -227
  63. data/lib/rchardet/langhebrewmodel.rb +0 -202
  64. data/lib/rchardet/langhungarianmodel.rb +0 -226
  65. data/lib/rchardet/langthaimodel.rb +0 -201
  66. data/lib/rchardet/latin1prober.rb +0 -147
  67. data/lib/rchardet/mbcharsetprober.rb +0 -89
  68. data/lib/rchardet/mbcsgroupprober.rb +0 -47
  69. data/lib/rchardet/mbcssm.rb +0 -542
  70. data/lib/rchardet/sbcharsetprober.rb +0 -122
  71. data/lib/rchardet/sbcsgroupprober.rb +0 -58
  72. data/lib/rchardet/sjisprober.rb +0 -88
  73. data/lib/rchardet/universaldetector.rb +0 -179
  74. data/lib/rchardet/utf8prober.rb +0 -87
  75. data/lib/rchardet/version.rb +0 -3
  76. data/lib/rchardet.rb +0 -67
  77. data/lib/zip/central_directory.rb +0 -212
  78. data/lib/zip/compressor.rb +0 -9
  79. data/lib/zip/constants.rb +0 -115
  80. data/lib/zip/crypto/decrypted_io.rb +0 -40
  81. data/lib/zip/crypto/encryption.rb +0 -11
  82. data/lib/zip/crypto/null_encryption.rb +0 -43
  83. data/lib/zip/crypto/traditional_encryption.rb +0 -99
  84. data/lib/zip/decompressor.rb +0 -31
  85. data/lib/zip/deflater.rb +0 -34
  86. data/lib/zip/dos_time.rb +0 -53
  87. data/lib/zip/entry.rb +0 -719
  88. data/lib/zip/entry_set.rb +0 -88
  89. data/lib/zip/errors.rb +0 -19
  90. data/lib/zip/extra_field/generic.rb +0 -44
  91. data/lib/zip/extra_field/ntfs.rb +0 -94
  92. data/lib/zip/extra_field/old_unix.rb +0 -46
  93. data/lib/zip/extra_field/universal_time.rb +0 -77
  94. data/lib/zip/extra_field/unix.rb +0 -39
  95. data/lib/zip/extra_field/zip64.rb +0 -70
  96. data/lib/zip/extra_field/zip64_placeholder.rb +0 -15
  97. data/lib/zip/extra_field.rb +0 -103
  98. data/lib/zip/file.rb +0 -468
  99. data/lib/zip/filesystem.rb +0 -643
  100. data/lib/zip/inflater.rb +0 -54
  101. data/lib/zip/input_stream.rb +0 -180
  102. data/lib/zip/ioextras/abstract_input_stream.rb +0 -122
  103. data/lib/zip/ioextras/abstract_output_stream.rb +0 -43
  104. data/lib/zip/ioextras.rb +0 -36
  105. data/lib/zip/null_compressor.rb +0 -15
  106. data/lib/zip/null_decompressor.rb +0 -19
  107. data/lib/zip/null_input_stream.rb +0 -10
  108. data/lib/zip/output_stream.rb +0 -198
  109. data/lib/zip/pass_thru_compressor.rb +0 -23
  110. data/lib/zip/pass_thru_decompressor.rb +0 -31
  111. data/lib/zip/streamable_directory.rb +0 -15
  112. data/lib/zip/streamable_stream.rb +0 -52
  113. data/lib/zip/version.rb +0 -3
  114. data/lib/zip.rb +0 -72
data/lib/git/base.rb DELETED
@@ -1,670 +0,0 @@
1
- require 'git/base/factory'
2
-
3
- module Git
4
- # Git::Base is the main public interface for interacting with Git commands.
5
- #
6
- # Instead of creating a Git::Base directly, obtain a Git::Base instance by
7
- # calling one of the follow {Git} class methods: {Git.open}, {Git.init},
8
- # {Git.clone}, or {Git.bare}.
9
- #
10
- class Base
11
- include Git::Base::Factory
12
-
13
- # (see Git.bare)
14
- def self.bare(git_dir, options = {})
15
- normalize_paths(options, default_repository: git_dir, bare: true)
16
- self.new(options)
17
- end
18
-
19
- # (see Git.clone)
20
- def self.clone(repository_url, directory, options = {})
21
- new_options = Git::Lib.new(nil, options[:log]).clone(repository_url, directory, options)
22
- normalize_paths(new_options, bare: options[:bare] || options[:mirror])
23
- new(new_options)
24
- end
25
-
26
- # Returns (and initialize if needed) a Git::Config instance
27
- #
28
- # @return [Git::Config] the current config instance.
29
- def self.config
30
- @@config ||= Config.new
31
- end
32
-
33
- # (see Git.init)
34
- def self.init(directory = '.', options = {})
35
- normalize_paths(options, default_working_directory: directory, default_repository: directory, bare: options[:bare])
36
-
37
- init_options = {
38
- :bare => options[:bare],
39
- :initial_branch => options[:initial_branch]
40
- }
41
-
42
- directory = options[:bare] ? options[:repository] : options[:working_directory]
43
- FileUtils.mkdir_p(directory) unless File.exist?(directory)
44
-
45
- # TODO: this dance seems awkward: this creates a Git::Lib so we can call
46
- # init so we can create a new Git::Base which in turn (ultimately)
47
- # creates another/different Git::Lib.
48
- #
49
- # TODO: maybe refactor so this Git::Bare.init does this:
50
- # self.new(opts).init(init_opts) and move all/some of this code into
51
- # Git::Bare#init. This way the init method can be called on any
52
- # repository you have a Git::Base instance for. This would not
53
- # change the existing interface (other than adding to it).
54
- #
55
- Git::Lib.new(options).init(init_options)
56
-
57
- self.new(options)
58
- end
59
-
60
- # (see Git.open)
61
- def self.open(working_dir, options = {})
62
- normalize_paths(options, default_working_directory: working_dir)
63
- self.new(options)
64
- end
65
-
66
- # Create an object that executes Git commands in the context of a working
67
- # copy or a bare repository.
68
- #
69
- # @param [Hash] options The options for this command (see list of valid
70
- # options below)
71
- #
72
- # @option options [Pathname] :working_dir the path to the root of the working
73
- # directory. Should be `nil` if executing commands on a bare repository.
74
- #
75
- # @option options [Pathname] :repository used to specify a non-standard path to
76
- # the repository directory. The default is `"#{working_dir}/.git"`.
77
- #
78
- # @option options [Pathname] :index used to specify a non-standard path to an
79
- # index file. The default is `"#{working_dir}/.git/index"`
80
- #
81
- # @option options [Logger] :log A logger to use for Git operations. Git
82
- # commands are logged at the `:info` level. Additional logging is done
83
- # at the `:debug` level.
84
- #
85
- # @return [Git::Base] an object that can execute git commands in the context
86
- # of the opened working copy or bare repository
87
- #
88
- def initialize(options = {})
89
- if working_dir = options[:working_directory]
90
- options[:repository] ||= File.join(working_dir, '.git')
91
- options[:index] ||= File.join(options[:repository], 'index')
92
- end
93
- if options[:log]
94
- @logger = options[:log]
95
- @logger.info("Starting Git")
96
- else
97
- @logger = nil
98
- end
99
-
100
- @working_directory = options[:working_directory] ? Git::WorkingDirectory.new(options[:working_directory]) : nil
101
- @repository = options[:repository] ? Git::Repository.new(options[:repository]) : nil
102
- @index = options[:index] ? Git::Index.new(options[:index], false) : nil
103
- end
104
-
105
- # changes current working directory for a block
106
- # to the git working directory
107
- #
108
- # example
109
- # @git.chdir do
110
- # # write files
111
- # @git.add
112
- # @git.commit('message')
113
- # end
114
- def chdir # :yields: the Git::Path
115
- Dir.chdir(dir.path) do
116
- yield dir.path
117
- end
118
- end
119
-
120
- #g.config('user.name', 'Scott Chacon') # sets value
121
- #g.config('user.email', 'email@email.com') # sets value
122
- #g.config('user.email', 'email@email.com', file: 'path/to/custom/config) # sets value in file
123
- #g.config('user.name') # returns 'Scott Chacon'
124
- #g.config # returns whole config hash
125
- def config(name = nil, value = nil, options = {})
126
- if name && value
127
- # set value
128
- lib.config_set(name, value, options)
129
- elsif name
130
- # return value
131
- lib.config_get(name)
132
- else
133
- # return hash
134
- lib.config_list
135
- end
136
- end
137
-
138
- # returns a reference to the working directory
139
- # @git.dir.path
140
- # @git.dir.writeable?
141
- def dir
142
- @working_directory
143
- end
144
-
145
- # returns reference to the git index file
146
- def index
147
- @index
148
- end
149
-
150
- # returns reference to the git repository directory
151
- # @git.dir.path
152
- def repo
153
- @repository
154
- end
155
-
156
- # returns the repository size in bytes
157
- def repo_size
158
- Dir.glob(File.join(repo.path, '**', '*'), File::FNM_DOTMATCH).reject do |f|
159
- f.include?('..')
160
- end.map do |f|
161
- File.expand_path(f)
162
- end.uniq.map do |f|
163
- File.stat(f).size.to_i
164
- end.reduce(:+)
165
- end
166
-
167
- def set_index(index_file, check = true)
168
- @lib = nil
169
- @index = Git::Index.new(index_file.to_s, check)
170
- end
171
-
172
- def set_working(work_dir, check = true)
173
- @lib = nil
174
- @working_directory = Git::WorkingDirectory.new(work_dir.to_s, check)
175
- end
176
-
177
- # returns +true+ if the branch exists locally
178
- def is_local_branch?(branch)
179
- branch_names = self.branches.local.map {|b| b.name}
180
- branch_names.include?(branch)
181
- end
182
-
183
- # returns +true+ if the branch exists remotely
184
- def is_remote_branch?(branch)
185
- branch_names = self.branches.remote.map {|b| b.name}
186
- branch_names.include?(branch)
187
- end
188
-
189
- # returns +true+ if the branch exists
190
- def is_branch?(branch)
191
- branch_names = self.branches.map {|b| b.name}
192
- branch_names.include?(branch)
193
- end
194
-
195
- # this is a convenience method for accessing the class that wraps all the
196
- # actual 'git' forked system calls. At some point I hope to replace the Git::Lib
197
- # class with one that uses native methods or libgit C bindings
198
- def lib
199
- @lib ||= Git::Lib.new(self, @logger)
200
- end
201
-
202
- # Run a grep for 'string' on the HEAD of the git repository
203
- #
204
- # @example Limit grep's scope by calling grep() from a specific object:
205
- # git.object("v2.3").grep('TODO')
206
- #
207
- # @example Using grep results:
208
- # git.grep("TODO").each do |sha, arr|
209
- # puts "in blob #{sha}:"
210
- # arr.each do |line_no, match_string|
211
- # puts "\t line #{line_no}: '#{match_string}'"
212
- # end
213
- # end
214
- #
215
- # @return [Hash<String, Array>] a hash of arrays
216
- # ```Ruby
217
- # {
218
- # 'tree-ish1' => [[line_no1, match_string1], ...],
219
- # 'tree-ish2' => [[line_no1, match_string1], ...],
220
- # ...
221
- # }
222
- # ```
223
- #
224
- def grep(string, path_limiter = nil, opts = {})
225
- self.object('HEAD').grep(string, path_limiter, opts)
226
- end
227
-
228
- # updates the repository index using the working directory content
229
- #
230
- # @example
231
- # git.add
232
- # git.add('path/to/file')
233
- # git.add(['path/to/file1','path/to/file2'])
234
- # git.add(:all => true)
235
- #
236
- # options:
237
- # :all => true
238
- #
239
- # @param [String,Array] paths files paths to be added (optional, default='.')
240
- # @param [Hash] options
241
- # @option options [boolean] :all
242
- # Update the index not only where the working tree has a file matching
243
- # <pathspec> but also where the index already has an entry.
244
- # See [the --all option to git-add](https://git-scm.com/docs/git-add#Documentation/git-add.txt--A)
245
- # for more details.
246
- #
247
- def add(paths = '.', **options)
248
- self.lib.add(paths, options)
249
- end
250
-
251
- # removes file(s) from the git repository
252
- def remove(path = '.', opts = {})
253
- self.lib.remove(path, opts)
254
- end
255
-
256
- # resets the working directory to the provided commitish
257
- def reset(commitish = nil, opts = {})
258
- self.lib.reset(commitish, opts)
259
- end
260
-
261
- # resets the working directory to the commitish with '--hard'
262
- def reset_hard(commitish = nil, opts = {})
263
- opts = {:hard => true}.merge(opts)
264
- self.lib.reset(commitish, opts)
265
- end
266
-
267
- # cleans the working directory
268
- #
269
- # options:
270
- # :force
271
- # :d
272
- # :ff
273
- #
274
- def clean(opts = {})
275
- self.lib.clean(opts)
276
- end
277
-
278
- # returns the most recent tag that is reachable from a commit
279
- #
280
- # options:
281
- # :all
282
- # :tags
283
- # :contains
284
- # :debug
285
- # :exact_match
286
- # :dirty
287
- # :abbrev
288
- # :candidates
289
- # :long
290
- # :always
291
- # :match
292
- #
293
- def describe(committish=nil, opts={})
294
- self.lib.describe(committish, opts)
295
- end
296
-
297
- # reverts the working directory to the provided commitish.
298
- # Accepts a range, such as comittish..HEAD
299
- #
300
- # options:
301
- # :no_edit
302
- #
303
- def revert(commitish = nil, opts = {})
304
- self.lib.revert(commitish, opts)
305
- end
306
-
307
- # commits all pending changes in the index file to the git repository
308
- #
309
- # options:
310
- # :all
311
- # :allow_empty
312
- # :amend
313
- # :author
314
- #
315
- def commit(message, opts = {})
316
- self.lib.commit(message, opts)
317
- end
318
-
319
- # commits all pending changes in the index file to the git repository,
320
- # but automatically adds all modified files without having to explicitly
321
- # calling @git.add() on them.
322
- def commit_all(message, opts = {})
323
- opts = {:add_all => true}.merge(opts)
324
- self.lib.commit(message, opts)
325
- end
326
-
327
- # checks out a branch as the new git working directory
328
- def checkout(branch = 'master', opts = {})
329
- self.lib.checkout(branch, opts)
330
- end
331
-
332
- # checks out an old version of a file
333
- def checkout_file(version, file)
334
- self.lib.checkout_file(version,file)
335
- end
336
-
337
- # fetches changes from a remote branch - this does not modify the working directory,
338
- # it just gets the changes from the remote if there are any
339
- def fetch(remote = 'origin', opts = {})
340
- if remote.is_a?(Hash)
341
- opts = remote
342
- remote = nil
343
- end
344
- self.lib.fetch(remote, opts)
345
- end
346
-
347
- # pushes changes to a remote repository - easiest if this is a cloned repository,
348
- # otherwise you may have to run something like this first to setup the push parameters:
349
- #
350
- # @git.config('remote.remote-name.push', 'refs/heads/master:refs/heads/master')
351
- #
352
- def push(remote = 'origin', branch = 'master', opts = {})
353
- # Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
354
- opts = {:tags => opts} if [true, false].include?(opts)
355
-
356
- self.lib.push(remote, branch, opts)
357
- end
358
-
359
- # merges one or more branches into the current working branch
360
- #
361
- # you can specify more than one branch to merge by passing an array of branches
362
- def merge(branch, message = 'merge', opts = {})
363
- self.lib.merge(branch, message, opts)
364
- end
365
-
366
- # iterates over the files which are unmerged
367
- def each_conflict(&block) # :yields: file, your_version, their_version
368
- self.lib.conflicts(&block)
369
- end
370
-
371
- # pulls the given branch from the given remote into the current branch
372
- #
373
- # @git.pull # pulls from origin/master
374
- # @git.pull('upstream') # pulls from upstream/master
375
- # @git.pull('upstream', 'develope') # pulls from upstream/develop
376
- #
377
- def pull(remote='origin', branch='master')
378
- self.lib.pull(remote, branch)
379
- end
380
-
381
- # returns an array of Git:Remote objects
382
- def remotes
383
- self.lib.remotes.map { |r| Git::Remote.new(self, r) }
384
- end
385
-
386
- # adds a new remote to this repository
387
- # url can be a git url or a Git::Base object if it's a local reference
388
- #
389
- # @git.add_remote('scotts_git', 'git://repo.or.cz/rubygit.git')
390
- # @git.fetch('scotts_git')
391
- # @git.merge('scotts_git/master')
392
- #
393
- # Options:
394
- # :fetch => true
395
- # :track => <branch_name>
396
- def add_remote(name, url, opts = {})
397
- url = url.repo.path if url.is_a?(Git::Base)
398
- self.lib.remote_add(name, url, opts)
399
- Git::Remote.new(self, name)
400
- end
401
-
402
- # sets the url for a remote
403
- # url can be a git url or a Git::Base object if it's a local reference
404
- #
405
- # @git.set_remote_url('scotts_git', 'git://repo.or.cz/rubygit.git')
406
- #
407
- def set_remote_url(name, url)
408
- url = url.repo.path if url.is_a?(Git::Base)
409
- self.lib.remote_set_url(name, url)
410
- Git::Remote.new(self, name)
411
- end
412
-
413
- # removes a remote from this repository
414
- #
415
- # @git.remove_remote('scott_git')
416
- def remove_remote(name)
417
- self.lib.remote_remove(name)
418
- end
419
-
420
- # returns an array of all Git::Tag objects for this repository
421
- def tags
422
- self.lib.tags.map { |r| tag(r) }
423
- end
424
-
425
- # Creates a new git tag (Git::Tag)
426
- #
427
- # @example
428
- # repo.add_tag('tag_name', object_reference)
429
- # repo.add_tag('tag_name', object_reference, {:options => 'here'})
430
- # repo.add_tag('tag_name', {:options => 'here'})
431
- #
432
- # @param [String] name The name of the tag to add
433
- # @param [Hash] options Opstions to pass to `git tag`.
434
- # See [git-tag](https://git-scm.com/docs/git-tag) for more details.
435
- # @option options [boolean] :annotate Make an unsigned, annotated tag object
436
- # @option options [boolean] :a An alias for the `:annotate` option
437
- # @option options [boolean] :d Delete existing tag with the given names.
438
- # @option options [boolean] :f Replace an existing tag with the given name (instead of failing)
439
- # @option options [String] :message Use the given tag message
440
- # @option options [String] :m An alias for the `:message` option
441
- # @option options [boolean] :s Make a GPG-signed tag.
442
- #
443
- def add_tag(name, *options)
444
- self.lib.tag(name, *options)
445
- self.tag(name)
446
- end
447
-
448
- # deletes a tag
449
- def delete_tag(name)
450
- self.lib.tag(name, {:d => true})
451
- end
452
-
453
- # creates an archive file of the given tree-ish
454
- def archive(treeish, file = nil, opts = {})
455
- self.object(treeish).archive(file, opts)
456
- end
457
-
458
- # repacks the repository
459
- def repack
460
- self.lib.repack
461
- end
462
-
463
- def gc
464
- self.lib.gc
465
- end
466
-
467
- def apply(file)
468
- if File.exist?(file)
469
- self.lib.apply(file)
470
- end
471
- end
472
-
473
- def apply_mail(file)
474
- self.lib.apply_mail(file) if File.exist?(file)
475
- end
476
-
477
- # Shows objects
478
- #
479
- # @param [String|NilClass] objectish the target object reference (nil == HEAD)
480
- # @param [String|NilClass] path the path of the file to be shown
481
- # @return [String] the object information
482
- def show(objectish=nil, path=nil)
483
- self.lib.show(objectish, path)
484
- end
485
-
486
- ## LOWER LEVEL INDEX OPERATIONS ##
487
-
488
- def with_index(new_index) # :yields: new_index
489
- old_index = @index
490
- set_index(new_index, false)
491
- return_value = yield @index
492
- set_index(old_index)
493
- return_value
494
- end
495
-
496
- def with_temp_index &blk
497
- # Workaround for JRUBY, since they handle the TempFile path different.
498
- # MUST be improved to be safer and OS independent.
499
- if RUBY_PLATFORM == 'java'
500
- temp_path = "/tmp/temp-index-#{(0...15).map{ ('a'..'z').to_a[rand(26)] }.join}"
501
- else
502
- tempfile = Tempfile.new('temp-index')
503
- temp_path = tempfile.path
504
- tempfile.close
505
- tempfile.unlink
506
- end
507
-
508
- with_index(temp_path, &blk)
509
- end
510
-
511
- def checkout_index(opts = {})
512
- self.lib.checkout_index(opts)
513
- end
514
-
515
- def read_tree(treeish, opts = {})
516
- self.lib.read_tree(treeish, opts)
517
- end
518
-
519
- def write_tree
520
- self.lib.write_tree
521
- end
522
-
523
- def write_and_commit_tree(opts = {})
524
- tree = write_tree
525
- commit_tree(tree, opts)
526
- end
527
-
528
- def update_ref(branch, commit)
529
- branch(branch).update_ref(commit)
530
- end
531
-
532
-
533
- def ls_files(location=nil)
534
- self.lib.ls_files(location)
535
- end
536
-
537
- def with_working(work_dir) # :yields: the Git::WorkingDirectory
538
- return_value = false
539
- old_working = @working_directory
540
- set_working(work_dir)
541
- Dir.chdir work_dir do
542
- return_value = yield @working_directory
543
- end
544
- set_working(old_working)
545
- return_value
546
- end
547
-
548
- def with_temp_working &blk
549
- tempfile = Tempfile.new("temp-workdir")
550
- temp_dir = tempfile.path
551
- tempfile.close
552
- tempfile.unlink
553
- Dir.mkdir(temp_dir, 0700)
554
- with_working(temp_dir, &blk)
555
- end
556
-
557
- # runs git rev-parse to convert the objectish to a full sha
558
- #
559
- # @example
560
- # git.revparse("HEAD^^")
561
- # git.revparse('v2.4^{tree}')
562
- # git.revparse('v2.4:/doc/index.html')
563
- #
564
- def revparse(objectish)
565
- self.lib.revparse(objectish)
566
- end
567
-
568
- def ls_tree(objectish)
569
- self.lib.ls_tree(objectish)
570
- end
571
-
572
- def cat_file(objectish)
573
- self.lib.object_contents(objectish)
574
- end
575
-
576
- # returns the name of the branch the working directory is currently on
577
- def current_branch
578
- self.lib.branch_current
579
- end
580
-
581
- private
582
-
583
- # Normalize options before they are sent to Git::Base.new
584
- #
585
- # Updates the options parameter by setting appropriate values for the following keys:
586
- # * options[:working_directory]
587
- # * options[:repository]
588
- # * options[:index]
589
- #
590
- # All three values will be set to absolute paths. An exception is that
591
- # :working_directory will be set to nil if bare is true.
592
- #
593
- private_class_method def self.normalize_paths(
594
- options, default_working_directory: nil, default_repository: nil, bare: false
595
- )
596
- normalize_working_directory(options, default: default_working_directory, bare: bare)
597
- normalize_repository(options, default: default_repository, bare: bare)
598
- normalize_index(options)
599
- end
600
-
601
- # Normalize options[:working_directory]
602
- #
603
- # If working with a bare repository, set to `nil`.
604
- # Otherwise, set to the first non-nil value of:
605
- # 1. `options[:working_directory]`,
606
- # 2. the `default` parameter, or
607
- # 3. the current working directory
608
- #
609
- # Finally, if options[:working_directory] is a relative path, convert it to an absoluite
610
- # path relative to the current directory.
611
- #
612
- private_class_method def self.normalize_working_directory(options, default:, bare: false)
613
- working_directory =
614
- if bare
615
- nil
616
- else
617
- File.expand_path(options[:working_directory] || default || Dir.pwd)
618
- end
619
-
620
- options[:working_directory] = working_directory
621
- end
622
-
623
- # Normalize options[:repository]
624
- #
625
- # If working with a bare repository, set to the first non-nil value out of:
626
- # 1. `options[:repository]`
627
- # 2. the `default` parameter
628
- # 3. the current working directory
629
- #
630
- # Otherwise, set to the first non-nil value of:
631
- # 1. `options[:repository]`
632
- # 2. `.git`
633
- #
634
- # Next, if options[:repository] refers to a *file* and not a *directory*, set
635
- # options[:repository] to the contents of that file. This is the case when
636
- # working with a submodule or a secondary working tree (created with git worktree
637
- # add). In these cases the repository is actually contained/nested within the
638
- # parent's repository directory.
639
- #
640
- # Finally, if options[:repository] is a relative path, convert it to an absolute
641
- # path relative to:
642
- # 1. the current directory if working with a bare repository or
643
- # 2. the working directory if NOT working with a bare repository
644
- #
645
- private_class_method def self.normalize_repository(options, default:, bare: false)
646
- repository =
647
- if bare
648
- File.expand_path(options[:repository] || default || Dir.pwd)
649
- else
650
- File.expand_path(options[:repository] || '.git', options[:working_directory])
651
- end
652
-
653
- if File.file?(repository)
654
- repository = File.expand_path(File.open(repository).read[8..-1].strip, options[:working_directory])
655
- end
656
-
657
- options[:repository] = repository
658
- end
659
-
660
- # Normalize options[:index]
661
- #
662
- # If options[:index] is a relative directory, convert it to an absolute
663
- # directory relative to the repository directory
664
- #
665
- private_class_method def self.normalize_index(options)
666
- index = File.expand_path(options[:index] || 'index', options[:repository])
667
- options[:index] = index
668
- end
669
- end
670
- end