Skip to content

Commit 52d80ac

Browse files
committed
fix: fix Rubocop Layout/LineLength offense
1 parent c010a86 commit 52d80ac

File tree

12 files changed

+138
-41
lines changed

12 files changed

+138
-41
lines changed

.rubocop.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ inherit_from: .rubocop_todo.yml
33
inherit_gem:
44
main_branch_shared_rubocop_config: config/rubocop.yml
55

6+
# Allow test data to have long lines
7+
Layout/LineLength:
8+
Exclude:
9+
- "tests/test_helper.rb"
10+
- "tests/units/**/*"
11+
- "*.gemspec"
12+
613
# Testing and gemspec DSL results in large blocks
714
Metrics/BlockLength:
815
Exclude:

.rubocop_todo.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 64
10-
# This cop supports safe autocorrection (--autocorrect).
11-
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
12-
# URISchemes: http, https
13-
Layout/LineLength:
14-
Max: 346
15-
169
# Offense count: 68
1710
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
1811
Metrics/AbcSize:

lib/git.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def self.clone(repository_url, directory = nil, options = {})
216216
# @example with the logging option
217217
# logger = Logger.new(STDOUT, level: Logger::INFO)
218218
# Git.default_branch('.', log: logger) # => 'master'
219-
# I, [2022-04-13T16:01:33.221596 #18415] INFO -- : git '-c' 'core.quotePath=true' '-c' 'color.ui=false' ls-remote '--symref' '--' '.' 'HEAD' 2>&1
219+
# I, [2022-04-13T16:01:33.221596 #18415] INFO -- : git '-c' 'core.quotePath=true'
220+
# '-c' 'color.ui=false' ls-remote '--symref' '--' '.' 'HEAD' 2>&1
220221
#
221222
# @param repository [URI, Pathname, String] The (possibly remote) repository to get the default branch name for
222223
#

lib/git/base.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ def self.root_of_worktree(working_dir)
9191
raise ArgumentError, "'#{working_dir}' does not exist" unless Dir.exist?(working_dir)
9292

9393
begin
94-
result, status = Open3.capture2e(Git::Base.config.binary_path, '-c', 'core.quotePath=true', '-c',
95-
'color.ui=false', 'rev-parse', '--show-toplevel', chdir: File.expand_path(working_dir))
94+
result, status = Open3.capture2e(
95+
Git::Base.config.binary_path, '-c', 'core.quotePath=true', '-c',
96+
'color.ui=false', 'rev-parse', '--show-toplevel', chdir: File.expand_path(working_dir)
97+
)
9698
result = result.chomp
9799
rescue Errno::ENOENT
98100
raise ArgumentError, 'Failed to find the root of the worktree: git binary not found'
@@ -242,7 +244,12 @@ def repo_size
242244
end
243245

244246
def set_index(index_file, check = nil, must_exist: nil)
245-
Git::Deprecation.warn('The "check" argument is deprecated and will be removed in a future version. Use "must_exist:" instead.') unless check.nil?
247+
unless check.nil?
248+
Git::Deprecation.warn(
249+
'The "check" argument is deprecated and will be removed in a future version. ' \
250+
'Use "must_exist:" instead.'
251+
)
252+
end
246253

247254
# default is true
248255
must_exist = must_exist.nil? && check.nil? ? true : must_exist | check
@@ -252,7 +259,12 @@ def set_index(index_file, check = nil, must_exist: nil)
252259
end
253260

254261
def set_working(work_dir, check = nil, must_exist: nil)
255-
Git::Deprecation.warn('The "check" argument is deprecated and will be removed in a future version. Use "must_exist:" instead.') unless check.nil?
262+
unless check.nil?
263+
Git::Deprecation.warn(
264+
'The "check" argument is deprecated and will be removed in a future version. ' \
265+
'Use "must_exist:" instead.'
266+
)
267+
end
256268

257269
# default is true
258270
must_exist = must_exist.nil? && check.nil? ? true : must_exist | check
@@ -874,7 +886,10 @@ def diff_path_status(objectish = 'HEAD', obj2 = nil)
874886
File.expand_path(options[:repository] || '.git', options[:working_directory])
875887
end
876888

877-
repository = File.expand_path(File.read(repository)[8..].strip, options[:working_directory]) if File.file?(repository)
889+
if File.file?(repository)
890+
repository = File.expand_path(File.read(repository)[8..].strip,
891+
options[:working_directory])
892+
end
878893

879894
options[:repository] = repository
880895
end

lib/git/branches.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def [](branch_name)
5151
branches[branch.full] ||= branch
5252

5353
# This is how Git (version 1.7.9.5) works.
54-
# Lets you ignore the 'remotes' if its at the beginning of the branch full name (even if is not a real remote branch).
54+
# Lets you ignore the 'remotes' if its at the beginning of the branch full
55+
# name (even if is not a real remote branch).
5556
branches[branch.full.sub('remotes/', '')] ||= branch if branch.full =~ %r{^remotes/.+}
5657
end[branch_name.to_s]
5758
end

lib/git/command_line.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,27 @@ def build_git_cmd(args)
252252
# Post process output, log the command and result, and raise an error if the
253253
# command failed.
254254
#
255-
# @param result [ProcessExecuter::Command::Result] the result it is a Process::Status and include command, stdout, and stderr
255+
# @param result [ProcessExecuter::Command::Result] the result it is a
256+
# Process::Status and include command, stdout, and stderr
257+
#
256258
# @param normalize [Boolean] whether to normalize the output of each writer
259+
#
257260
# @param chomp [Boolean] whether to chomp the output of each writer
258-
# @param timeout [Numeric, nil] the maximum seconds to wait for the command to complete
259261
#
260-
# @return [Git::CommandLineResult] the result of the command to return to the caller
262+
# @param timeout [Numeric, nil] the maximum seconds to wait for the command to
263+
# complete
264+
#
265+
# @return [Git::CommandLineResult] the result of the command to return to the
266+
# caller
261267
#
262268
# @raise [Git::FailedError] if the command failed
269+
#
263270
# @raise [Git::SignaledError] if the command was signaled
271+
#
264272
# @raise [Git::TimeoutError] if the command times out
265-
# @raise [Git::ProcessIOError] if an exception was raised while collecting subprocess output
273+
#
274+
# @raise [Git::ProcessIOError] if an exception was raised while collecting
275+
# subprocess output
266276
#
267277
# @api private
268278
#

lib/git/errors.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
module Git
4+
# rubocop:disable Layout/LineLength
5+
46
# Base class for all custom git module errors
57
#
68
# The git gem will only raise an `ArgumentError` or an error that is a subclass of
@@ -60,6 +62,8 @@ module Git
6062
#
6163
class Error < StandardError; end
6264

65+
# rubocop:enable Layout/LineLength
66+
6367
# An alias for Git::Error
6468
#
6569
# Git::GitExecuteError error class is an alias for Git::Error for backwards
@@ -155,7 +159,8 @@ class TimeoutError < Git::SignaledError
155159
# status = ProcessExecuter.spawn(*command, timeout: timeout_duration)
156160
# result = Git::CommandLineResult.new(command, status, 'stdout', 'err output')
157161
# error = Git::TimeoutError.new(result, timeout_duration)
158-
# error.error_message #=> '["sleep", "10"], status: pid 70144 SIGKILL (signal 9), stderr: "err output", timed out after 1s'
162+
# error.error_message
163+
# #=> '["sleep", "10"], status: pid 70144 SIGKILL (signal 9), stderr: "err output", timed out after 1s'
159164
#
160165
# @param result [Git::CommandLineResult] the result of the git command including
161166
# the git command, status, stdout, and stderr
@@ -171,7 +176,8 @@ def initialize(result, timeout_duration)
171176
# The human readable representation of this error
172177
#
173178
# @example
174-
# error.error_message #=> '["sleep", "10"], status: pid 88811 SIGKILL (signal 9), stderr: "err output", timed out after 1s'
179+
# error.error_message
180+
# #=> '["sleep", "10"], status: pid 88811 SIGKILL (signal 9), stderr: "err output", timed out after 1s'
175181
#
176182
# @return [String]
177183
#

lib/git/lib.rb

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def init(opts = {})
9696
# Clones a repository into a newly created directory
9797
#
9898
# @param [String] repository_url the URL of the repository to clone
99+
#
99100
# @param [String, nil] directory the directory to clone into
100101
#
101102
# If nil, the repository is cloned into a directory with the same name as
@@ -104,16 +105,28 @@ def init(opts = {})
104105
# @param [Hash] opts the options for this command
105106
#
106107
# @option opts [Boolean] :bare (false) if true, clone as a bare repository
108+
#
107109
# @option opts [String] :branch the branch to checkout
110+
#
108111
# @option opts [String, Array] :config one or more configuration options to set
112+
#
109113
# @option opts [Integer] :depth the number of commits back to pull
114+
#
110115
# @option opts [String] :filter specify partial clone
116+
#
111117
# @option opts [String] :mirror set up a mirror of the source repository
118+
#
112119
# @option opts [String] :origin the name of the remote
120+
#
113121
# @option opts [String] :path an optional prefix for the directory parameter
122+
#
114123
# @option opts [String] :remote the name of the remote
115-
# @option opts [Boolean] :recursive after the clone is created, initialize all submodules within, using their default settings
116-
# @option opts [Numeric, nil] :timeout the number of seconds to wait for the command to complete
124+
#
125+
# @option opts [Boolean] :recursive after the clone is created, initialize all
126+
# within, using their default settings
127+
#
128+
# @option opts [Numeric, nil] :timeout the number of seconds to wait for the
129+
# command to complete
117130
#
118131
# See {Git::Lib#command} for more information about :timeout
119132
#
@@ -268,37 +281,53 @@ def log_commits(opts = {})
268281
#
269282
# @param opts [Hash] the given options
270283
#
271-
# @option opts :count [Integer] the maximum number of commits to return (maps to max-count)
284+
# @option opts :count [Integer] the maximum number of commits to return (maps to
285+
# max-count)
286+
#
272287
# @option opts :all [Boolean]
288+
#
273289
# @option opts :cherry [Boolean]
290+
#
274291
# @option opts :since [String]
292+
#
275293
# @option opts :until [String]
294+
#
276295
# @option opts :grep [String]
296+
#
277297
# @option opts :author [String]
278-
# @option opts :between [Array<String>] an array of two commit-ish strings to specify a revision range
298+
#
299+
# @option opts :between [Array<String>] an array of two commit-ish strings to
300+
# specify a revision range
279301
#
280302
# Only :between or :object options can be used, not both.
281303
#
282304
# @option opts :object [String] the revision range for the git log command
283305
#
284306
# Only :between or :object options can be used, not both.
285307
#
286-
# @option opts :path_limiter [Array<String>, String] only include commits that impact files from the specified paths
308+
# @option opts :path_limiter [Array<String>, String] only include commits that
309+
# impact files from the specified paths
310+
#
287311
# @option opts :skip [Integer]
288312
#
289313
# @return [Array<Hash>] the log output parsed into an array of hashs for each commit
290314
#
291315
# Each hash contains the following keys:
316+
#
292317
# * 'sha' [String] the commit sha
293318
# * 'author' [String] the author of the commit
294319
# * 'message' [String] the commit message
295320
# * 'parent' [Array<String>] the commit shas of the parent commits
296321
# * 'tree' [String] the tree sha
297-
# * 'author' [String] the author of the commit and timestamp of when the changes were created
298-
# * 'committer' [String] the committer of the commit and timestamp of when the commit was applied
299-
# * 'merges' [Boolean] if truthy, only include merge commits (aka commits with 2 or more parents)
322+
# * 'author' [String] the author of the commit and timestamp of when the
323+
# changes were created
324+
# * 'committer' [String] the committer of the commit and timestamp of when the
325+
# commit was applied
326+
# * 'merges' [Boolean] if truthy, only include merge commits (aka commits with
327+
# 2 or more parents)
300328
#
301-
# @raise [ArgumentError] if the revision range (specified with :between or :object) is a string starting with a hyphen
329+
# @raise [ArgumentError] if the revision range (specified with :between or
330+
# :object) is a string starting with a hyphen
302331
#
303332
def full_log_commits(opts = {})
304333
assert_args_are_not_options('between', opts[:between]&.first)
@@ -321,7 +350,8 @@ def full_log_commits(opts = {})
321350
#
322351
# @see https://git-scm.com/docs/git-rev-parse git-rev-parse
323352
# @see https://git-scm.com/docs/git-rev-parse#_specifying_revisions Valid ways to specify revisions
324-
# @see https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt-emltrefnamegtemegemmasterememheadsmasterememrefsheadsmasterem Ref disambiguation rules
353+
# @see https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt-emltrefnamegtemegemmasterememheadsmasterememrefsheadsmasterem
354+
# Ref disambiguation rules
325355
#
326356
# @example
327357
# lib.rev_parse('HEAD') # => '9b9b31e704c0b85ffdd8d2af2ded85170a5af87d'
@@ -492,10 +522,12 @@ def each_cat_file_header(data)
492522

493523
# Return a hash of annotated tag data
494524
#
495-
# Does not work with lightweight tags. List all annotated tags in your repository with the following command:
525+
# Does not work with lightweight tags. List all annotated tags in your repository
526+
# with the following command:
496527
#
497528
# ```sh
498-
# git for-each-ref --format='%(refname:strip=2)' refs/tags | while read tag; do git cat-file tag $tag >/dev/null 2>&1 && echo $tag; done
529+
# git for-each-ref --format='%(refname:strip=2)' refs/tags | \
530+
# while read tag; do git cat-file tag $tag >/dev/null 2>&1 && echo $tag; done
499531
# ```
500532
#
501533
# @see https://git-scm.com/docs/git-cat-file git-cat-file
@@ -520,7 +552,8 @@ def each_cat_file_header(data)
520552
# * object [String] the sha of the tag object
521553
# * type [String]
522554
# * tag [String] tag name
523-
# * tagger [String] the name and email of the user who created the tag and the timestamp of when the tag was created
555+
# * tagger [String] the name and email of the user who created the tag
556+
# and the timestamp of when the tag was created
524557
# * message [String] the tag message
525558
#
526559
# @raise [ArgumentError] if object is a string starting with a hyphen
@@ -1300,7 +1333,10 @@ def tag(name, *opts)
13001333

13011334
opts = opts.last.instance_of?(Hash) ? opts.last : {}
13021335

1303-
raise ArgumentError, 'Cannot create an annotated tag without a message.' if (opts[:a] || opts[:annotate]) && !(opts[:m] || opts[:message])
1336+
if (opts[:a] || opts[:annotate]) && !(opts[:m] || opts[:message])
1337+
raise ArgumentError,
1338+
'Cannot create an annotated tag without a message.'
1339+
end
13041340

13051341
arr_opts = []
13061342

@@ -1518,7 +1554,10 @@ def self.warn_if_old_command(lib) # rubocop:disable Naming/PredicateMethod
15181554
return true if @version_checked
15191555

15201556
@version_checked = true
1521-
warn "[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." unless lib.meets_required_version?
1557+
unless lib.meets_required_version?
1558+
warn "[WARNING] The git gem requires git #{lib.required_command_version.join('.')} or later, " \
1559+
"but only found #{lib.current_command_version.join('.')}. You should probably upgrade."
1560+
end
15221561
true
15231562
end
15241563

@@ -1664,7 +1703,10 @@ def diff_as_hash(diff_command, opts = [])
16641703
def log_common_options(opts)
16651704
arr_opts = []
16661705

1667-
raise ArgumentError, "The log count option must be an Integer but was #{opts[:count].inspect}" if opts[:count] && !opts[:count].is_a?(Integer)
1706+
if opts[:count] && !opts[:count].is_a?(Integer)
1707+
raise ArgumentError,
1708+
"The log count option must be an Integer but was #{opts[:count].inspect}"
1709+
end
16681710

16691711
arr_opts << "--max-count=#{opts[:count]}" if opts[:count]
16701712
arr_opts << '--all' if opts[:all]

lib/git/log.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ def [](index)
264264
private
265265

266266
def deprecate_method(method_name)
267-
Git::Deprecation.warn("Calling Git::Log##{method_name} is deprecated and will be removed in a future version. Call #execute and then ##{method_name} on the result object.")
267+
Git::Deprecation.warn(
268+
"Calling Git::Log##{method_name} is deprecated and will be removed in a future version. " \
269+
"Call #execute and then ##{method_name} on the result object."
270+
)
268271
end
269272

270273
def dirty_log

lib/git/path.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ class Path
1010
attr_accessor :path
1111

1212
def initialize(path, check_path = nil, must_exist: nil)
13-
Git::Deprecation.warn('The "check_path" argument is deprecated and will be removed in a future version. Use "must_exist:" instead.') unless check_path.nil?
13+
unless check_path.nil?
14+
Git::Deprecation.warn(
15+
'The "check_path" argument is deprecated and ' \
16+
'will be removed in a future version. Use "must_exist:" instead.'
17+
)
18+
end
1419

1520
# default is true
1621
must_exist = must_exist.nil? && check_path.nil? ? true : must_exist || check_path

lib/git/stash.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ module Git
44
# A stash in a Git repository
55
class Stash
66
def initialize(base, message, existing = nil, save: nil)
7-
Git::Deprecation.warn('The "existing" argument is deprecated and will be removed in a future version. Use "save:" instead.') unless existing.nil?
7+
unless existing.nil?
8+
Git::Deprecation.warn(
9+
'The "existing" argument is deprecated and will be removed in a future version. Use "save:" instead.'
10+
)
11+
end
812

913
# default is false
1014
save = existing.nil? && save.nil? ? false : save | existing

0 commit comments

Comments
 (0)