diff --git a/.rubocop.yml b/.rubocop.yml index e229110..9fd7d19 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,822 +1,96 @@ -require: - - rubocop-rspec - -inherit_from: .rubocop_todo.yml - AllCops: - TargetRubyVersion: 2.1 - # Cop names are not d§splayed in offense messages by default. Change behavior - # by overriding DisplayCopNames, or by giving the -D/--display-cop-names - # option. - DisplayCopNames: true - # Style guide URLs are not displayed in offense messages by default. Change - # behavior by overriding DisplayStyleGuide, or by giving the - # -S/--display-style-guide option. - DisplayStyleGuide: false - # Exclude some GitLab files - Exclude: - - 'support/**/*' - -##################### Style ################################## - -# Check indentation of private/protected visibility modifiers. -Style/AccessModifierIndentation: - Enabled: true - -# Check the naming of accessor methods for get_/set_. -Style/AccessorMethodName: - Enabled: false - -# Use alias_method instead of alias. -Style/Alias: - EnforcedStyle: prefer_alias_method - Enabled: true - -# Align the elements of an array literal if they span more than one line. -Style/AlignArray: - Enabled: true - -# Align the elements of a hash literal if they span more than one line. -Style/AlignHash: - Enabled: true - -# Use `Array#join` instead of `Array#*`. -Style/ArrayJoin: - Enabled: true - -# Use only ascii symbols in comments. -Style/AsciiComments: - Enabled: true - -# Use only ascii symbols in identifiers. -Style/AsciiIdentifiers: - Enabled: true - -# Checks for uses of Module#attr. -Style/Attr: - Enabled: true - -# Avoid the use of BEGIN blocks. -Style/BeginBlock: - Enabled: true - -# Do not use block comments. -Style/BlockComments: - Enabled: true - -# Put end statement of multiline block on its own line. -Style/BlockEndNewline: - Enabled: true - -# Avoid using {...} for multi-line blocks (multiline chaining is # always -# ugly). Prefer {...} over do...end for single-line blocks. -Style/BlockDelimiters: - Enabled: true - -# Indentation of when in a case/when/[else/]end. -Style/CaseIndentation: - Enabled: true - -# Checks for uses of character literals. -Style/CharacterLiteral: - Enabled: true - -# Use CamelCase for classes and modules.' -Style/ClassAndModuleCamelCase: - Enabled: true - -# Checks style of children classes and modules. -Style/ClassAndModuleChildren: - Enabled: false - -# Enforces consistent use of `Object#is_a?` or `Object#kind_of?`. -Style/ClassCheck: - Enabled: false - -# Use self when defining module/class methods. -Style/ClassMethods: - Enabled: true - -# Avoid the use of class variables. -Style/ClassVars: - Enabled: true - -# Indentation of comments. -Style/CommentIndentation: - Enabled: true - -# Constants should use SCREAMING_SNAKE_CASE. -Style/ConstantName: - Enabled: true - -# Use def with parentheses when there are arguments. -Style/DefWithParentheses: - Enabled: true - -# Document classes and non-namespace modules. -Style/Documentation: - Enabled: false - -# Align elses and elsifs correctly. -Style/ElseAlignment: - Enabled: true - -# Use empty lines between defs. -Style/EmptyLineBetweenDefs: - Enabled: false - -# Don't use several empty lines in a row. -Style/EmptyLines: - Enabled: true - -# Keep blank lines around access modifiers. -Style/EmptyLinesAroundAccessModifier: - Enabled: true - -# Keeps track of empty lines around block bodies. -Style/EmptyLinesAroundBlockBody: - Enabled: true - -# Keeps track of empty lines around class bodies. -Style/EmptyLinesAroundClassBody: - Enabled: true - -# Keeps track of empty lines around module bodies. -Style/EmptyLinesAroundModuleBody: - Enabled: true - -# Keeps track of empty lines around method bodies. -Style/EmptyLinesAroundMethodBody: - Enabled: true - -# Avoid the use of END blocks. -Style/EndBlock: - Enabled: true - -# Use Unix-style line endings. -Style/EndOfLine: - Enabled: true - -# Favor the use of Fixnum#even? && Fixnum#odd? -Style/EvenOdd: - Enabled: true - -# Use snake_case for source file names. -Style/FileName: - Enabled: true - -# Checks for a line break before the first parameter in a multi-line method -# parameter definition. -Style/FirstMethodParameterLineBreak: - Enabled: true - -# Checks for flip flops. -Style/FlipFlop: - Enabled: true - -# Checks use of for or each in multiline loops. -Style/For: - Enabled: true - -# Checks if there is a magic comment to enforce string literals -Style/FrozenStringLiteralComment: - Enabled: false -# Do not introduce global variables. -Style/GlobalVars: - Enabled: true - -# Prefer Ruby 1.9 hash syntax `{ a: 1, b: 2 }` -# over 1.8 syntax `{ :a => 1, :b => 2 }`. -Style/HashSyntax: - Enabled: true - -# Do not use if x; .... Use the ternary operator instead. -Style/IfWithSemicolon: - Enabled: true - -# Checks that conditional statements do not have an identical line at the -# end of each branch, which can validly be moved out of the conditional. -Style/IdenticalConditionalBranches: - Enabled: true - -# Checks the indentation of the first line of the right-hand-side of a -# multi-line assignment. -Style/IndentAssignment: - Enabled: true - -# Keep indentation straight. -Style/IndentationConsistency: - Enabled: true - -# Use 2 spaces for indentation. -Style/IndentationWidth: - Enabled: true + TargetRubyVersion: 2.5 + TargetRailsVersion: 5.1 -# Use Kernel#loop for infinite loops. -Style/InfiniteLoop: - Enabled: true + CacheRootDirectory: /tmp + AllowSymlinksInCacheRootDirectory: true -# Use lambda.call(...) instead of lambda.(...). -Style/LambdaCall: - Enabled: true - -# Comments should start with a space. -Style/LeadingCommentSpace: - Enabled: true - -# Checks if the method definitions have or don't have parentheses. -Style/MethodDefParentheses: - Enabled: true - -# Use the configured style when naming methods. -Style/MethodName: - Enabled: true - -# Checks for usage of `extend self` in modules. -Style/ModuleFunction: - Enabled: false - -# Checks that the closing brace in an array literal is either on the same line -# as the last array element, or a new line. -Style/MultilineArrayBraceLayout: - Enabled: false - EnforcedStyle: symmetrical - -# Avoid multi-line chains of blocks. -Style/MultilineBlockChain: - Enabled: true - -# Ensures newlines after multiline block do statements. -Style/MultilineBlockLayout: - Enabled: true - -# Checks that the closing brace in a hash literal is either on the same line as -# the last hash element, or a new line. -Style/MultilineHashBraceLayout: - Enabled: false - EnforcedStyle: symmetrical - -# Do not use then for multi-line if/unless. -Style/MultilineIfThen: - Enabled: true - -# Checks that the closing brace in a method call is either on the same line as -# the last method argument, or a new line. -Style/MultilineMethodCallBraceLayout: - Enabled: false - EnforcedStyle: symmetrical - -# Checks indentation of method calls with the dot operator that span more than -# one line. -Style/MultilineMethodCallIndentation: - Enabled: false - -# Checks that the closing brace in a method definition is symmetrical with -# respect to the opening brace and the method parameters. -Style/MultilineMethodDefinitionBraceLayout: - Enabled: false - -# Checks indentation of binary operations that span more than one line. -Style/MultilineOperationIndentation: - Enabled: false - -# Avoid multi-line `? :` (the ternary operator), use if/unless instead. -Style/MultilineTernaryOperator: - Enabled: true - -# Favor unless over if for negative conditions (or control flow or). -Style/NegatedIf: - Enabled: true - -# Avoid using nested modifiers. -Style/NestedModifier: - Enabled: true - -# Use one expression per branch in a ternary operator. -Style/NestedTernaryOperator: - Enabled: true - -# Prefer x.nil? to x == nil. -Style/NilComparison: - Enabled: true - -# Checks for redundant nil checks. -Style/NonNilCheck: - Enabled: true - -# Use ! instead of not. -Style/Not: - Enabled: true - -# Add underscores to large numeric literals to improve their readability. -Style/NumericLiterals: - Enabled: false - -# Favor the ternary operator(?:) over if/then/else/end constructs. -Style/OneLineConditional: - Enabled: true - -# When defining binary operators, name the argument other. -Style/OpMethod: - Enabled: true - -# Don't use parentheses around the condition of an if/unless/while. -Style/ParenthesesAroundCondition: - Enabled: true - -# Checks for parentheses that seem not to serve any purpose. -Style/RedundantParentheses: - Enabled: true - -# Don't use return where it's not required. -Style/RedundantReturn: - Enabled: true - -# Don't use semicolons to terminate expressions. -Style/Semicolon: - Enabled: true - -# Checks for proper usage of fail and raise. -Style/SignalException: - EnforcedStyle: only_raise - Enabled: true - -# Use spaces after colons. -Style/SpaceAfterColon: - Enabled: true - -# Use spaces after commas. -Style/SpaceAfterComma: - Enabled: true - -# Do not put a space between a method name and the opening parenthesis in a -# method definition. -Style/SpaceAfterMethodName: - Enabled: true - -# Tracks redundant space after the ! operator. -Style/SpaceAfterNot: - Enabled: true - -# Use spaces after semicolons. -Style/SpaceAfterSemicolon: - Enabled: true - -# Use space around equals in parameter default -Style/SpaceAroundEqualsInParameterDefault: - Enabled: true - -# Use a space around keywords if appropriate. -Style/SpaceAroundKeyword: - Enabled: true - -# Use a single space around operators. -Style/SpaceAroundOperators: - Enabled: true - -# No spaces before commas. -Style/SpaceBeforeComma: - Enabled: true - -# Checks for missing space between code and a comment on the same line. -Style/SpaceBeforeComment: - Enabled: true - -# No spaces before semicolons. -Style/SpaceBeforeSemicolon: - Enabled: true - -# Use spaces inside hash literal braces - or don't. -Style/SpaceInsideHashLiteralBraces: - Enabled: true - -# No spaces inside range literals. -Style/SpaceInsideRangeLiteral: - Enabled: true - -# Checks for padding/surrounding spaces inside string interpolation. -Style/SpaceInsideStringInterpolation: + Exclude: + - 'apidoc/**/*' + - 'bin/bundle' + - 'bin/rails' + - 'bin/rake' + - 'bin/setup' + - 'bin/spring' + - 'bin/update' + - 'config/deploy/*.rb' + - 'config/mixins/applications/*.rb' + - 'data/**/*' + - 'db/schema.rb' + - 'node_modules/**/*' + - 'spec/dummy/**/*' + - 'vendor/**/*' + - 'repositories/**/*' + - 'repos/**/*' + - 'tmp/**/*' + +Layout/AlignParameters: + Enabled: false + +Layout/DotPosition: + EnforcedStyle: trailing + +Layout/MultilineMethodCallIndentation: + EnforcedStyle: indented + +Layout/SpaceInsideHashLiteralBraces: EnforcedStyle: no_space - Enabled: true - -# Avoid Perl-style global variables. -Style/SpecialGlobalVars: - Enabled: false - -# Check for the usage of parentheses around stabby lambda arguments. -Style/StabbyLambdaParentheses: - EnforcedStyle: require_parentheses - Enabled: true - -# Checks if uses of quotes match the configured preference. -Style/StringLiterals: - Enabled: false -# Checks if configured preferred methods are used over non-preferred. -Style/StringMethods: - PreferredMethods: - intern: to_sym - Enabled: true - -# No hard tabs. -Style/Tab: - Enabled: true - -# Checks trailing blank lines and final newline. -Style/TrailingBlankLines: - Enabled: true - -# Checks for %W when interpolation is not needed. -Style/UnneededCapitalW: - Enabled: true - -# Checks for %q/%Q when single quotes or double quotes would do. -Style/UnneededPercentQ: - Enabled: false - -# Don't interpolate global, instance and class variables directly in strings. -Style/VariableInterpolation: - Enabled: true - -# Use the configured style when naming variables. -Style/VariableName: - EnforcedStyle: snake_case - Enabled: true - -# Use the configured style when numbering variables. -Style/VariableNumber: - Enabled: false - -# Use when x then ... for one-line cases. -Style/WhenThen: - Enabled: true - -# Checks for redundant do after while or until. -Style/WhileUntilDo: - Enabled: true - -# Favor modifier while/until usage when you have a single-line body. -Style/WhileUntilModifier: - Enabled: true - -# Use %w or %W for arrays of words. -Style/WordArray: - Enabled: false - -#################### Metrics ################################ - -# A calculated magnitude based on number of assignments, -# branches, and conditions. -Metrics/AbcSize: - Enabled: true - Max: 60 - -# Avoid excessive block nesting. -Metrics/BlockNesting: - Enabled: true - Max: 4 - -# Avoid classes longer than 100 lines of code. -Metrics/ClassLength: - Enabled: false - -# A complexity metric that is strongly correlated to the number -# of test cases needed to validate a method. -Metrics/CyclomaticComplexity: - Enabled: true - Max: 17 +Metrics/BlockLength: + Exclude: + - 'app/graphql/**/*' + - 'config/routes.rb' + - 'config/environments/**/*' + - 'config/initializers/devise.rb' + - 'lib/tasks/**/*.rake' + - 'spec/**/*' + - 'db/migrate/*' + - '*.gemspec' -# Limit lines to 80 characters. Metrics/LineLength: - Enabled: false - -# Avoid methods longer than 10 lines of code. -Metrics/MethodLength: - Enabled: false - -# Avoid modules longer than 100 lines of code. -Metrics/ModuleLength: - Enabled: false - -# Avoid parameter lists longer than three or four parameters. -Metrics/ParameterLists: - Enabled: true - Max: 8 - -# A complexity metric geared towards measuring complexity for a human reader. -Metrics/PerceivedComplexity: - Enabled: true - Max: 18 - - -#################### Lint ################################ - -# Checks for useless access modifiers. -Lint/UselessAccessModifier: - Enabled: true - -# Checks for attempts to use `private` or `protected` to set the visibility -# of a class method, which does not work. -Lint/IneffectiveAccessModifier: - Enabled: false - -# Checks for ambiguous operators in the first argument of a method invocation -# without parentheses. -Lint/AmbiguousOperator: - Enabled: true - -# Align block ends correctly. -Lint/BlockAlignment: - Enabled: true - -# Default values in optional keyword arguments and optional ordinal arguments -# should not refer back to the name of the argument. -Lint/CircularArgumentReference: - Enabled: true - -# Checks for condition placed in a confusing position relative to the keyword. -Lint/ConditionPosition: - Enabled: true - -# Check for debugger calls. -Lint/Debugger: - Enabled: true - -# Align ends corresponding to defs correctly. -Lint/DefEndAlignment: - Enabled: true - -# Check for deprecated class method calls. -Lint/DeprecatedClassMethods: - Enabled: true - -# Check for immutable argument given to each_with_object. -Lint/EachWithObjectArgument: - Enabled: true - -# Check for odd code arrangement in an else block. -Lint/ElseLayout: - Enabled: true - -# Checks for empty ensure block. -Lint/EmptyEnsure: - Enabled: true - -# Align ends correctly. -Lint/EndAlignment: - Enabled: true - -# END blocks should not be placed inside method definitions. -Lint/EndInMethod: - Enabled: true - -# Do not use return in an ensure block. -Lint/EnsureReturn: - Enabled: true - -# The use of eval represents a serious security risk. -Lint/Eval: - Enabled: true - -# Catches floating-point literals too large or small for Ruby to represent. -Lint/FloatOutOfRange: - Enabled: true - -# The number of parameters to format/sprint must match the fields. -Lint/FormatParameterMismatch: - Enabled: true - -# Checks for adjacent string literals on the same line, which could better be -# represented as a single string literal. -Lint/ImplicitStringConcatenation: - Enabled: true - -# Checks for invalid character literals with a non-escaped whitespace -# character. -Lint/InvalidCharacterLiteral: - Enabled: true - -# Checks of literals used in conditions. -Lint/LiteralInCondition: - Enabled: true - -# Checks for literals used in interpolation. -Lint/LiteralInInterpolation: - Enabled: true - -# Do not use nested method definitions. -Lint/NestedMethodDefinition: - Enabled: true - -# Do not omit the accumulator when calling `next` in a `reduce`/`inject` block. -Lint/NextWithoutAccumulator: - Enabled: true - -# Checks for method calls with a space before the opening parenthesis. -Lint/ParenthesesAsGroupedExpression: - Enabled: true - -# Checks for `rand(1)` calls. Such calls always return `0` and most likely -# a mistake. -Lint/RandOne: - Enabled: true - -# Use parentheses in the method call to avoid confusion about precedence. -Lint/RequireParentheses: - Enabled: true - -# Avoid rescuing the Exception class. -Lint/RescueException: - Enabled: true - -# Checks for the order which exceptions are rescued to avoid rescueing a less specific exception before a more specific exception. -Lint/ShadowedException: - Enabled: false - -# Checks for Object#to_s usage in string interpolation. -Lint/StringConversionInInterpolation: - Enabled: true - -# Do not use prefix `_` for a variable that is used. -Lint/UnderscorePrefixedVariableName: - Enabled: true - -# Checks for rubocop:disable comments that can be removed. -# Note: this cop is not disabled when disabling all cops. -# It must be explicitly disabled. -Lint/UnneededDisable: - Enabled: false - -# Unreachable code. -Lint/UnreachableCode: - Enabled: true - -# Checks for useless assignment to a local variable. -Lint/UselessAssignment: - Enabled: true - -# Checks for comparison of something with itself. -Lint/UselessComparison: - Enabled: true - -# Checks for useless `else` in `begin..end` without `rescue`. -Lint/UselessElseWithoutRescue: - Enabled: true - -# Checks for useless setter call to a local variable. -Lint/UselessSetterCall: - Enabled: true - -# Possible use of operator/literal/variable in void context. -Lint/Void: - Enabled: true - - -##################### Performance ############################ - -# Use `casecmp` rather than `downcase ==`. -Performance/Casecmp: - Enabled: true - -# Use `str.{start,end}_with?(x, ..., y, ...)` instead of -# `str.{start,end}_with?(x, ...) || str.{start,end}_with?(y, ...)`. -Performance/DoubleStartEndWith: - Enabled: true - -# Use `strip` instead of `lstrip.rstrip`. -Performance/LstripRstrip: - Enabled: true - -# Use `Range#cover?` instead of `Range#include?`. -Performance/RangeInclude: - Enabled: true - -# Use `sort` instead of `sort_by { |x| x }`. -Performance/RedundantSortBy: - Enabled: true - -# Use `start_with?` instead of a regex match anchored to the beginning of a -# string. -Performance/StartWith: - Enabled: true - -# Use `tr` instead of `gsub` when you are replacing the same number of -# characters. Use `delete` instead of `gsub` when you are deleting -# characters. -Performance/StringReplacement: - Enabled: true - -# Checks for `.times.map` calls. -Performance/TimesMap: - Enabled: true - - -##################### Rails ################################## - -# Enables Rails cops. -Rails: - Enabled: true - -# Enforces consistent use of action filter methods. -Rails/ActionFilter: - Enabled: true - EnforcedStyle: action - -# Checks the correct usage of date aware methods, such as `Date.today`, -# `Date.current`, etc. -Rails/Date: - Enabled: false - -# Prefer delegate method for delegations. -Rails/Delegate: - Enabled: false - -# Prefer `find_by` over `where.first`. -Rails/FindBy: - Enabled: true - -# Prefer `all.find_each` over `all.find`. -Rails/FindEach: - Enabled: true - -# Prefer has_many :through to has_and_belongs_to_many. -Rails/HasAndBelongsToMany: - Enabled: true - -# Checks for calls to puts, print, etc. -Rails/Output: - Enabled: true - -# Checks for incorrect grammar when using methods like `3.day.ago`. -Rails/PluralizationGrammar: - Enabled: true - -# Checks for `read_attribute(:attr)` and `write_attribute(:attr, val)`. -Rails/ReadWriteAttribute: - Enabled: false - -# Checks the arguments of ActiveRecord scopes. -Rails/ScopeArgs: - Enabled: true - -##################### RSpec ################################## - -# Check that instances are not being stubbed globally. -RSpec/AnyInstance: - Enabled: false - -# Check that the first argument to the top level describe is the tested class or -# module. -RSpec/DescribeClass: - Enabled: false + Exclude: + - 'app/graphql/**/*_enum.rb' + - 'config/initializers/devise.rb' -# Use `described_class` for tested class / module. -RSpec/DescribeMethod: - Enabled: false +Naming/FileName: + Exclude: + - config/deploy/*.rb + - config/mixins/applications/*.rb + - lib/git-shell.rb + - lib/graphql-pundit.rb + - lib/hets-agent.rb + - lib/ontohub-models.rb + - spec/lib/git-shell_spec.rb -# Checks that the second argument to top level describe is the tested method -# name. -RSpec/DescribedClass: - Enabled: false +Style/Documentation: + Exclude: + - 'app/indexers/**/*' + - 'spec/**/*' -# Checks for long example. -RSpec/ExampleLength: +Style/DoubleNegation: Enabled: false - Max: 5 -# Do not use should when describing your tests. -RSpec/ExampleWording: +Style/FormatStringToken: Enabled: false - CustomTransform: - be: is - have: has - not: does not - IgnoredWords: [] -# Checks the file and folder naming of the spec file. -RSpec/FilePath: +Style/NumericLiterals: Enabled: false - CustomTransform: - RuboCop: rubocop - RSpec: rspec -# Checks if there are focused specs. -RSpec/Focus: - Enabled: true - -# Checks for the usage of instance variables. -RSpec/InstanceVariable: - Enabled: false +Style/PercentLiteralDelimiters: + PreferredDelimiters: + default: () + '%i': '()' + '%I': '()' + '%r': '{}' + '%w': '()' + '%W': '()' -# Checks for multiple top-level describes. -RSpec/MultipleDescribes: - Enabled: false +Style/SymbolArray: + Exclude: + - 'db/migrate/**' -# Enforces the usage of the same method on all negative message expectations. -RSpec/NotToNot: - EnforcedStyle: not_to - Enabled: true +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma -# Prefer using verifying doubles over normal doubles. -RSpec/VerifiedDoubles: - Enabled: false +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 11b34fa..0000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,526 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config --exclude-limit 0` -# on 2016-10-04 13:16:20 +0200 using RuboCop version 0.43.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 160 -Lint/AmbiguousRegexpLiteral: - Enabled: false - -# Offense count: 40 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Enabled: false - -# Offense count: 18 -Lint/HandleExceptions: - Enabled: false - -# Offense count: 2 -Lint/Loop: - Enabled: false - -# Offense count: 19 -Lint/ShadowingOuterLocalVariable: - Enabled: false - -# Offense count: 9 -# Cop supports --auto-correct. -Lint/UnifiedInteger: - Enabled: false - -# Offense count: 13 -# Cop supports --auto-correct. -Lint/UnneededSplatExpansion: - Enabled: false - -# Offense count: 69 -# Cop supports --auto-correct. -# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. -Lint/UnusedBlockArgument: - Enabled: false - -# Offense count: 144 -# Cop supports --auto-correct. -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. -Lint/UnusedMethodArgument: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Performance/RedundantBlockCall: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -Performance/RedundantMatch: - Enabled: false - -# Offense count: 26 -# Cop supports --auto-correct. -# Configuration parameters: MaxKeyValuePairs. -Performance/RedundantMerge: - Enabled: false - -# Offense count: 7 -RSpec/BeEql: - Enabled: false - -# Offense count: 20 -# Configuration parameters: CustomIncludeMethods. -RSpec/EmptyExampleGroup: - Enabled: false - -# Offense count: 16 -RSpec/ExpectActual: - Enabled: false - -# Offense count: 34 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: implicit, each, example -RSpec/HookArgument: - Enabled: false - -# Offense count: 168 -RSpec/LeadingSubject: - Enabled: false - -# Offense count: 162 -RSpec/LetSetup: - Enabled: false - -# Offense count: 10 -RSpec/MessageChain: - Enabled: false - -# Offense count: 714 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: allow, expect -RSpec/MessageExpectation: - Enabled: false - -# Offense count: 2423 -RSpec/MultipleExpectations: - Max: 36 - -# Offense count: 1504 -RSpec/NamedSubject: - Enabled: false - -# Offense count: 1335 -# Configuration parameters: MaxNesting. -RSpec/NestedGroups: - Enabled: false - -# Offense count: 99 -RSpec/SubjectStub: - Enabled: false - -# Offense count: 64 -Rails/OutputSafety: - Enabled: false - -# Offense count: 151 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: strict, flexible -Rails/TimeZone: - Enabled: false - -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/Validation: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Security/JSONLoad: - Enabled: false - -# Offense count: 284 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: with_first_parameter, with_fixed_indentation -Style/AlignParameters: - Enabled: false - -# Offense count: 28 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: always, conditionals -Style/AndOr: - Enabled: false - -# Offense count: 52 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: percent_q, bare_percent -Style/BarePercentLiterals: - Enabled: false - -# Offense count: 291 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Enabled: false - -# Offense count: 6 -Style/CaseEquality: - Enabled: false - -# Offense count: 26 -# Cop supports --auto-correct. -Style/ColonMethodCall: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: Keywords. -# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW -Style/CommentAnnotation: - Enabled: false - -# Offense count: 30 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Enabled: false - -# Offense count: 957 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: leading, trailing -Style/DotPosition: - Enabled: false - -# Offense count: 13 -Style/DoubleNegation: - Enabled: false - -# Offense count: 6 -# Cop supports --auto-correct. -Style/EachWithObject: - Enabled: false - -# Offense count: 26 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty, nil, both -Style/EmptyElse: - Enabled: false - -# Offense count: 3 -# Cop supports --auto-correct. -Style/EmptyLiteral: - Enabled: false - -# Offense count: 140 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. -Style/ExtraSpacing: - Enabled: false - -# Offense count: 6 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Enabled: false - -# Offense count: 201 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Enabled: false - -# Offense count: 11 -Style/IfInsideElse: - Enabled: false - -# Offense count: 174 -# Cop supports --auto-correct. -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Enabled: false - -# Offense count: 53 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Style/IndentArray: - Enabled: false - -# Offense count: 95 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Style/IndentHash: - Enabled: false - -# Offense count: 29 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -Style/LineEndConcatenation: - Enabled: false - -# Offense count: 15 -# Cop supports --auto-correct. -Style/MethodCallParentheses: - Enabled: false - -# Offense count: 8 -Style/MethodMissing: - Enabled: false - -# Offense count: 95 -# Cop supports --auto-correct. -Style/MutableConstant: - Enabled: false - -# Offense count: 8 -# Cop supports --auto-correct. -Style/NestedParenthesizedCalls: - Enabled: false - -# Offense count: 13 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. -# SupportedStyles: skip_modifier_ifs, always -Style/Next: - Enabled: false - -# Offense count: 12 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles. -# SupportedOctalStyles: zero_with_o, zero_only -Style/NumericLiteralPrefix: - Enabled: false - -# Offense count: 53 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: predicate, comparison -Style/NumericPredicate: - Enabled: false - -# Offense count: 29 -# Cop supports --auto-correct. -Style/ParallelAssignment: - Enabled: false - -# Offense count: 294 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Enabled: false - -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: lower_case_q, upper_case_q -Style/PercentQLiterals: - Enabled: false - -# Offense count: 13 -# Cop supports --auto-correct. -Style/PerlBackrefs: - Enabled: false - -# Offense count: 38 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. -# NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? -Style/PredicateName: - Enabled: false - -# Offense count: 26 -# Cop supports --auto-correct. -Style/PreferredHashMethods: - Enabled: false - -# Offense count: 6 -# Cop supports --auto-correct. -Style/Proc: - Enabled: false - -# Offense count: 22 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: compact, exploded -Style/RaiseArgs: - Enabled: false - -# Offense count: 4 -# Cop supports --auto-correct. -Style/RedundantBegin: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantException: - Enabled: false - -# Offense count: 24 -# Cop supports --auto-correct. -Style/RedundantFreeze: - Enabled: false - -# Offense count: 427 -# Cop supports --auto-correct. -Style/RedundantSelf: - Enabled: false - -# Offense count: 97 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Enabled: false - -# Offense count: 18 -# Cop supports --auto-correct. -Style/RescueModifier: - Enabled: false - -# Offense count: 114 -# Cop supports --auto-correct. -Style/SafeNavigation: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -Style/SelfAssignment: - Enabled: false - -# Offense count: 2 -# Configuration parameters: Methods. -# Methods: {"reduce"=>["a", "e"]}, {"inject"=>["a", "e"]} -Style/SingleLineBlockParams: - Enabled: false - -# Offense count: 50 -# Cop supports --auto-correct. -# Configuration parameters: AllowIfMethodIsEmpty. -Style/SingleLineMethods: - Enabled: false - -# Offense count: 125 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: space, no_space -Style/SpaceBeforeBlockBraces: - Enabled: false - -# Offense count: 10 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Style/SpaceBeforeFirstArg: - Enabled: false - -# Offense count: 145 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -Style/SpaceInsideBlockBraces: - Enabled: false - -# Offense count: 99 -# Cop supports --auto-correct. -Style/SpaceInsideBrackets: - Enabled: false - -# Offense count: 65 -# Cop supports --auto-correct. -Style/SpaceInsideParens: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -Style/SpaceInsidePercentLiteralDelimiters: - Enabled: false - -# Offense count: 41 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles. -# SupportedStyles: use_perl_names, use_english_names -Style/SpecialGlobalVars: - EnforcedStyle: use_perl_names - -# Offense count: 31 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiteralsInInterpolation: - Enabled: false - -# Offense count: 33 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to, define_method -Style/SymbolProc: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment. -# SupportedStyles: require_parentheses, require_no_parentheses -Style/TernaryParentheses: - Enabled: false - -# Offense count: 29 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. -# SupportedStyles: comma, consistent_comma, no_comma -Style/TrailingCommaInArguments: - Enabled: false - -# Offense count: 102 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. -# SupportedStyles: comma, consistent_comma, no_comma -Style/TrailingCommaInLiteral: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: AllowNamedUnderscoreVariables. -Style/TrailingUnderscoreVariable: - Enabled: false - -# Offense count: 76 -# Cop supports --auto-correct. -Style/TrailingWhitespace: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist. -# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym -Style/TrivialAccessors: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Style/UnlessElse: - Enabled: false - -# Offense count: 14 -# Cop supports --auto-correct. -Style/UnneededInterpolation: - Enabled: false - -# Offense count: 8 -# Cop supports --auto-correct. -Style/ZeroLengthPredicate: - Enabled: false diff --git a/Appraisals b/Appraisals index 9213c32..b33957c 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,9 @@ -appraise "rails-42" do - gem "activesupport", "~> 4.2.7" +# frozen_string_literal: true + +appraise 'rails-42' do + gem 'activesupport', '~> 4.2.7' end -appraise "rails-50" do - gem "activesupport", "~> 5.0.0" +appraise 'rails-50' do + gem 'activesupport', '~> 5.0.0' end diff --git a/Gemfile.lock b/Gemfile.lock index b2b3b1a..03af646 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,7 +19,7 @@ GEM bundler rake thor (>= 0.14.0) - ast (2.3.0) + ast (2.4.0) binding_of_caller (0.7.3) debug_inspector (>= 0.0.1) bundler-audit (0.6.0) @@ -59,8 +59,8 @@ GEM mime-types-data (3.2016.0521) minitest (5.11.3) parallel (1.12.1) - parser (2.4.0.2) - ast (~> 2.3) + parser (2.5.0.3) + ast (~> 2.4.0) powerpack (0.1.1) pry (0.11.3) coderay (~> 1.1.0) @@ -89,13 +89,15 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.7.0) rspec-support (3.7.0) - rubocop (0.52.1) + rubocop (0.53.0) parallel (~> 1.10) - parser (>= 2.4.0.2, < 3.0) + parser (>= 2.5) powerpack (~> 0.1) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) + rubocop-rspec (1.24.0) + rubocop (>= 0.53.0) ruby-progressbar (1.9.0) rugged (0.26.0) simplecov (0.15.1) @@ -128,7 +130,8 @@ DEPENDENCIES pry-stack_explorer (~> 0.4.9.2) rake (~> 12.0) rspec (~> 3.7) - rubocop (~> 0.52.1) + rubocop (~> 0.53.0) + rubocop-rspec (~> 1.24.0) simplecov (~> 0.15.1) BUNDLED WITH diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index e37dfaa..508096f --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,6 @@ #!/usr/bin/env rake -require "rubygems" -require "bundler/setup" -require "bundler/gem_tasks" +# frozen_string_literal: true + +require 'rubygems' +require 'bundler/setup' +require 'bundler/gem_tasks' diff --git a/bringit.gemspec b/bringit.gemspec index 82c46d1..1ec62f3 100644 --- a/bringit.gemspec +++ b/bringit.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -$LOAD_PATH.push File.expand_path('../lib', __FILE__) +$LOAD_PATH.push File.expand_path('lib', __dir__) # Maintain your gem's version: require 'bringit/version' @@ -8,9 +8,9 @@ require 'bringit/version' Gem::Specification.new do |s| s.name = 'bringit' s.version = Bringit::VERSION - s.date = Time.now.strftime("%Y-%m-%d") - s.summary = "Bringit library" - s.description = "Bringit wrapper around git objects" + s.date = Time.now.strftime('%Y-%m-%d') + s.summary = 'Bringit library' + s.description = 'Bringit wrapper around git objects' s.authors = ['Ontohub Core Developers', 'Dmitriy Zaporozhets'] s.email = ['ontohub-dev-l@ovgu.de', 'dmitriy.zaporozhets@gmail.com'] s.license = 'MIT' @@ -18,10 +18,10 @@ Gem::Specification.new do |s| s.homepage = 'https://github.com/ontohub/bringit' - s.add_dependency('github-linguist', '>= 5.1', '< 5.4') s.add_dependency('activesupport', '>= 4.0') - s.add_dependency('rugged', '~> 0.26.0') s.add_dependency('charlock_holmes', '~> 0.7.3') + s.add_dependency('github-linguist', '>= 5.1', '< 5.4') + s.add_dependency('rugged', '~> 0.26.0') s.add_development_dependency 'appraisal' s.add_development_dependency 'bundler', '~> 1.14' @@ -36,6 +36,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'pry-stack_explorer', '~> 0.4.9.2' s.add_development_dependency 'rake', '~> 12.0' s.add_development_dependency 'rspec', '~> 3.7' - s.add_development_dependency 'rubocop', '~> 0.52.1' + s.add_development_dependency 'rubocop', '~> 0.53.0' + s.add_development_dependency 'rubocop-rspec', '~> 1.24.0' s.add_development_dependency 'simplecov', '~> 0.15.1' end diff --git a/gemfiles/rails_42.gemfile b/gemfiles/rails_42.gemfile index 145112a..009587b 100644 --- a/gemfiles/rails_42.gemfile +++ b/gemfiles/rails_42.gemfile @@ -1,24 +1,26 @@ +# frozen_string_literal: true + # This file was generated by Appraisal -source "https://rubygems.org" +source 'https://rubygems.org' -gem "activesupport", "~> 4.2.7" +gem 'activesupport', '~> 4.2.7' group :development do - gem "rubocop", '~> 0.43.0' - gem "rubocop-rspec", '~> 1.8.0' - gem "rspec", "~> 3.5.0" - gem "pry" - gem "rake" + gem 'pry' + gem 'rake' + gem 'rspec', '~> 3.5.0' + gem 'rubocop', '~> 0.43.0' + gem 'rubocop-rspec', '~> 1.8.0' end group :test do - gem "simplecov", :require => false + gem 'simplecov', require: false end group :development, :test do - gem "bundler-audit", "~> 0.5.0", :require => false - gem "appraisal" + gem 'appraisal' + gem 'bundler-audit', '~> 0.5.0', require: false end -gemspec :path => "../" +gemspec path: '../' diff --git a/gemfiles/rails_50.gemfile b/gemfiles/rails_50.gemfile index 6929bf4..dd01a37 100644 --- a/gemfiles/rails_50.gemfile +++ b/gemfiles/rails_50.gemfile @@ -1,24 +1,26 @@ +# frozen_string_literal: true + # This file was generated by Appraisal -source "https://rubygems.org" +source 'https://rubygems.org' -gem "activesupport", "~> 5.0.0" +gem 'activesupport', '~> 5.0.0' group :development do - gem "rubocop", '~> 0.43.0' - gem "rubocop-rspec", '~> 1.8.0' - gem "rspec", "~> 3.5.0" - gem "pry" - gem "rake" + gem 'pry' + gem 'rake' + gem 'rspec', '~> 3.5.0' + gem 'rubocop', '~> 0.43.0' + gem 'rubocop-rspec', '~> 1.8.0' end group :test do - gem "simplecov", :require => false + gem 'simplecov', require: false end group :development, :test do - gem "bundler-audit", "~> 0.5.0", :require => false - gem "appraisal" + gem 'appraisal' + gem 'bundler-audit', '~> 0.5.0', require: false end -gemspec :path => "../" +gemspec path: '../' diff --git a/lib/bringit.rb b/lib/bringit.rb index 9c23f14..4b871f0 100644 --- a/lib/bringit.rb +++ b/lib/bringit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Libraries require 'ostruct' require 'fileutils' @@ -9,40 +11,40 @@ require 'active_support/core_ext/object/try' require 'active_support/core_ext/module/delegation' require 'rugged' -require "charlock_holmes" +require 'charlock_holmes' # Bringit -require_relative "bringit/popen" +require_relative 'bringit/popen' require_relative 'bringit/encoding_helper' require_relative 'bringit/path_helper' -require_relative "bringit/blame" -require_relative "bringit/blob" -require_relative "bringit/commit" -require_relative "bringit/commit_stats" -require_relative "bringit/compare" -require_relative "bringit/diff" -require_relative "bringit/diff_collection" -require_relative "bringit/hook" -require_relative "bringit/index" -require_relative "bringit/rev_list" -require_relative "bringit/repository" -require_relative "bringit/tree" -require_relative "bringit/blob_snippet" -require_relative "bringit/ref" -require_relative "bringit/branch" -require_relative "bringit/tag" -require_relative "bringit/util" -require_relative "bringit/attributes" -require_relative "bringit/version_info" -require_relative "bringit/committing" -require_relative "bringit/cloning" -require_relative "bringit/pulling" -require_relative "bringit/wrapper" +require_relative 'bringit/blame' +require_relative 'bringit/blob' +require_relative 'bringit/commit' +require_relative 'bringit/commit_stats' +require_relative 'bringit/compare' +require_relative 'bringit/diff' +require_relative 'bringit/diff_collection' +require_relative 'bringit/hook' +require_relative 'bringit/index' +require_relative 'bringit/rev_list' +require_relative 'bringit/repository' +require_relative 'bringit/tree' +require_relative 'bringit/blob_snippet' +require_relative 'bringit/ref' +require_relative 'bringit/branch' +require_relative 'bringit/tag' +require_relative 'bringit/util' +require_relative 'bringit/attributes' +require_relative 'bringit/version_info' +require_relative 'bringit/committing' +require_relative 'bringit/cloning' +require_relative 'bringit/pulling' +require_relative 'bringit/wrapper' module Bringit BLANK_SHA = ('0' * 40).freeze - TAG_REF_PREFIX = "refs/tags/".freeze - BRANCH_REF_PREFIX = "refs/heads/".freeze + TAG_REF_PREFIX = 'refs/tags/' + BRANCH_REF_PREFIX = 'refs/heads/' class << self def ref_name(ref) @@ -51,11 +53,7 @@ def ref_name(ref) def branch_name(ref) ref = ref.to_s - if self.branch_ref?(ref) - self.ref_name(ref) - else - nil - end + ref_name(ref) if branch_ref?(ref) end def committer_hash(email:, name:) @@ -64,17 +62,13 @@ def committer_hash(email:, name:) { email: email, name: name, - time: Time.now + time: Time.now, } end def tag_name(ref) ref = ref.to_s - if self.tag_ref?(ref) - self.ref_name(ref) - else - nil - end + ref_name(ref) if tag_ref?(ref) end def tag_ref?(ref) @@ -90,7 +84,7 @@ def blank_ref?(ref) end def version - Bringit::VersionInfo.parse(Bringit::Popen.popen(%W(git --version)).first) + Bringit::VersionInfo.parse(Bringit::Popen.popen(%w(git --version)).first) end end end diff --git a/lib/bringit/attributes.rb b/lib/bringit/attributes.rb index 08a1740..a624b79 100644 --- a/lib/bringit/attributes.rb +++ b/lib/bringit/attributes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit # Class for parsing Git attribute files and extracting the attributes for # file patterns. diff --git a/lib/bringit/blame.rb b/lib/bringit/blame.rb index 2d6ce26..cc911d4 100644 --- a/lib/bringit/blame.rb +++ b/lib/bringit/blame.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit class Blame include Bringit::EncodingHelper @@ -26,21 +28,25 @@ def each def load_blame cmd = %W(git --git-dir=#{@repo.path} blame -p #{@sha} -- #{@path}) # Read in binary mode to ensure ASCII-8BIT - raw_output = IO.popen(cmd, 'rb') {|io| io.read } + raw_output = IO.popen(cmd, 'rb', &:read) output = encode_utf8(raw_output) process_raw_blame output end def process_raw_blame(output) - lines, final = [], [] - info, commits = {}, {} + lines = [] + final = [] + info = {} + commits = {} # process the output output.split("\n").each do |line| if line[0, 1] == "\t" lines << line[1, line.size] elsif m = /^(\w{40}) (\d+) (\d+)/.match(line) - commit_id, old_lineno, lineno = m[1], m[2].to_i, m[3].to_i + commit_id = m[1] + old_lineno = m[2].to_i + lineno = m[3].to_i commits[commit_id] = nil unless commits.key?(commit_id) info[lineno] = [commit_id, old_lineno] end diff --git a/lib/bringit/blob.rb b/lib/bringit/blob.rb index 973aba1..6c2e63a 100644 --- a/lib/bringit/blob.rb +++ b/lib/bringit/blob.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit class Blob include Linguist::BlobHelper @@ -36,8 +38,7 @@ def find(repository, sha, path) mode: blob_entry[:filemode].to_s(8), path: Bringit::PathHelper.normalize_path(path).to_s, commit_id: sha, - binary: blob.binary? - ) + binary: blob.binary?) end end end @@ -49,8 +50,7 @@ def raw(repository, sha) id: blob.oid, size: blob.size, data: blob.content(MAX_DATA_DISPLAY_SIZE), - binary: blob.binary? - ) + binary: blob.binary?) end # Recursive search of blob id by path @@ -81,7 +81,7 @@ def find_entry_by_path(repository, root_id, path) path_arr.shift find_entry_by_path(repository, entry[:oid], path_arr.join('/')) else - [:blob, :commit].include?(entry[:type]) ? entry : nil + %i(blob commit).include?(entry[:type]) ? entry : nil end end @@ -92,15 +92,14 @@ def submodule_blob(repository, blob_entry, path, sha) name: blob_entry[:name], data: '', path: path, - commit_id: sha, - ) + commit_id: sha) end end def initialize(repository, options) @repository = repository %w(id name path size data mode commit_id binary).each do |key| - self.send("#{key}=", options[key.to_sym]) + send("#{key}=", options[key.to_sym]) end @loaded_all_data = false @@ -169,7 +168,7 @@ def truncated? private def has_lfs_version_key? - !empty? && text? && data.start_with?("version https://git-lfs.github.com/spec") + !empty? && text? && data.start_with?('version https://git-lfs.github.com/spec') end end end diff --git a/lib/bringit/blob_snippet.rb b/lib/bringit/blob_snippet.rb index fba0036..457e183 100644 --- a/lib/bringit/blob_snippet.rb +++ b/lib/bringit/blob_snippet.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit class BlobSnippet include Linguist::BlobHelper @@ -8,7 +10,10 @@ class BlobSnippet attr_accessor :startline def initialize(ref, lines, startline, filename) - @ref, @lines, @startline, @filename = ref, lines, startline, filename + @ref = ref + @lines = lines + @startline = startline + @filename = filename end def data diff --git a/lib/bringit/branch.rb b/lib/bringit/branch.rb index efaf96a..c7940ac 100644 --- a/lib/bringit/branch.rb +++ b/lib/bringit/branch.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Bringit class Branch < Ref - def self.find(repository,name) + def self.find(repository, name) repository.branches.find { |branch| branch.name == name } end end diff --git a/lib/bringit/commit.rb b/lib/bringit/commit.rb index 8b9c256..98df71a 100644 --- a/lib/bringit/commit.rb +++ b/lib/bringit/commit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Bringit::Commit is a wrapper around native Rugged::Commit object module Bringit class Commit @@ -6,11 +8,11 @@ class Commit attr_reader :repository attr_accessor :raw_commit, :head, :refs - SERIALIZE_KEYS = [ - :id, :message, :parent_ids, - :authored_date, :author_name, :author_email, - :committed_date, :committer_name, :committer_email - ].freeze + SERIALIZE_KEYS = %i( + id message parent_ids + authored_date author_name author_email + committed_date committer_name committer_email + ).freeze attr_accessor *SERIALIZE_KEYS # rubocop:disable Lint/AmbiguousOperator @@ -19,9 +21,9 @@ class Commit def ==(other) return false unless other.is_a?(Bringit::Commit) - methods = [:message, :parent_ids, :authored_date, :author_name, - :author_email, :committed_date, :committer_name, - :committer_email] + methods = %i(messageparent_idsauthored_dateauthor_name + author_email committed_date committer_name + committer_email) methods.all? do |method| send(method) == other.send(method) @@ -54,7 +56,7 @@ def where(options) # # Commit.find(repo, 'master') # - def find(repo, commit_id = "HEAD") + def find(repo, commit_id = 'HEAD') return decorate(commit_id, repo) if commit_id.is_a?(Rugged::Commit) obj = if commit_id.is_a?(String) @@ -128,9 +130,9 @@ def diff_from_parent(rugged_commit, options = {}) actual_options = Bringit::Diff.filter_diff_options(options) diff = if rugged_commit.parents.empty? - rugged_commit.diff(actual_options.merge(reverse: true)) - else - rugged_commit.parents[0].diff(rugged_commit, actual_options) + rugged_commit.diff(actual_options.merge(reverse: true)) + else + rugged_commit.parents[0].diff(rugged_commit, actual_options) end diff.find_similar!(break_rewrites: break_rewrites) @@ -139,7 +141,7 @@ def diff_from_parent(rugged_commit, options = {}) end def initialize(raw_commit, repository = nil, head = nil) - raise "Nil as raw commit passed" unless raw_commit + raise 'Nil as raw commit passed' unless raw_commit if raw_commit.is_a?(Hash) init_from_hash(raw_commit) @@ -195,12 +197,12 @@ def diff_from_parent(options = {}) def has_zero_stats? stats.total.zero? - rescue + rescue StandardError true end def no_commit_message - "--no commit message" + '--no commit message' end def to_hash @@ -226,12 +228,10 @@ def stats end def to_patch(options = {}) - begin - raw_commit.to_mbox(options) - rescue Rugged::InvalidError => ex - if ex.message =~ /Commit \w+ is a merge commit/ - 'Patch format is not currently supported for merge commits.' - end + raw_commit.to_mbox(options) + rescue Rugged::InvalidError => ex + if ex.message.match?(/Commit \w+ is a merge commit/) + 'Patch format is not currently supported for merge commits.' end end @@ -247,17 +247,15 @@ def refs # Get a collection of Bringit::Ref (its subclasses) objects def references refs.map do |ref| - if ref.name.match(%r{\Arefs/heads/}) + if ref.name.match?(%r{\Arefs/heads/}) Bringit::Branch.new(repository, ref.name, ref.target) - elsif ref.name.match(%r{\Arefs/tags/}) + elsif ref.name.match?(%r{\Arefs/tags/}) message = nil if ref.target.is_a?(Rugged::Tag::Annotation) tag_message = ref.target.message - if tag_message.respond_to?(:chomp) - message = tag_message.chomp - end + message = tag_message.chomp if tag_message.respond_to?(:chomp) end Bringit::Tag.new(self, ref.name, ref.target, message) @@ -274,7 +272,7 @@ def references # def ref_names repository.refs_hash[id].map do |ref| - ref.name.sub(%r{^refs/(heads|remotes|tags)/}, "") + ref.name.sub(%r{^refs/(heads|remotes|tags)/}, '') end end diff --git a/lib/bringit/commit_stats.rb b/lib/bringit/commit_stats.rb index 5079926..559b47a 100644 --- a/lib/bringit/commit_stats.rb +++ b/lib/bringit/commit_stats.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Bringit::CommitStats counts the additions, deletions, and total changes # in a commit. module Bringit diff --git a/lib/bringit/committing.rb b/lib/bringit/committing.rb index 9eebb97..19026be 100644 --- a/lib/bringit/committing.rb +++ b/lib/bringit/committing.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "committing/merge" +require_relative 'committing/merge' module Bringit # Methods for committing. Use all these methods only mutexed with the git @@ -247,7 +247,6 @@ def commit_multichange(options, previous_head_sha = nil) protected - # Converts the options from a single change commit to a multi change # commit. def convert_options(options, action) @@ -282,10 +281,6 @@ def normalize_update_ref(options) # This method does the actual committing. Use this mutexed with the git # repository as the key. - # rubocop:disable Metrics/AbcSize - # rubocop:disable Metrics/CyclomaticComplexity - # rubocop:disable Metrics/PerceivedComplexity - # rubocop:disable Metrics/MethodLength def commit_with(options, previous_head_sha) # rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/CyclomaticComplexity @@ -317,7 +312,7 @@ def parents_and_last_commit(options) [parents, last_commit] end - def create_commit(index, tree, options, parents) + def create_commit(_index, tree, options, parents) opts = {} opts[:tree] = tree opts[:author] = options[:author] diff --git a/lib/bringit/committing/merge.rb b/lib/bringit/committing/merge.rb index 8208a73..a835c76 100644 --- a/lib/bringit/committing/merge.rb +++ b/lib/bringit/committing/merge.rb @@ -9,7 +9,7 @@ def merge_if_needed(options, previous_head_sha) return [:noop, nil] unless diverged?(options, previous_head_sha) commit_sha = merge(options, previous_head_sha) - return [:merge_commit_created, commit_sha] + [:merge_commit_created, commit_sha] end def diverged?(options, previous_head_sha) @@ -76,17 +76,17 @@ def conflict_on_update(base_commit, user_commit, path) def conflict_hash(blob_object, stage) {path: blob_object.path, - oid: blob_object.id, - dev: 0, - ino: 0, - mode: blob_object.mode.to_i(8), - gid: 0, - uid: 0, - file_size: 0, - valid: false, - stage: stage, - ctime: Time.at(0), - mtime: Time.at(0)} + oid: blob_object.id, + dev: 0, + ino: 0, + mode: blob_object.mode.to_i(8), + gid: 0, + uid: 0, + file_size: 0, + valid: false, + stage: stage, + ctime: Time.at(0), + mtime: Time.at(0)} end def create_user_commit(options, previous_head_sha) @@ -100,7 +100,7 @@ def create_user_commit(options, previous_head_sha) end end - def with_temp_user_reference(options, previous_head_sha) + def with_temp_user_reference(_options, previous_head_sha) refname = "#{Time.now.to_f.to_s.tr('.', '')}_#{SecureRandom.hex(20)}" full_refname = "refs/merges/user/#{refname}" reference = rugged.references.create(full_refname, previous_head_sha) @@ -115,8 +115,8 @@ def create_merging_commit(parent_commit, index, tree_id, options) end def raise_head_changed_error(conflicts, options) - message = < ENCODING_CONFIDENCE_THRESHOLD @@ -31,8 +33,8 @@ def encode!(message) # encode and clean the bad chars message.replace clean(message) - rescue - encoding = detect ? detect[:encoding] : "unknown" + rescue StandardError + encoding = detect ? detect[:encoding] : 'unknown' "--broken encoding: #{encoding}" end @@ -48,9 +50,9 @@ def encode_utf8(message) private def clean(message) - message.encode("UTF-16BE", undef: :replace, invalid: :replace, replace: "") - .encode("UTF-8") - .gsub("\0".encode("UTF-8"), "") + message.encode('UTF-16BE', undef: :replace, invalid: :replace, replace: ''). + encode('UTF-8'). + gsub("\0".encode('UTF-8'), '') end end end diff --git a/lib/bringit/hook.rb b/lib/bringit/hook.rb index 58b8643..5497f76 100644 --- a/lib/bringit/hook.rb +++ b/lib/bringit/hook.rb @@ -1,8 +1,10 @@ -require "bundler" +# frozen_string_literal: true + +require 'bundler' module Bringit class Hook - GL_PROTOCOL = 'web'.freeze + GL_PROTOCOL = 'web' attr_reader :name, :repo_path, :path def initialize(name, repo_path) @@ -20,9 +22,9 @@ def trigger(user_id, oldrev, newrev, ref) Bundler.with_clean_env do case name - when "pre-receive", "post-receive" + when 'pre-receive', 'post-receive' call_receive_hook(user_id, oldrev, newrev, ref) - when "update" + when 'update' call_update_hook(user_id, oldrev, newrev, ref) end end @@ -31,7 +33,7 @@ def trigger(user_id, oldrev, newrev, ref) private def call_receive_hook(user_id, oldrev, newrev, ref) - changes = [oldrev, newrev, ref].join(" ") + changes = [oldrev, newrev, ref].join(' ') exit_status = false exit_message = nil @@ -39,11 +41,11 @@ def call_receive_hook(user_id, oldrev, newrev, ref) vars = { 'USER_ID' => user_id, 'PWD' => repo_path, - 'GL_PROTOCOL' => GL_PROTOCOL + 'GL_PROTOCOL' => GL_PROTOCOL, } options = { - chdir: repo_path + chdir: repo_path, } Open3.popen3(vars, path, options) do |stdin, stdout, stderr, wait_thr| @@ -74,7 +76,7 @@ def call_receive_hook(user_id, oldrev, newrev, ref) def call_update_hook(user_id, oldrev, newrev, ref) Dir.chdir(repo_path) do - stdout, stderr, status = Open3.capture3({ 'USER_ID' => user_id }, path, ref, oldrev, newrev) + stdout, stderr, status = Open3.capture3({'USER_ID' => user_id}, path, ref, oldrev, newrev) [status.success?, stderr.presence || stdout] end end diff --git a/lib/bringit/index.rb b/lib/bringit/index.rb index 79ed48e..3412ccf 100644 --- a/lib/bringit/index.rb +++ b/lib/bringit/index.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit class Index DEFAULT_MODE = 0o100644 @@ -24,7 +26,7 @@ def create(options) file_entry = get(options[:file_path]) if file_entry - raise Bringit::Repository::InvalidBlobName.new("Filename already exists") + raise Bringit::Repository::InvalidBlobName, 'Filename already exists' end add_blob(options) @@ -35,11 +37,11 @@ def create_dir(options) file_entry = get(options[:file_path]) if file_entry - raise Bringit::Repository::InvalidBlobName.new("Directory already exists as a file") + raise Bringit::Repository::InvalidBlobName, 'Directory already exists as a file' end if dir_exists?(options[:file_path]) - raise Bringit::Repository::InvalidBlobName.new("Directory already exists") + raise Bringit::Repository::InvalidBlobName, 'Directory already exists' end options = options.dup @@ -54,7 +56,7 @@ def update(options) file_entry = get(options[:file_path]) unless file_entry - raise Bringit::Repository::InvalidBlobName.new("File doesn't exist") + raise Bringit::Repository::InvalidBlobName, "File doesn't exist" end add_blob(options, mode: file_entry[:mode]) @@ -65,11 +67,11 @@ def move(options) file_entry = get(options[:previous_path]) unless file_entry - raise Bringit::Repository::InvalidBlobName.new("File doesn't exist") + raise Bringit::Repository::InvalidBlobName, "File doesn't exist" end if get(options[:file_path]) - raise IndexError, "A file with this name already exists" + raise IndexError, 'A file with this name already exists' end raw_index.remove(options[:previous_path]) @@ -82,7 +84,7 @@ def delete(options) file_entry = get(options[:file_path]) unless file_entry - raise Bringit::Repository::InvalidBlobName.new("File doesn't exist") + raise Bringit::Repository::InvalidBlobName, "File doesn't exist" end raw_index.remove(options[:file_path]) @@ -101,7 +103,7 @@ def normalize_path(path) pathname = Bringit::PathHelper.normalize_path(path.dup) if pathname.each_filename.include?('..') - raise Bringit::Repository::InvalidBlobName.new('Invalid path') + raise Bringit::Repository::InvalidBlobName, 'Invalid path' end pathname.to_s @@ -122,7 +124,7 @@ def add_blob(options, mode: nil) raw_index.add(path: options[:file_path], oid: oid, mode: mode || DEFAULT_MODE) rescue Rugged::IndexError => e - raise Bringit::Repository::InvalidBlobName.new(e.message) + raise Bringit::Repository::InvalidBlobName, e.message end end end diff --git a/lib/bringit/path_helper.rb b/lib/bringit/path_helper.rb index 09135da..ab61fd9 100644 --- a/lib/bringit/path_helper.rb +++ b/lib/bringit/path_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit class PathHelper class << self diff --git a/lib/bringit/popen.rb b/lib/bringit/popen.rb index 7f5bcf2..61ff034 100644 --- a/lib/bringit/popen.rb +++ b/lib/bringit/popen.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'fileutils' require 'open3' module Bringit module Popen - extend self + module_function def self.popen(cmd, path = nil, vars = {}) unless cmd.is_a?(Array) diff --git a/lib/bringit/ref.rb b/lib/bringit/ref.rb index 76ae161..f80e767 100644 --- a/lib/bringit/ref.rb +++ b/lib/bringit/ref.rb @@ -1,16 +1,15 @@ +# frozen_string_literal: true + module Bringit class Ref include Bringit::EncodingHelper def self.name_valid?(name) - if name.start_with?('refs/heads/') || name.start_with?('refs/remotes/') - return false - end + return false if name.start_with?('refs/heads/', 'refs/remotes/') Popen.popen(%W(git check-ref-format refs/#{name})).last == 0 end - # Branch or tag name # without "refs/tags|heads" prefix attr_reader :name @@ -48,8 +47,6 @@ def initialize(repository, name, target) target.name elsif target.is_a? String target - else - nil end end end diff --git a/lib/bringit/repository.rb b/lib/bringit/repository.rb index 3c7725b..e59630b 100644 --- a/lib/bringit/repository.rb +++ b/lib/bringit/repository.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + # Bringit::Repository is a wrapper around native Rugged::Repository object require 'tempfile' require 'forwardable' -require "rubygems/package" +require 'rubygems/package' module Bringit class Repository @@ -26,7 +28,7 @@ class Repository # /path/to/my-repo.git def initialize(path) @path = path - @name = path.split("/").last + @name = path.split('/').last @attributes = Bringit::Attributes.new(path) end @@ -47,7 +49,7 @@ def raw def rugged @rugged ||= Rugged::Repository.new(path) rescue Rugged::RepositoryError, Rugged::OSError - raise NoRepository.new('no repository for such path') + raise NoRepository, 'no repository for such path' end # Returns an Array of branch names @@ -59,11 +61,9 @@ def branch_names # Returns an Array of Branches def branches rugged.branches.map do |rugged_ref| - begin - Bringit::Branch.new(self, rugged_ref.name, rugged_ref.target) - rescue Rugged::ReferenceError - # Omit invalid branch - end + Bringit::Branch.new(self, rugged_ref.name, rugged_ref.target) + rescue Rugged::ReferenceError + # Omit invalid branch end.compact.sort_by(&:name) end @@ -94,32 +94,28 @@ def local_branches # Returns the number of valid branches def branch_count rugged.branches.count do |ref| - begin - ref.name && ref.target # ensures the branch is valid + ref.name && ref.target # ensures the branch is valid - true - rescue Rugged::ReferenceError - false - end + true + rescue Rugged::ReferenceError + false end end # Returns an Array of tag names def tag_names - rugged.tags.map { |t| t.name } + rugged.tags.map(&:name) end # Returns an Array of Tags def tags - rugged.references.each("refs/tags/*").map do |ref| + rugged.references.each('refs/tags/*').map do |ref| message = nil if ref.target.is_a?(Rugged::Tag::Annotation) tag_message = ref.target.message - if tag_message.respond_to?(:chomp) - message = tag_message.chomp - end + message = tag_message.chomp if tag_message.respond_to?(:chomp) end Bringit::Tag.new(self, ref.name, ref.target, message) @@ -154,7 +150,7 @@ def ref_names # Deprecated. Will be removed in 5.2 def heads - rugged.references.each("refs/heads/*").map do |head| + rugged.references.each('refs/heads/*').map do |head| Bringit::Ref.new(self, head.name, head.target) end.sort_by(&:name) end @@ -199,11 +195,11 @@ def rugged_head end def archive_prefix(ref, sha) - project_name = self.name.chomp('.git') + project_name = name.chomp('.git') "#{project_name}-#{ref.tr('/', '-')}-#{sha}" end - def archive_metadata(ref, storage_path, format = "tar.gz") + def archive_metadata(ref, storage_path, format = 'tar.gz') ref ||= root_ref commit = Bringit::Commit.find(self, ref) return {} if commit.nil? @@ -218,21 +214,21 @@ def archive_metadata(ref, storage_path, format = "tar.gz") } end - def archive_file_path(name, storage_path, format = "tar.gz") + def archive_file_path(name, storage_path, format = 'tar.gz') # Build file path return nil unless name extension = case format - when "tar.bz2", "tbz", "tbz2", "tb2", "bz2" - "tar.bz2" - when "tar" - "tar" - when "zip" - "zip" + when 'tar.bz2', 'tbz', 'tbz2', 'tb2', 'bz2' + 'tar.bz2' + when 'tar' + 'tar' + when 'zip' + 'zip' else # everything else should fall back to tar.gz - "tar.gz" + 'tar.gz' end file_name = "#{name}.#{extension}" @@ -326,7 +322,7 @@ def log_by_walk(sha, options) show: sha, sort: Rugged::SORT_TOPO, limit: options[:limit], - offset: options[:offset] + offset: options[:offset], } commits = Rugged::Walker.walk(rugged, walk_options).to_a if options[:only_commit_sha] @@ -346,7 +342,7 @@ def log_by_shell(sha, options) offset_in_ruby = use_follow_flag && options[:offset].present? limit += offset if offset_in_ruby - cmd = %W[git --git-dir=#{path} log] + cmd = %W(git --git-dir=#{path} log) cmd << "--max-count=#{limit}" if limit > 0 cmd << '--format=%H' cmd << "--skip=#{offset}" unless offset_in_ruby @@ -356,10 +352,10 @@ def log_by_shell(sha, options) cmd << "--before=#{options[:before].iso8601}" if options[:before] cmd << sha if options[:path].present? - cmd += %W[-- #{options[:path].sub(%r{\A/*}, './')}] + cmd += %W(-- #{options[:path].sub(%r{\A/*}, './')}) end - raw_output = IO.popen(cmd) { |io| io.read } + raw_output = IO.popen(cmd, &:read) lines = offset_in_ruby ? raw_output.lines.drop(offset) : raw_output.lines if options[:only_commit_sha] @@ -370,13 +366,13 @@ def log_by_shell(sha, options) end def count_commits(options) - cmd = %W[git --git-dir=#{path} rev-list] + cmd = %W(git --git-dir=#{path} rev-list) cmd << "--after=#{options[:after].iso8601}" if options[:after] cmd << "--before=#{options[:before].iso8601}" if options[:before] - cmd += %W[--count #{options[:ref]}] - cmd += %W[-- #{options[:path]}] if options[:path].present? + cmd += %W(--count #{options[:ref]}) + cmd += %W(-- #{options[:path]}) if options[:path].present? - raw_output = IO.popen(cmd) { |io| io.read } + raw_output = IO.popen(cmd, &:read) raw_output.to_i end @@ -449,13 +445,13 @@ def diff(from, to, options = {}, *paths) def find_commits(options = {}) actual_options = options.dup - allowed_options = [:ref, :max_count, :skip, :contains, :order] + allowed_options = %i(ref max_count skip contains order) actual_options.keep_if do |key| allowed_options.include?(key) end - default_options = { skip: 0 } + default_options = {skip: 0} actual_options = default_options.merge(actual_options) walker = Rugged::Walker.new(rugged) @@ -467,7 +463,7 @@ def find_commits(options = {}) walker.push(branch.target_id) end else - rugged.references.each("refs/heads/*") do |ref| + rugged.references.each('refs/heads/*') do |ref| walker.push(ref.target_id) end end @@ -500,7 +496,7 @@ def find_commits(options = {}) # repo.branch_names_contains('master') # def branch_names_contains(commit) - branches_contains(commit).map { |c| c.name } + branches_contains(commit).map(&:name) end # Returns branch collection that contains the special commit(SHA1 or name) @@ -567,7 +563,7 @@ def submodules(ref) return {} unless commit begin - content = blob_content(commit, ".gitmodules") + content = blob_content(commit, '.gitmodules') rescue InvalidBlobName return {} end @@ -761,12 +757,12 @@ def clean(options = {}) # :target_directory :: # A path to an alternative workdir directory in which the checkout # should be performed. - def checkout(ref, options = {}, start_point = "HEAD") + def checkout(ref, options = {}, start_point = 'HEAD') if options[:b] rugged.branches.create(ref, start_point) options.delete(:b) end - default_options = { strategy: [:recreate_missing, :safe] } + default_options = {strategy: %i(recreate_missing safe)} rugged.checkout(ref, default_options.merge(options)) end @@ -780,12 +776,12 @@ def delete_branch(branch_name) # Examples: # create_branch("feature") # create_branch("other-feature", "master") - def create_branch(ref, start_point = "HEAD") + def create_branch(ref, start_point = 'HEAD') rugged_ref = rugged.branches.create(ref, start_point) Bringit::Branch.new(self, rugged_ref.name, rugged_ref.target) rescue Rugged::ReferenceError => e - raise InvalidRef.new("Branch #{ref} already exists") if e.to_s =~ /'refs\/heads\/#{ref}'/ - raise InvalidRef.new("Invalid reference #{start_point}") + raise InvalidRef, "Branch #{ref} already exists" if e.to_s =~ /'refs\/heads\/#{ref}'/ + raise InvalidRef, "Invalid reference #{start_point}" end # Return an array of this repository's remote names @@ -829,8 +825,8 @@ def merge(source_name, target_name, options = {}) our_commit = rugged.branches[target_name].target their_commit = rugged.branches[source_name].target - raise "Invalid merge target" if our_commit.nil? - raise "Invalid merge source" if their_commit.nil? + raise 'Invalid merge target' if our_commit.nil? + raise 'Invalid merge source' if their_commit.nil? merge_index = rugged.merge_commits(our_commit, their_commit) return false if merge_index.conflicts? @@ -847,7 +843,7 @@ def commits_since(from_date) walker = Rugged::Walker.new(rugged) walker.sorting(Rugged::SORT_DATE | Rugged::SORT_REVERSE) - rugged.references.each("refs/heads/*") do |ref| + rugged.references.each('refs/heads/*') do |ref| walker.push(ref.target_id) end @@ -861,9 +857,9 @@ def commits_since(from_date) end AUTOCRLF_VALUES = { - "true" => true, - "false" => false, - "input" => :input + 'true' => true, + 'false' => false, + 'input' => :input, }.freeze def autocrlf @@ -897,8 +893,8 @@ def ls_files(ref) raw_output = IO.popen(cmd, &:read).split("\n").map do |f| stuff, path = f.split("\t") - _mode, type, _sha = stuff.split(" ") - path if type == "blob" + _mode, type, _sha = stuff.split(' ') + path if type == 'blob' # Contain only blob type end @@ -909,7 +905,7 @@ def copy_gitattributes(ref) begin commit = lookup(ref) rescue Rugged::ReferenceError - raise InvalidRef.new("Ref #{ref} is invalid") + raise InvalidRef, "Ref #{ref} is invalid" end # Create the paths @@ -930,7 +926,7 @@ def copy_gitattributes(ref) # Write the contents of the .gitattributes file to info/attributes # Use binary mode to prevent Rails from converting ASCII-8BIT to UTF-8 - File.open(info_attributes_path, "wb") do |file| + File.open(info_attributes_path, 'wb') do |file| file.write(gitattributes_content) end end @@ -954,15 +950,13 @@ def attributes(path) def blob_content(commit, blob_name) blob_entry = tree_entry(commit, blob_name) - unless blob_entry - raise InvalidBlobName.new("Invalid blob name: #{blob_name}") - end + raise InvalidBlobName, "Invalid blob name: #{blob_name}" unless blob_entry case blob_entry[:type] when :commit blob_entry[:oid] when :tree - raise InvalidBlobName.new("#{blob_name} is a tree, not a blob") + raise InvalidBlobName, "#{blob_name} is a tree, not a blob" when :blob rugged.lookup(blob_entry[:oid]).content end @@ -973,9 +967,9 @@ def blob_content(commit, blob_name) def parse_gitmodules(commit, content) results = {} - current = "" + current = '' content.split("\n").each do |txt| - if txt =~ /^\s*\[/ + if txt.match?(/^\s*\[/) current = txt.match(/(?<=").*(?=")/)[0] results[current] = {} else @@ -985,9 +979,9 @@ def parse_gitmodules(commit, content) target = match_data[2].chomp results[current][match_data[1]] = target - if match_data[1] == "path" + if match_data[1] == 'path' begin - results[current]["id"] = blob_content(commit, target) + results[current]['id'] = blob_content(commit, target) rescue InvalidBlobName results.delete(current) end @@ -1115,22 +1109,20 @@ def archive_to_file(treeish = 'master', filename = 'archive.tar.gz', format = ni # When 'git archive' and the compression process are finished, we are # done. Process.waitpid(git_archive_pid) - raise "#{git_archive_cmd.join(' ')} failed" unless $?.success? + raise "#{git_archive_cmd.join(' ')} failed" unless $CHILD_STATUS.success? Process.waitpid(compress_pid) - raise "#{compress_cmd.join(' ')} failed" unless $?.success? + raise "#{compress_cmd.join(' ')} failed" unless $CHILD_STATUS.success? end end def nice(cmd) nice_cmd = %w(nice -n 20) - unless unsupported_platform? - nice_cmd += %w(ionice -c 2 -n 7) - end + nice_cmd += %w(ionice -c 2 -n 7) unless unsupported_platform? nice_cmd + cmd end def unsupported_platform? - %w[darwin freebsd solaris].map { |platform| RUBY_PLATFORM.include?(platform) }.any? + %w(darwin freebsd solaris).map { |platform| RUBY_PLATFORM.include?(platform) }.any? end # Returns true if the index entry has the special file mode that denotes @@ -1190,9 +1182,9 @@ def build_greps(file_contents, query, ref, filename) # Loop through consecutive blocks of lines with indexes lines_with_index.each_cons(2 * SEARCH_CONTEXT_LINES + 1) do |line_block| # Get the 'middle' line and index from the block - line, _ = line_block[SEARCH_CONTEXT_LINES] + line, = line_block[SEARCH_CONTEXT_LINES] - next unless line && line.match(/#{Regexp.escape(query)}/i) + next unless line&.match(/#{Regexp.escape(query)}/i) # Yay, 'line' contains a match! # Get an array with just the context lines (no indexes) diff --git a/lib/bringit/rev_list.rb b/lib/bringit/rev_list.rb index 309d73d..a7a9054 100644 --- a/lib/bringit/rev_list.rb +++ b/lib/bringit/rev_list.rb @@ -1,18 +1,20 @@ +# frozen_string_literal: true + module Bringit class RevList attr_reader :repository, :env - ALLOWED_VARIABLES = %w[GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES].freeze + ALLOWED_VARIABLES = %w(GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES).freeze def initialize(oldrev, newrev, repository:, env: nil) @repository = repository @env = env.presence || {} - @args = ["git", - "--git-dir=#{repository.path}", - "rev-list", - "--max-count=1", - oldrev, - "^#{newrev}"] + @args = ['git', + "--git-dir=#{repository.path}", + 'rev-list', + '--max-count=1', + oldrev, + "^#{newrev}"] end def execute @@ -20,7 +22,7 @@ def execute end def valid? - environment_variables.all? do |(name, value)| + environment_variables.all? do |(_name, value)| value.to_s.start_with?(repository.path) end end diff --git a/lib/bringit/tag.rb b/lib/bringit/tag.rb index 3597b6e..8791136 100644 --- a/lib/bringit/tag.rb +++ b/lib/bringit/tag.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit class Tag < Ref attr_reader :object_sha diff --git a/lib/bringit/tree.rb b/lib/bringit/tree.rb index 6066b7f..d4d5c46 100644 --- a/lib/bringit/tree.rb +++ b/lib/bringit/tree.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit class Tree include Bringit::EncodingHelper @@ -17,14 +19,14 @@ def where(repository, sha, path = nil) root_tree = commit.tree tree = if path - id = find_id_by_path(repository, root_tree.oid, path) - if id - repository.lookup(id) - else - [] - end - else - root_tree + id = find_id_by_path(repository, root_tree.oid, path) + if id + repository.lookup(id) + else + [] + end + else + root_tree end tree.map do |entry| @@ -35,7 +37,7 @@ def where(repository, sha, path = nil) type: entry[:type], mode: entry[:filemode], path: path ? File.join(path, entry[:name]) : entry[:name], - commit_id: sha, + commit_id: sha ) end end @@ -73,7 +75,7 @@ def find_id_by_path(repository, root_id, path) def initialize(options) %w(id root_id name path type mode commit_id).each do |key| - self.send("#{key}=", options[key.to_sym]) + send("#{key}=", options[key.to_sym]) end end diff --git a/lib/bringit/util.rb b/lib/bringit/util.rb index fad0212..1b96193 100644 --- a/lib/bringit/util.rb +++ b/lib/bringit/util.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Bringit module Util - LINE_SEP = "\n".freeze + LINE_SEP = "\n" def self.count_lines(string) case string[-1] diff --git a/lib/bringit/version_info.rb b/lib/bringit/version_info.rb index a7f4550..7c0da89 100644 --- a/lib/bringit/version_info.rb +++ b/lib/bringit/version_info.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Bringit class VersionInfo include Comparable @@ -41,9 +43,9 @@ def <=>(other) def to_s if valid? - "%d.%d.%d" % [@major, @minor, @patch] + format('%d.%d.%d', @major, @minor, @patch) else - "Unknown" + 'Unknown' end end diff --git a/performance/Rakefile b/performance/Rakefile index 56012f8..f01903b 100644 --- a/performance/Rakefile +++ b/performance/Rakefile @@ -1,11 +1,13 @@ -BRINGIT_GIT_ROOT = File.expand_path('../..', __FILE__) +# frozen_string_literal: true + +BRINGIT_GIT_ROOT = File.expand_path('..', __dir__) PERFORMANCE_TEST_REPO_SOURCE = 'https://gitlab.com/gitlab-org/git-memory-test.git' PERFORMANCE_TEST_REPO_PATH = File.join(BRINGIT_GIT_ROOT, 'support/git-memory-test.git') desc "Clone the test repo from #{PERFORMANCE_TEST_REPO_SOURCE}" task :clone do unless File.exist?(PERFORMANCE_TEST_REPO_PATH) - system(*%W(git clone --bare #{PERFORMANCE_TEST_REPO_SOURCE} -- #{PERFORMANCE_TEST_REPO_PATH})) + system('git', 'clone', '--bare', PERFORMANCE_TEST_REPO_SOURCE.to_s, '--', PERFORMANCE_TEST_REPO_PATH.to_s) end end @@ -20,7 +22,7 @@ Dir['test/*.rb'].each do |test_file| desc "Performance test: #{test_name}" task test_name => :clone do puts "Running performance test: #{test_name}" - system(*%W(time bundle exec ruby -Ilib #{test_file} #{PERFORMANCE_TEST_REPO_PATH})) + system('time', 'bundle', 'exec', 'ruby', '-Ilib', test_file.to_s, PERFORMANCE_TEST_REPO_PATH.to_s) end tests << test_name end diff --git a/performance/lib/memory_benchmark.rb b/performance/lib/memory_benchmark.rb index 7b69dba..c95c07f 100644 --- a/performance/lib/memory_benchmark.rb +++ b/performance/lib/memory_benchmark.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def memory_benchmark print_rss 10.times do @@ -7,5 +9,5 @@ def memory_benchmark end def print_rss - printf "%s RSS: %9s", $PROGRAM_NAME, IO.popen(%W(ps -o rss= -p #{Process.pid})).read + printf '%s RSS: %9s', $PROGRAM_NAME, IO.popen(%W(ps -o rss= -p #{Process.pid})).read end diff --git a/performance/test/load_large_diff.rb b/performance/test/load_large_diff.rb index 049a7cc..8166ffe 100644 --- a/performance/test/load_large_diff.rb +++ b/performance/test/load_large_diff.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bringit' require 'memory_benchmark' diff --git a/performance/test/search.rb b/performance/test/search.rb index 28bba19..ad87b81 100644 --- a/performance/test/search.rb +++ b/performance/test/search.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bringit' require 'memory_benchmark' diff --git a/spec/attributes_spec.rb b/spec/attributes_spec.rb index c0b8875..931d5b7 100644 --- a/spec/attributes_spec.rb +++ b/spec/attributes_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Bringit::Attributes, seed_helper: true do @@ -10,40 +12,40 @@ describe '#attributes' do context 'using a path with attributes' do it 'returns the attributes as a Hash' do - expect(subject.attributes('test.txt')).to eq({ 'text' => true }) + expect(subject.attributes('test.txt')).to eq('text' => true) end it 'returns a Hash containing multiple attributes' do expect(subject.attributes('test.sh')). - to eq({ 'eol' => 'lf', 'bringit-language' => 'shell' }) + to eq('eol' => 'lf', 'bringit-language' => 'shell') end it 'returns a Hash containing attributes for a file with multiple extensions' do expect(subject.attributes('test.haml.html')). - to eq({ 'bringit-language' => 'haml' }) + to eq('bringit-language' => 'haml') end it 'returns a Hash containing attributes for a file in a directory' do - expect(subject.attributes('foo/bar.txt')).to eq({ 'foo' => true }) + expect(subject.attributes('foo/bar.txt')).to eq('foo' => true) end it 'returns a Hash containing attributes with query string parameters' do expect(subject.attributes('foo.cgi')). - to eq({ 'key' => 'value?p1=v1&p2=v2' }) + to eq('key' => 'value?p1=v1&p2=v2') end it 'returns a Hash containing the attributes for an absolute path' do - expect(subject.attributes('/test.txt')).to eq({ 'text' => true }) + expect(subject.attributes('/test.txt')).to eq('text' => true) end it 'returns a Hash containing the attributes when a pattern is defined using an absolute path' do # When a path is given without a leading slash it should still match # patterns defined with a leading slash. expect(subject.attributes('foo.png')). - to eq({ 'bringit-language' => 'png' }) + to eq('bringit-language' => 'png') expect(subject.attributes('/foo.png')). - to eq({ 'bringit-language' => 'png' }) + to eq('bringit-language' => 'png') end it 'returns an empty Hash for a defined path without attributes' do @@ -75,7 +77,7 @@ it 'parses an entry that uses a tab to separate the pattern and attributes' do expect(subject.patterns[File.join(path, '*.md')]). - to eq({ 'bringit-language' => 'markdown' }) + to eq('bringit-language' => 'markdown') end it 'stores patterns in reverse order' do @@ -101,27 +103,27 @@ describe '#parse_attributes' do it 'parses a boolean attribute' do - expect(subject.parse_attributes('text')).to eq({ 'text' => true }) + expect(subject.parse_attributes('text')).to eq('text' => true) end it 'parses a negated boolean attribute' do - expect(subject.parse_attributes('-text')).to eq({ 'text' => false }) + expect(subject.parse_attributes('-text')).to eq('text' => false) end it 'parses a key-value pair' do - expect(subject.parse_attributes('foo=bar')).to eq({ 'foo' => 'bar' }) + expect(subject.parse_attributes('foo=bar')).to eq('foo' => 'bar') end it 'parses multiple attributes' do input = 'boolean key=value -negated' expect(subject.parse_attributes(input)). - to eq({ 'boolean' => true, 'key' => 'value', 'negated' => false }) + to eq('boolean' => true, 'key' => 'value', 'negated' => false) end it 'parses attributes with query string parameters' do expect(subject.parse_attributes('foo=bar?baz=1')). - to eq({ 'foo' => 'bar?baz=1' }) + to eq('foo' => 'bar?baz=1') end end diff --git a/spec/blame_spec.rb b/spec/blame_spec.rb index 5d0ef4c..d056198 100644 --- a/spec/blame_spec.rb +++ b/spec/blame_spec.rb @@ -1,31 +1,33 @@ -# coding: utf-8 -require "spec_helper" + +# frozen_string_literal: true + +require 'spec_helper' describe Bringit::Blame, seed_helper: true do let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } let(:blame) do - Bringit::Blame.new(repository, SeedRepo::Commit::ID, "CONTRIBUTING.md") + Bringit::Blame.new(repository, SeedRepo::Commit::ID, 'CONTRIBUTING.md') end - context "each count" do + context 'each count' do it do data = [] blame.each do |commit, line| data << { commit: commit, - line: line + line: line, } end expect(data.size).to eq(95) expect(data.first[:commit]).to be_kind_of(Bringit::Commit) - expect(data.first[:line]).to eq("# Contribute to GitLab") + expect(data.first[:line]).to eq('# Contribute to GitLab') end end - context "ISO-8859 encoding" do + context 'ISO-8859 encoding' do let(:blame) do - Bringit::Blame.new(repository, SeedRepo::EncodingCommit::ID, "encoding/iso8859.txt") + Bringit::Blame.new(repository, SeedRepo::EncodingCommit::ID, 'encoding/iso8859.txt') end it 'converts to UTF-8' do @@ -33,19 +35,19 @@ blame.each do |commit, line| data << { commit: commit, - line: line + line: line, } end expect(data.size).to eq(1) expect(data.first[:commit]).to be_kind_of(Bringit::Commit) - expect(data.first[:line]).to eq("Ä ü") + expect(data.first[:line]).to eq('Ä ü') end end - context "unknown encoding" do + context 'unknown encoding' do let(:blame) do - Bringit::Blame.new(repository, SeedRepo::EncodingCommit::ID, "encoding/iso8859.txt") + Bringit::Blame.new(repository, SeedRepo::EncodingCommit::ID, 'encoding/iso8859.txt') end it 'converts to UTF-8' do @@ -53,14 +55,14 @@ data = [] blame.each do |commit, line| data << { - commit: commit, - line: line + commit: commit, + line: line, } end expect(data.size).to eq(1) expect(data.first[:commit]).to be_kind_of(Bringit::Commit) - expect(data.first[:line]).to eq(" ") + expect(data.first[:line]).to eq(' ') end end end diff --git a/spec/blob_snippet_spec.rb b/spec/blob_snippet_spec.rb index 9d53f53..cdc3146 100644 --- a/spec/blob_snippet_spec.rb +++ b/spec/blob_snippet_spec.rb @@ -1,6 +1,6 @@ -# encoding: UTF-8 +# frozen_string_literal: true -require "spec_helper" +require 'spec_helper' describe Bringit::BlobSnippet, seed_helper: true do describe :data do diff --git a/spec/blob_spec.rb b/spec/blob_spec.rb index bc97ed1..8af2e19 100644 --- a/spec/blob_spec.rb +++ b/spec/blob_spec.rb @@ -1,6 +1,6 @@ -# encoding: utf-8 +# frozen_string_literal: true -require "spec_helper" +require 'spec_helper' describe Bringit::Blob, seed_helper: true do let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } @@ -17,44 +17,44 @@ describe :find do context 'file in subdir' do - let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") } + let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, 'files/ruby/popen.rb') } it { expect(blob.id).to eq(SeedRepo::RubyBlob::ID) } it { expect(blob.name).to eq(SeedRepo::RubyBlob::NAME) } - it { expect(blob.path).to eq("files/ruby/popen.rb") } + it { expect(blob.path).to eq('files/ruby/popen.rb') } it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) } it { expect(blob.data[0..10]).to eq(SeedRepo::RubyBlob::CONTENT[0..10]) } it { expect(blob.size).to eq(669) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } end context 'file in root' do - let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, ".gitignore") } + let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, '.gitignore') } - it { expect(blob.id).to eq("dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82") } - it { expect(blob.name).to eq(".gitignore") } - it { expect(blob.path).to eq(".gitignore") } + it { expect(blob.id).to eq('dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82') } + it { expect(blob.name).to eq('.gitignore') } + it { expect(blob.path).to eq('.gitignore') } it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) } it { expect(blob.data[0..10]).to eq("*.rbc\n*.sas") } it { expect(blob.size).to eq(241) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } it { expect(blob).not_to be_binary } end context 'file in root with leading slash' do - let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, "/.gitignore") } + let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, '/.gitignore') } - it { expect(blob.id).to eq("dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82") } - it { expect(blob.name).to eq(".gitignore") } - it { expect(blob.path).to eq(".gitignore") } + it { expect(blob.id).to eq('dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82') } + it { expect(blob.name).to eq('.gitignore') } + it { expect(blob.path).to eq('.gitignore') } it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) } it { expect(blob.data[0..10]).to eq("*.rbc\n*.sas") } it { expect(blob.size).to eq(241) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } end context 'non-exist file' do - let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, "missing.rb") } + let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, 'missing.rb') } it { expect(blob).to be_nil } end @@ -128,34 +128,34 @@ describe 'encoding' do context 'file with russian text' do - let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, "encoding/russian.rb") } + let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, 'encoding/russian.rb') } - it { expect(blob.name).to eq("russian.rb") } - it { expect(blob.data.lines.first).to eq("Хороший файл") } + it { expect(blob.name).to eq('russian.rb') } + it { expect(blob.data.lines.first).to eq('Хороший файл') } it { expect(blob.size).to eq(23) } it { expect(blob.truncated?).to be_falsey } # Run it twice since data is encoded after the first run it { expect(blob.truncated?).to be_falsey } - it { expect(blob.mode).to eq("100755") } + it { expect(blob.mode).to eq('100755') } end context 'file with Chinese text' do - let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, "encoding/テスト.txt") } + let(:blob) { Bringit::Blob.find(repository, SeedRepo::Commit::ID, 'encoding/テスト.txt') } - it { expect(blob.name).to eq("テスト.txt") } - it { expect(blob.data).to include("これはテスト") } + it { expect(blob.name).to eq('テスト.txt') } + it { expect(blob.data).to include('これはテスト') } it { expect(blob.size).to eq(340) } - it { expect(blob.mode).to eq("100755") } + it { expect(blob.mode).to eq('100755') } it { expect(blob.truncated?).to be_falsey } end context 'file with ISO-8859 text' do - let(:blob) { Bringit::Blob.find(repository, SeedRepo::LastCommit::ID, "encoding/iso8859.txt") } + let(:blob) { Bringit::Blob.find(repository, SeedRepo::LastCommit::ID, 'encoding/iso8859.txt') } - it { expect(blob.name).to eq("iso8859.txt") } + it { expect(blob.name).to eq('iso8859.txt') } it { expect(blob.loaded_size).to eq(4) } it { expect(blob.size).to eq(4) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } it { expect(blob.truncated?).to be_falsey } end end @@ -173,7 +173,7 @@ it { expect(blob.name).to eq('regex.rb') } it { expect(blob.path).to eq('files/ruby/regex.rb') } it { expect(blob.size).to eq(1200) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } end context 'file binary' do @@ -188,7 +188,7 @@ it { expect(blob.name).to eq('ls') } it { expect(blob.path).to eq('files/executables/ls') } it { expect(blob.size).to eq(110080) } - it { expect(blob.mode).to eq("100755") } + it { expect(blob.mode).to eq('100755') } end context 'file symlink to regular' do @@ -203,7 +203,7 @@ it { expect(blob.name).to eq('ruby-style-guide.md') } it { expect(blob.path).to eq('files/links/ruby-style-guide.md') } it { expect(blob.size).to eq(31) } - it { expect(blob.mode).to eq("120000") } + it { expect(blob.mode).to eq('120000') } end context 'file symlink to binary' do @@ -218,7 +218,7 @@ it { expect(blob.name).to eq('touch') } it { expect(blob.path).to eq('files/links/touch') } it { expect(blob.size).to eq(20) } - it { expect(blob.mode).to eq("120000") } + it { expect(blob.mode).to eq('120000') } end end @@ -233,13 +233,13 @@ end it { expect(blob.lfs_pointer?).to eq(true) } - it { expect(blob.lfs_oid).to eq("4206f951d2691c78aac4c0ce9f2b23580b2c92cdcc4336e1028742c0274938e0") } - it { expect(blob.lfs_size).to eq("19548") } - it { expect(blob.id).to eq("f4d76af13003d1106be7ac8c5a2a3d37ddf32c2a") } - it { expect(blob.name).to eq("image.jpg") } - it { expect(blob.path).to eq("files/lfs/image.jpg") } + it { expect(blob.lfs_oid).to eq('4206f951d2691c78aac4c0ce9f2b23580b2c92cdcc4336e1028742c0274938e0') } + it { expect(blob.lfs_size).to eq('19548') } + it { expect(blob.id).to eq('f4d76af13003d1106be7ac8c5a2a3d37ddf32c2a') } + it { expect(blob.name).to eq('image.jpg') } + it { expect(blob.path).to eq('files/lfs/image.jpg') } it { expect(blob.size).to eq(130) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } end describe 'file an invalid lfs pointer' do @@ -255,11 +255,11 @@ it { expect(blob.lfs_pointer?).to eq(false) } it { expect(blob.lfs_oid).to eq(nil) } it { expect(blob.lfs_size).to eq(nil) } - it { expect(blob.id).to eq("f8a898db217a5a85ed8b3d25b34c1df1d1094c46") } - it { expect(blob.name).to eq("archive-invalid.tar") } - it { expect(blob.path).to eq("files/lfs/archive-invalid.tar") } + it { expect(blob.id).to eq('f8a898db217a5a85ed8b3d25b34c1df1d1094c46') } + it { expect(blob.name).to eq('archive-invalid.tar') } + it { expect(blob.path).to eq('files/lfs/archive-invalid.tar') } it { expect(blob.size).to eq(43) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } end context 'with correct version header and size but incorrect size and oid' do @@ -273,12 +273,12 @@ it { expect(blob.lfs_pointer?).to eq(false) } it { expect(blob.lfs_oid).to eq(nil) } - it { expect(blob.lfs_size).to eq("1575078") } - it { expect(blob.id).to eq("5ae35296e1f95c1ef9feda1241477ed29a448572") } - it { expect(blob.name).to eq("picture-invalid.png") } - it { expect(blob.path).to eq("files/lfs/picture-invalid.png") } + it { expect(blob.lfs_size).to eq('1575078') } + it { expect(blob.id).to eq('5ae35296e1f95c1ef9feda1241477ed29a448572') } + it { expect(blob.name).to eq('picture-invalid.png') } + it { expect(blob.path).to eq('files/lfs/picture-invalid.png') } it { expect(blob.size).to eq(57) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } end context 'with correct version header and size but invalid size and oid' do @@ -293,11 +293,11 @@ it { expect(blob.lfs_pointer?).to eq(false) } it { expect(blob.lfs_oid).to eq(nil) } it { expect(blob.lfs_size).to eq(nil) } - it { expect(blob.id).to eq("d831981bd876732b85a1bcc6cc01210c9f36248f") } - it { expect(blob.name).to eq("file-invalid.zip") } - it { expect(blob.path).to eq("files/lfs/file-invalid.zip") } + it { expect(blob.id).to eq('d831981bd876732b85a1bcc6cc01210c9f36248f') } + it { expect(blob.name).to eq('file-invalid.zip') } + it { expect(blob.path).to eq('files/lfs/file-invalid.zip') } it { expect(blob.size).to eq(60) } - it { expect(blob.mode).to eq("100644") } + it { expect(blob.mode).to eq('100644') } end end end diff --git a/spec/branch_spec.rb b/spec/branch_spec.rb index ad31229..969d4dd 100644 --- a/spec/branch_spec.rb +++ b/spec/branch_spec.rb @@ -1,4 +1,6 @@ -require "spec_helper" +# frozen_string_literal: true + +require 'spec_helper' describe Bringit::Branch, seed_helper: true do let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } @@ -16,7 +18,7 @@ let(:branch) { repository.branches.first } it { expect(branch.name).to eq(SeedRepo::Repo::BRANCHES.first) } - it { expect(branch.dereferenced_target.sha).to eq("0b4bc9a49b562e85de7cc9e834518ea6828729b9") } + it { expect(branch.dereferenced_target.sha).to eq('0b4bc9a49b562e85de7cc9e834518ea6828729b9') } end describe 'master branch' do diff --git a/spec/commit_spec.rb b/spec/commit_spec.rb index 7329946..6dffee7 100644 --- a/spec/commit_spec.rb +++ b/spec/commit_spec.rb @@ -1,4 +1,6 @@ -require "spec_helper" +# frozen_string_literal: true + +require 'spec_helper' describe Bringit::Commit, seed_helper: true do let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } @@ -7,20 +9,20 @@ repository.rugged.lookup(SeedRepo::Commit::ID) end - describe "Commit info" do + describe 'Commit info' do before do repo = Bringit::Repository.new(TEST_REPO_PATH).rugged @committer = { email: 'mike@smith.com', - name: "Mike Smith", - time: Time.now + name: 'Mike Smith', + time: Time.now, } @author = { email: 'john@smith.com', - name: "John Smith", - time: Time.now + name: 'John Smith', + time: Time.now, } @parents = [repo.head.target] @@ -34,8 +36,8 @@ committer: @committer, tree: @tree, parents: @parents, - message: "Refactoring specs", - update_ref: "HEAD" + message: 'Refactoring specs', + update_ref: 'HEAD' ) @raw_commit = repo.lookup(sha) @@ -55,44 +57,44 @@ it { expect(@commit.different_committer?).to be_truthy } it { expect(@commit.parents).to eq(@bringit_parents) } it { expect(@commit.parent_id).to eq(@parents.first.oid) } - it { expect(@commit.no_commit_message).to eq("--no commit message") } + it { expect(@commit.no_commit_message).to eq('--no commit message') } it { expect(@commit.tree).to eq(@tree) } after do # Erase the new commit so other tests get the original repo repo = Bringit::Repository.new(TEST_REPO_PATH).rugged - repo.references.update("refs/heads/master", SeedRepo::LastCommit::ID) + repo.references.update('refs/heads/master', SeedRepo::LastCommit::ID) end end context 'Class methods' do describe :find do - it "should return first head commit if without params" do + it 'should return first head commit if without params' do expect(Bringit::Commit.last(repository).id).to eq( repository.raw.head.target.oid ) end - it "should return valid commit" do + it 'should return valid commit' do expect(Bringit::Commit.find(repository, SeedRepo::Commit::ID)).to be_valid_commit end - it "should return valid commit for tag" do + it 'should return valid commit for tag' do expect(Bringit::Commit.find(repository, 'v1.0.0').id).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') end - it "should return nil for non-commit ids" do - blob = Bringit::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") + it 'should return nil for non-commit ids' do + blob = Bringit::Blob.find(repository, SeedRepo::Commit::ID, 'files/ruby/popen.rb') expect(Bringit::Commit.find(repository, blob.id)).to be_nil end - it "should return nil for parent of non-commit object" do - blob = Bringit::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") + it 'should return nil for parent of non-commit object' do + blob = Bringit::Blob.find(repository, SeedRepo::Commit::ID, 'files/ruby/popen.rb') expect(Bringit::Commit.find(repository, "#{blob.id}^")).to be_nil end - it "should return nil for nonexisting ids" do - expect(Bringit::Commit.find(repository, "+123_4532530XYZ")).to be_nil + it 'should return nil for nonexisting ids' do + expect(Bringit::Commit.find(repository, '+123_4532530XYZ')).to be_nil end context 'with broken repo' do @@ -133,7 +135,7 @@ end end - describe "where" do + describe 'where' do context 'path is empty string' do subject do commits = Bringit::Commit.where( @@ -143,7 +145,7 @@ limit: 10 ) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 10 elements' do @@ -161,7 +163,7 @@ limit: 10 ) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 10 elements' do @@ -180,33 +182,33 @@ offset: 1 ) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 3 elements' do expect(subject.size).to eq(3) end - it { is_expected.to include("d14d6c0abdd253381df51a723d58691b2ee1ab08") } - it { is_expected.not_to include("eb49186cfa5c4338011f5f590fac11bd66c5c631") } + it { is_expected.to include('d14d6c0abdd253381df51a723d58691b2ee1ab08') } + it { is_expected.not_to include('eb49186cfa5c4338011f5f590fac11bd66c5c631') } end context 'ref is commit id' do subject do commits = Bringit::Commit.where( repo: repository, - ref: "874797c3a73b60d2187ed6e2fcabd289ff75171e", + ref: '874797c3a73b60d2187ed6e2fcabd289ff75171e', path: 'files', limit: 3, offset: 1 ) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 3 elements' do expect(subject.size).to eq(3) end - it { is_expected.to include("2f63565e7aac07bcdadb654e253078b727143ec4") } + it { is_expected.to include('2f63565e7aac07bcdadb654e253078b727143ec4') } it { is_expected.not_to include(SeedRepo::Commit::ID) } end @@ -220,13 +222,13 @@ offset: 1 ) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 3 elements' do expect(subject.size).to eq(3) end - it { is_expected.to include("874797c3a73b60d2187ed6e2fcabd289ff75171e") } + it { is_expected.to include('874797c3a73b60d2187ed6e2fcabd289ff75171e') } it { is_expected.not_to include(SeedRepo::Commit::ID) } end end @@ -234,7 +236,7 @@ describe :between do subject do commits = Bringit::Commit.between(repository, SeedRepo::Commit::PARENT_ID, SeedRepo::Commit::ID) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 1 element' do @@ -252,7 +254,7 @@ max_count: 50 ) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 31 elements' do @@ -272,7 +274,7 @@ skip: 1 ) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 23 elements' do @@ -291,7 +293,7 @@ max_count: 7 ) - commits.map { |c| c.id } + commits.map(&:id) end it 'has 7 elements' do @@ -321,12 +323,12 @@ describe '#id' do subject { super().id } - it { is_expected.to eq(sample_commit_hash[:id])} + it { is_expected.to eq(sample_commit_hash[:id]) } end describe '#message' do subject { super().message } - it { is_expected.to eq(sample_commit_hash[:message])} + it { is_expected.to eq(sample_commit_hash[:message]) } end end @@ -348,7 +350,7 @@ subject { commit.to_diff } it { is_expected.not_to include "From #{SeedRepo::Commit::ID}" } - it { is_expected.to include 'diff --git a/files/ruby/popen.rb b/files/ruby/popen.rb'} + it { is_expected.to include 'diff --git a/files/ruby/popen.rb b/files/ruby/popen.rb' } end describe :has_zero_stats? do @@ -359,7 +361,7 @@ subject { commit.to_patch } it { is_expected.to include "From #{SeedRepo::Commit::ID}" } - it { is_expected.to include 'diff --git a/files/ruby/popen.rb b/files/ruby/popen.rb'} + it { is_expected.to include 'diff --git a/files/ruby/popen.rb b/files/ruby/popen.rb' } end describe :to_hash do @@ -389,8 +391,8 @@ it 'has 1 element' do expect(subject.size).to eq(1) end - it { is_expected.to include("master") } - it { is_expected.not_to include("feature") } + it { is_expected.to include('master') } + it { is_expected.not_to include('feature') } end describe :references do @@ -443,15 +445,15 @@ def sample_commit_hash { - author_email: "dmitriy.zaporozhets@gmail.com", - author_name: "Dmitriy Zaporozhets", - authored_date: "2012-02-27 20:51:12 +0200", - committed_date: "2012-02-27 20:51:12 +0200", - committer_email: "dmitriy.zaporozhets@gmail.com", - committer_name: "Dmitriy Zaporozhets", + author_email: 'dmitriy.zaporozhets@gmail.com', + author_name: 'Dmitriy Zaporozhets', + authored_date: '2012-02-27 20:51:12 +0200', + committed_date: '2012-02-27 20:51:12 +0200', + committer_email: 'dmitriy.zaporozhets@gmail.com', + committer_name: 'Dmitriy Zaporozhets', id: SeedRepo::Commit::ID, - message: "tree css fixes", - parent_ids: ["874797c3a73b60d2187ed6e2fcabd289ff75171e"] + message: 'tree css fixes', + parent_ids: ['874797c3a73b60d2187ed6e2fcabd289ff75171e'], } end end diff --git a/spec/committing_spec.rb b/spec/committing_spec.rb index 9206176..5fb2a7c 100644 --- a/spec/committing_spec.rb +++ b/spec/committing_spec.rb @@ -100,7 +100,7 @@ filepath: filepath2, content: content2, branch: branch) - commit_info[:file].merge!(previous_path: filepath1) + commit_info[:file][:previous_path] = filepath1 subject.rename_and_update_file(commit_info, sha1) end @@ -140,7 +140,7 @@ filepath: filepath2, branch: branch) commit_info[:file].delete(:content) - commit_info[:file].merge!(previous_path: filepath1) + commit_info[:file][:previous_path] = filepath1 subject.rename_file(commit_info, sha1) end @@ -208,7 +208,7 @@ context 'making multiple changes at once' do let(:num_setup_commits) { 6 } - let!(:file_range) { (0 .. num_setup_commits - 1) } + let!(:file_range) { (0..num_setup_commits - 1) } let!(:old_files) { file_range.map { generate(:filepath) } } let!(:old_contents) { file_range.map { generate(:content) } } let!(:setup_commits) do @@ -247,7 +247,7 @@ action: :remove}, {path: new_files[5], - action: :mkdir} + action: :mkdir}, ] subject.commit_multichange(info) end @@ -321,17 +321,17 @@ let(:existing_file_added) { generate(:filepath) } let(:existing_file_removed) { generate(:filepath) } let(:existing_content) do - < e - expect(e.conflicts). - to match([{ancestor: expected_conflict_ancestor, - ours: expected_conflict_ours, - theirs: expected_conflict_theirs, - merge_info: expected_conflict_merge_info}]) - end + new_commit + rescue Bringit::Committing::HeadChangedError => e + expect(e.conflicts). + to match([{ancestor: expected_conflict_ancestor, + ours: expected_conflict_ours, + theirs: expected_conflict_theirs, + merge_info: expected_conflict_merge_info}]) end context 'trying to commit' do before do - begin - new_commit - rescue Bringit::Committing::HeadChangedError - end + new_commit + rescue Bringit::Committing::HeadChangedError end it 'keeps the HEAD of the branch' do diff --git a/spec/compare_spec.rb b/spec/compare_spec.rb index c6572b3..28ca398 100644 --- a/spec/compare_spec.rb +++ b/spec/compare_spec.rb @@ -1,4 +1,6 @@ -require "spec_helper" +# frozen_string_literal: true + +require 'spec_helper' describe Bringit::Compare, seed_helper: true do let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } @@ -67,7 +69,7 @@ end end - describe :same do + describe :same do subject do compare.same end diff --git a/spec/diff_collection_spec.rb b/spec/diff_collection_spec.rb index fdd498c..5d4156c 100644 --- a/spec/diff_collection_spec.rb +++ b/spec/diff_collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Bringit::DiffCollection, seed_helper: true do @@ -298,14 +300,14 @@ describe '#real_size' do subject { super().real_size } - it { is_expected.to eq('0')} + it { is_expected.to eq('0') } end end describe :each do context 'when diff are too large' do let(:collection) do - Bringit::DiffCollection.new([{ diff: 'a' * 204800 }]) + Bringit::DiffCollection.new([{diff: 'a' * 204800}]) end it 'yields Diff instances even when they are too large' do @@ -325,7 +327,7 @@ end context 'when diff is quite large will collapse by default' do - let(:iterator) { [{ diff: 'a' * 20480 }] } + let(:iterator) { [{diff: 'a' * 20480}] } context 'when no collapse is set' do let(:no_collapse) { true } @@ -368,7 +370,7 @@ let(:iterator) { [fake_diff(1, 1)] * 4 } before(:each) do - stub_const('Bringit::DiffCollection::DEFAULT_LIMITS', { max_files: 2, max_lines: max_lines }) + stub_const('Bringit::DiffCollection::DEFAULT_LIMITS', max_files: 2, max_lines: max_lines) end it 'prunes diffs by default even little ones' do @@ -388,12 +390,12 @@ fake_diff(1, 45), fake_diff(1, 45), fake_diff(1, 20480), - fake_diff(1, 1) + fake_diff(1, 1), ] end before(:each) do - stub_const('Bringit::DiffCollection::DEFAULT_LIMITS', { max_files: max_files, max_lines: 80 }) + stub_const('Bringit::DiffCollection::DEFAULT_LIMITS', max_files: max_files, max_lines: 80) end it 'prunes diffs by default even little ones' do @@ -413,12 +415,12 @@ fake_diff(1, 45), fake_diff(1, 45), fake_diff(1, 20480), - fake_diff(1, 1) + fake_diff(1, 1), ] end before(:each) do - stub_const('Bringit::DiffCollection::DEFAULT_LIMITS', { max_files: max_files, max_lines: 80 }) + stub_const('Bringit::DiffCollection::DEFAULT_LIMITS', max_files: max_files, max_lines: 80) end it 'prunes diffs by default even little ones' do @@ -455,6 +457,6 @@ end def fake_diff(line_length, line_count) - { 'diff' => "#{'a' * line_length}\n" * line_count } + {'diff' => "#{'a' * line_length}\n" * line_count} end end diff --git a/spec/diff_spec.rb b/spec/diff_spec.rb index 637d7f2..ca3dcd8 100644 --- a/spec/diff_spec.rb +++ b/spec/diff_spec.rb @@ -1,11 +1,13 @@ -require "spec_helper" +# frozen_string_literal: true + +require 'spec_helper' describe Bringit::Diff, seed_helper: true do let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } before do @raw_diff_hash = { - diff: <&2 @@ -26,8 +28,8 @@ def create_failing_hook(name) ['pre-receive', 'post-receive', 'update'].each do |hook_name| context "when triggering a #{hook_name} hook" do - context "when the hook is successful" do - it "returns success with no errors" do + context 'when the hook is successful' do + it 'returns success with no errors' do create_hook(hook_name) hook = Bringit::Hook.new(hook_name, repository.path) blank = Bringit::BLANK_SHA @@ -39,8 +41,8 @@ def create_failing_hook(name) end end - context "when the hook is unsuccessful" do - it "returns failure with errors" do + context 'when the hook is unsuccessful' do + it 'returns failure with errors' do create_failing_hook(hook_name) hook = Bringit::Hook.new(hook_name, repository.path) blank = Bringit::BLANK_SHA @@ -55,7 +57,7 @@ def create_failing_hook(name) end context "when the hook doesn't exist" do - it "returns success with no errors" do + it 'returns success with no errors' do hook = Bringit::Hook.new('unknown_hook', repository.path) blank = Bringit::BLANK_SHA ref = Bringit::BRANCH_REF_PREFIX + 'new_branch' diff --git a/spec/index_spec.rb b/spec/index_spec.rb index df994b4..57b28d4 100644 --- a/spec/index_spec.rb +++ b/spec/index_spec.rb @@ -1,4 +1,6 @@ -require "base64" +# frozen_string_literal: true + +require 'base64' require 'spec_helper' describe Bringit::Index, seed_helper: true do @@ -13,7 +15,7 @@ let(:options) do { content: 'Lorem ipsum...', - file_path: 'documents/story.txt' + file_path: 'documents/story.txt', } end @@ -70,7 +72,7 @@ describe '#create_dir' do let(:options) do { - file_path: 'newdir' + file_path: 'newdir', } end @@ -109,7 +111,7 @@ let(:options) do { content: 'Lorem ipsum...', - file_path: 'README.md' + file_path: 'README.md', } end @@ -139,7 +141,7 @@ entry = index.get(options[:file_path]) - expect(entry[:mode]).to eq(0100755) + expect(entry[:mode]).to eq(0o100755) end end end @@ -149,7 +151,7 @@ { content: 'Lorem ipsum...', previous_path: 'README.md', - file_path: 'NEWREADME.md' + file_path: 'NEWREADME.md', } end @@ -186,7 +188,7 @@ entry = index.get(options[:file_path]) - expect(entry[:mode]).to eq(0100755) + expect(entry[:mode]).to eq(0o100755) end end end @@ -194,7 +196,7 @@ describe '#delete' do let(:options) do { - file_path: 'README.md' + file_path: 'README.md', } end diff --git a/spec/repository_spec.rb b/spec/repository_spec.rb index a282c3f..6addeb6 100644 --- a/spec/repository_spec.rb +++ b/spec/repository_spec.rb @@ -1,11 +1,13 @@ -require "spec_helper" +# frozen_string_literal: true + +require 'spec_helper' describe Bringit::Repository, seed_helper: true do include Bringit::EncodingHelper let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } - describe "Respond to" do + describe 'Respond to' do subject { repository } it { is_expected.to respond_to(:raw) } @@ -14,7 +16,7 @@ it { is_expected.to respond_to(:tags) } end - describe "#discover_default_branch" do + describe '#discover_default_branch' do let(:master) { 'master' } let(:feature) { 'feature' } let(:feature2) { 'feature2' } @@ -24,24 +26,24 @@ expect(repository.discover_default_branch).to eq('master') end - it "returns non-master when master exists but default branch is set to something else" do + it 'returns non-master when master exists but default branch is set to something else' do File.write(File.join(repository.path, 'HEAD'), 'ref: refs/heads/feature') expect(repository).to receive(:branch_names).at_least(:once).and_return([feature, master]) expect(repository.discover_default_branch).to eq('feature') File.write(File.join(repository.path, 'HEAD'), 'ref: refs/heads/master') end - it "returns a non-master branch when only one exists" do + it 'returns a non-master branch when only one exists' do expect(repository).to receive(:branch_names).at_least(:once).and_return([feature]) expect(repository.discover_default_branch).to eq('feature') end - it "returns a non-master branch when more than one exists and master does not" do + it 'returns a non-master branch when more than one exists and master does not' do expect(repository).to receive(:branch_names).at_least(:once).and_return([feature, feature2]) expect(repository.discover_default_branch).to eq('feature') end - it "returns nil when no branch exists" do + it 'returns nil when no branch exists' do expect(repository).to receive(:branch_names).at_least(:once).and_return([]) expect(repository.discover_default_branch).to be_nil end @@ -53,8 +55,8 @@ it 'has SeedRepo::Repo::BRANCHES.size elements' do expect(subject.size).to eq(SeedRepo::Repo::BRANCHES.size) end - it { is_expected.to include("master") } - it { is_expected.not_to include("branch-from-space") } + it { is_expected.to include('master') } + it { is_expected.not_to include('branch-from-space') } end describe '#tag_names' do @@ -67,10 +69,10 @@ describe '#last' do subject { super().last } - it { is_expected.to eq("v1.2.1") } + it { is_expected.to eq('v1.2.1') } end - it { is_expected.to include("v1.0.0") } - it { is_expected.not_to include("v5.0.0") } + it { is_expected.to include('v1.0.0') } + it { is_expected.not_to include('v5.0.0') } end shared_examples 'archive check' do |extenstion| @@ -79,7 +81,7 @@ end describe '#archive_prefix' do - let(:project_name) { 'project-name'} + let(:project_name) { 'project-name' } before do expect(repository).to receive(:name).once.and_return(project_name) @@ -156,13 +158,13 @@ describe '#name' do subject { super().name } - it { is_expected.to eq("feature") } + it { is_expected.to eq('feature') } end context :commit do subject { heads.first.dereferenced_target.sha } - it { is_expected.to eq("0b4bc9a49b562e85de7cc9e834518ea6828729b9") } + it { is_expected.to eq('0b4bc9a49b562e85de7cc9e834518ea6828729b9') } end end end @@ -215,7 +217,7 @@ describe '#data' do subject { super().data } - it { is_expected.to include "Ability to filter by multiple labels" } + it { is_expected.to include 'Ability to filter by multiple labels' } end end end @@ -232,12 +234,12 @@ it 'should have valid data' do expect(submodule).to eq([ - "six", { - "id" => "409f37c4f05865e4fb208c771485f211a22c4c2d", - "path" => "six", - "url" => "git://github.com/randx/six.git" - } - ]) + 'six', { + 'id' => '409f37c4f05865e4fb208c771485f211a22c4c2d', + 'path' => 'six', + 'url' => 'git://github.com/randx/six.git', + } + ]) end it 'should handle nested submodules correctly' do @@ -267,12 +269,12 @@ submodules = repository.submodules('v1.2.1') expect(submodules.first).to eq([ - "six", { - "id" => "409f37c4f05865e4fb208c771485f211a22c4c2d", - "path" => "six", - "url" => "git://github.com/randx/six.git" - } - ]) + 'six', { + 'id' => '409f37c4f05865e4fb208c771485f211a22c4c2d', + 'path' => 'six', + 'url' => 'git://github.com/randx/six.git', + } + ]) end end @@ -285,57 +287,57 @@ end describe '#commit_count' do - it { expect(repository.commit_count("master")).to eq(25) } - it { expect(repository.commit_count("feature")).to eq(9) } + it { expect(repository.commit_count('master')).to eq(25) } + it { expect(repository.commit_count('feature')).to eq(9) } end - describe "#reset" do - change_path = File.join(TEST_NORMAL_REPO_PATH, "CHANGELOG") - untracked_path = File.join(TEST_NORMAL_REPO_PATH, "UNTRACKED") - tracked_path = File.join(TEST_NORMAL_REPO_PATH, "files", "ruby", "popen.rb") + describe '#reset' do + change_path = File.join(TEST_NORMAL_REPO_PATH, 'CHANGELOG') + untracked_path = File.join(TEST_NORMAL_REPO_PATH, 'UNTRACKED') + tracked_path = File.join(TEST_NORMAL_REPO_PATH, 'files', 'ruby', 'popen.rb') - change_text = "New changelog text" - untracked_text = "This file is untracked" + change_text = 'New changelog text' + untracked_text = 'This file is untracked' reset_commit = SeedRepo::LastCommit::ID - context "--hard" do + context '--hard' do before(:all) do # Modify a tracked file - File.open(change_path, "w") do |f| + File.open(change_path, 'w') do |f| f.write(change_text) end # Add an untracked file to the working directory - File.open(untracked_path, "w") do |f| + File.open(untracked_path, 'w') do |f| f.write(untracked_text) end @normal_repo = Bringit::Repository.new(TEST_NORMAL_REPO_PATH) - @normal_repo.reset("HEAD", :hard) + @normal_repo.reset('HEAD', :hard) end - it "should replace the working directory with the content of the index" do - File.open(change_path, "r") do |f| + it 'should replace the working directory with the content of the index' do + File.open(change_path, 'r') do |f| expect(f.each_line.first).not_to eq(change_text) end - File.open(tracked_path, "r") do |f| + File.open(tracked_path, 'r') do |f| expect(f.each_line.to_a[8]).to include('raise RuntimeError, "System commands') end end - it "should not touch untracked files" do + it 'should not touch untracked files' do expect(File.exist?(untracked_path)).to be_truthy end - it "should move the HEAD to the correct commit" do + it 'should move the HEAD to the correct commit' do new_head = @normal_repo.rugged.head.target.oid expect(new_head).to eq(reset_commit) end - it "should move the tip of the master branch to the correct commit" do - new_tip = @normal_repo.rugged.references["refs/heads/master"]. + it 'should move the tip of the master branch to the correct commit' do + new_tip = @normal_repo.rugged.references['refs/heads/master']. target.oid expect(new_tip).to eq(reset_commit) @@ -349,27 +351,27 @@ end end - describe "#checkout" do - new_branch = "foo_branch" + describe '#checkout' do + new_branch = 'foo_branch' - context "-b" do + context '-b' do before(:all) do @normal_repo = Bringit::Repository.new(TEST_NORMAL_REPO_PATH) - @normal_repo.checkout(new_branch, { b: true }, "origin/feature") + @normal_repo.checkout(new_branch, {b: true}, 'origin/feature') end - it "should create a new branch" do + it 'should create a new branch' do expect(@normal_repo.rugged.branches[new_branch]).not_to be_nil end - it "should move the HEAD to the correct commit" do + it 'should move the HEAD to the correct commit' do expect(@normal_repo.rugged.head.target.oid).to( - eq(@normal_repo.rugged.branches["origin/feature"].target.oid) + eq(@normal_repo.rugged.branches['origin/feature'].target.oid) ) end it "should refresh the repo's #heads collection" do - head_names = @normal_repo.heads.map { |h| h.name } + head_names = @normal_repo.heads.map(&:name) expect(head_names).to include(new_branch) end @@ -379,18 +381,18 @@ end end - context "without -b" do - context "and specifying a nonexistent branch" do - it "should not do anything" do + context 'without -b' do + context 'and specifying a nonexistent branch' do + it 'should not do anything' do normal_repo = Bringit::Repository.new(TEST_NORMAL_REPO_PATH) expect { normal_repo.checkout(new_branch) }.to raise_error(Rugged::ReferenceError) expect(normal_repo.rugged.branches[new_branch]).to be_nil expect(normal_repo.rugged.head.target.oid).to( - eq(normal_repo.rugged.branches["master"].target.oid) + eq(normal_repo.rugged.branches['master'].target.oid) ) - head_names = normal_repo.heads.map { |h| h.name } + head_names = normal_repo.heads.map(&:name) expect(head_names).not_to include(new_branch) end @@ -400,21 +402,21 @@ end end - context "and with a valid branch" do + context 'and with a valid branch' do before(:all) do @normal_repo = Bringit::Repository.new(TEST_NORMAL_REPO_PATH) - @normal_repo.rugged.branches.create("feature", "origin/feature") - @normal_repo.checkout("feature") + @normal_repo.rugged.branches.create('feature', 'origin/feature') + @normal_repo.checkout('feature') end - it "should move the HEAD to the correct commit" do + it 'should move the HEAD to the correct commit' do expect(@normal_repo.rugged.head.target.oid).to( - eq(@normal_repo.rugged.branches["feature"].target.oid) + eq(@normal_repo.rugged.branches['feature'].target.oid) ) end - it "should update the working directory" do - File.open(File.join(TEST_NORMAL_REPO_PATH, ".gitignore"), "r") do |f| + it 'should update the working directory' do + File.open(File.join(TEST_NORMAL_REPO_PATH, '.gitignore'), 'r') do |f| expect(f.read.each_line.to_a).not_to include(".DS_Store\n") end end @@ -427,18 +429,18 @@ end end - describe "#delete_branch" do + describe '#delete_branch' do before(:all) do @repo = Bringit::Repository.new(TEST_MUTABLE_REPO_PATH) - @repo.delete_branch("feature") + @repo.delete_branch('feature') end - it "should remove the branch from the repo" do - expect(@repo.rugged.branches["feature"]).to be_nil + it 'should remove the branch from the repo' do + expect(@repo.rugged.branches['feature']).to be_nil end it "should update the repo's #heads collection" do - expect(@repo.heads).not_to include("feature") + expect(@repo.heads).not_to include('feature') end after(:all) do @@ -447,26 +449,26 @@ end end - describe "#create_branch" do + describe '#create_branch' do before(:all) do @repo = Bringit::Repository.new(TEST_MUTABLE_REPO_PATH) end - it "should create a new branch" do + it 'should create a new branch' do expect(@repo.create_branch('new_branch', 'master')).not_to be_nil end - it "should create a new branch with the right name" do + it 'should create a new branch with the right name' do expect(@repo.create_branch('another_branch', 'master').name).to eq('another_branch') end - it "should fail if we create an existing branch" do + it 'should fail if we create an existing branch' do @repo.create_branch('duplicated_branch', 'master') - expect{@repo.create_branch('duplicated_branch', 'master')}.to raise_error("Branch duplicated_branch already exists") + expect { @repo.create_branch('duplicated_branch', 'master') }.to raise_error('Branch duplicated_branch already exists') end - it "should fail if we create a branch from a non existing ref" do - expect{@repo.create_branch('branch_based_in_wrong_ref', 'master_2_the_revenge')}.to raise_error("Invalid reference master_2_the_revenge") + it 'should fail if we create a branch from a non existing ref' do + expect { @repo.create_branch('branch_based_in_wrong_ref', 'master_2_the_revenge') }.to raise_error('Invalid reference master_2_the_revenge') end after(:all) do @@ -475,33 +477,33 @@ end end - describe "#remote_names" do + describe '#remote_names' do let(:remotes) { repository.remote_names } it "should have one entry: 'origin'" do expect(remotes.size).to eq(1) - expect(remotes.first).to eq("origin") + expect(remotes.first).to eq('origin') end end - describe "#refs_hash" do + describe '#refs_hash' do let(:refs) { repository.refs_hash } - it "should have as many entries as branches and tags" do + it 'should have as many entries as branches and tags' do expected_refs = SeedRepo::Repo::BRANCHES + SeedRepo::Repo::TAGS # We flatten in case a commit is pointed at by more than one branch and/or tag expect(refs.values.flatten.size).to eq(expected_refs.size) end end - describe "#remote_delete" do + describe '#remote_delete' do before(:all) do @repo = Bringit::Repository.new(TEST_MUTABLE_REPO_PATH) - @repo.remote_delete("expendable") + @repo.remote_delete('expendable') end - it "should remove the remote" do - expect(@repo.rugged.remotes).not_to include("expendable") + it 'should remove the remote' do + expect(@repo.rugged.remotes).not_to include('expendable') end after(:all) do @@ -510,14 +512,14 @@ end end - describe "#remote_add" do + describe '#remote_add' do before(:all) do @repo = Bringit::Repository.new(TEST_MUTABLE_REPO_PATH) - @repo.remote_add("new_remote", SeedHelper::GITLAB_URL) + @repo.remote_add('new_remote', SeedHelper::GITLAB_URL) end - it "should add the remote" do - expect(@repo.rugged.remotes.each_name.to_a).to include("new_remote") + it 'should add the remote' do + expect(@repo.rugged.remotes.each_name.to_a).to include('new_remote') end after(:all) do @@ -526,14 +528,14 @@ end end - describe "#remote_update" do + describe '#remote_update' do before(:all) do @repo = Bringit::Repository.new(TEST_MUTABLE_REPO_PATH) - @repo.remote_update("expendable", url: TEST_NORMAL_REPO_PATH) + @repo.remote_update('expendable', url: TEST_NORMAL_REPO_PATH) end - it "should add the remote" do - expect(@repo.rugged.remotes["expendable"].url).to( + it 'should add the remote' do + expect(@repo.rugged.remotes['expendable'].url).to( eq(TEST_NORMAL_REPO_PATH) ) end @@ -544,7 +546,7 @@ end end - describe "#log" do + describe '#log' do commit_with_old_name = nil commit_with_new_name = nil rename_commit = nil @@ -561,15 +563,15 @@ after(:context) do # Erase our commits so other tests get the original repo repo = Bringit::Repository.new(TEST_REPO_PATH).rugged - repo.references.update("refs/heads/master", SeedRepo::LastCommit::ID) + repo.references.update('refs/heads/master', SeedRepo::LastCommit::ID) end context "where 'follow' == true" do - let(:options) { { ref: "master", follow: true } } + let(:options) { {ref: 'master', follow: true} } context "and 'path' is a directory" do - it "does not follow renames" do - log_commits = repository.log(options.merge(path: "encoding")) + it 'does not follow renames' do + log_commits = repository.log(options.merge(path: 'encoding')) aggregate_failures do expect(log_commits).to include(commit_with_new_name) @@ -581,8 +583,8 @@ context "and 'path' is a file that matches the new filename" do context 'without offset' do - it "follows renames" do - log_commits = repository.log(options.merge(path: "encoding/CHANGELOG")) + it 'follows renames' do + log_commits = repository.log(options.merge(path: 'encoding/CHANGELOG')) aggregate_failures do expect(log_commits).to include(commit_with_new_name) @@ -593,8 +595,8 @@ end context 'with offset=1' do - it "follows renames and skip the latest commit" do - log_commits = repository.log(options.merge(path: "encoding/CHANGELOG", offset: 1)) + it 'follows renames and skip the latest commit' do + log_commits = repository.log(options.merge(path: 'encoding/CHANGELOG', offset: 1)) aggregate_failures do expect(log_commits).not_to include(commit_with_new_name) @@ -605,16 +607,16 @@ end context 'with offset=1', 'and limit=1' do - it "follows renames, skip the latest commit and return only one commit" do - log_commits = repository.log(options.merge(path: "encoding/CHANGELOG", offset: 1, limit: 1)) + it 'follows renames, skip the latest commit and return only one commit' do + log_commits = repository.log(options.merge(path: 'encoding/CHANGELOG', offset: 1, limit: 1)) expect(log_commits).to contain_exactly(rename_commit) end end context 'with offset=1', 'and limit=2' do - it "follows renames, skip the latest commit and return only two commits" do - log_commits = repository.log(options.merge(path: "encoding/CHANGELOG", offset: 1, limit: 2)) + it 'follows renames, skip the latest commit and return only two commits' do + log_commits = repository.log(options.merge(path: 'encoding/CHANGELOG', offset: 1, limit: 2)) aggregate_failures do expect(log_commits).to contain_exactly(rename_commit, commit_with_old_name) @@ -623,8 +625,8 @@ end context 'with offset=2' do - it "follows renames and skip the latest commit" do - log_commits = repository.log(options.merge(path: "encoding/CHANGELOG", offset: 2)) + it 'follows renames and skip the latest commit' do + log_commits = repository.log(options.merge(path: 'encoding/CHANGELOG', offset: 2)) aggregate_failures do expect(log_commits).not_to include(commit_with_new_name) @@ -635,16 +637,16 @@ end context 'with offset=2', 'and limit=1' do - it "follows renames, skip the two latest commit and return only one commit" do - log_commits = repository.log(options.merge(path: "encoding/CHANGELOG", offset: 2, limit: 1)) + it 'follows renames, skip the two latest commit and return only one commit' do + log_commits = repository.log(options.merge(path: 'encoding/CHANGELOG', offset: 2, limit: 1)) expect(log_commits).to contain_exactly(commit_with_old_name) end end context 'with offset=2', 'and limit=2' do - it "follows renames, skip the two latest commit and return only one commit" do - log_commits = repository.log(options.merge(path: "encoding/CHANGELOG", offset: 2, limit: 2)) + it 'follows renames, skip the two latest commit and return only one commit' do + log_commits = repository.log(options.merge(path: 'encoding/CHANGELOG', offset: 2, limit: 2)) aggregate_failures do expect(log_commits).not_to include(commit_with_new_name) @@ -656,8 +658,8 @@ end context "and 'path' is a file that matches the old filename" do - it "does not follow renames" do - log_commits = repository.log(options.merge(path: "CHANGELOG")) + it 'does not follow renames' do + log_commits = repository.log(options.merge(path: 'CHANGELOG')) aggregate_failures do expect(log_commits).not_to include(commit_with_new_name) @@ -667,8 +669,8 @@ end end - context "unknown ref" do - it "returns an empty array" do + context 'unknown ref' do + it 'returns an empty array' do log_commits = repository.log(options.merge(ref: 'unknown')) expect(log_commits).to eq([]) @@ -677,14 +679,14 @@ end context "where 'follow' == false" do - options = { follow: false } + options = {follow: false} context "and 'path' is a directory" do let(:log_commits) do - repository.log(options.merge(path: "encoding")) + repository.log(options.merge(path: 'encoding')) end - it "should not follow renames" do + it 'should not follow renames' do expect(log_commits).to include(commit_with_new_name) expect(log_commits).to include(rename_commit) expect(log_commits).not_to include(commit_with_old_name) @@ -693,10 +695,10 @@ context "and 'path' is a file that matches the new filename" do let(:log_commits) do - repository.log(options.merge(path: "encoding/CHANGELOG")) + repository.log(options.merge(path: 'encoding/CHANGELOG')) end - it "should not follow renames" do + it 'should not follow renames' do expect(log_commits).to include(commit_with_new_name) expect(log_commits).to include(rename_commit) expect(log_commits).not_to include(commit_with_old_name) @@ -705,10 +707,10 @@ context "and 'path' is a file that matches the old filename" do let(:log_commits) do - repository.log(options.merge(path: "CHANGELOG")) + repository.log(options.merge(path: 'CHANGELOG')) end - it "should not follow renames" do + it 'should not follow renames' do expect(log_commits).to include(commit_with_old_name) expect(log_commits).to include(rename_commit) expect(log_commits).not_to include(commit_with_new_name) @@ -717,17 +719,17 @@ context "and 'path' includes a directory that used to be a file" do let(:log_commits) do - repository.log(options.merge(ref: "refs/heads/fix-blob-path", path: "files/testdir/file.txt")) + repository.log(options.merge(ref: 'refs/heads/fix-blob-path', path: 'files/testdir/file.txt')) end - it "should return a list of commits" do + it 'should return a list of commits' do expect(log_commits.size).to eq(1) end end end - context "only_commit_sha" do - let(:options) { { ref: "master", only_commit_sha: true } } + context 'only_commit_sha' do + let(:options) { {ref: 'master', only_commit_sha: true} } let(:commits_by_walk) { repository.log(options) } let(:commits_by_shell) { repository.log(options.merge(disable_walk: true)) } @@ -736,62 +738,62 @@ it { expect(commits_by_walk.first).to match(/[a-z0-9]{40}/) } end - context "compare results between log_by_walk and log_by_shell" do - let(:options) { { ref: "master" } } + context 'compare results between log_by_walk and log_by_shell' do + let(:options) { {ref: 'master'} } let(:commits_by_walk) { repository.log(options).map(&:oid) } - let(:commits_by_shell) { repository.log(options.merge({ disable_walk: true })).map(&:oid) } + let(:commits_by_shell) { repository.log(options.merge(disable_walk: true)).map(&:oid) } it { expect(commits_by_walk).to eq(commits_by_shell) } - context "without path" do - context "with limit" do - let(:options) { { ref: "master", limit: 1 } } + context 'without path' do + context 'with limit' do + let(:options) { {ref: 'master', limit: 1} } it { expect(commits_by_walk).to eq(commits_by_shell) } end - context "with offset" do - let(:options) { { ref: "master", offset: 1 } } + context 'with offset' do + let(:options) { {ref: 'master', offset: 1} } it { expect(commits_by_walk).to eq(commits_by_shell) } end - context "with skip_merges" do - let(:options) { { ref: "master", skip_merges: true } } + context 'with skip_merges' do + let(:options) { {ref: 'master', skip_merges: true} } it { expect(commits_by_walk).to eq(commits_by_shell) } end end - context "with root path" do - let(:path) { "/" } + context 'with root path' do + let(:path) { '/' } - context "with limit" do - let(:options) { { ref: "master", limit: 1, path: path } } + context 'with limit' do + let(:options) { {ref: 'master', limit: 1, path: path} } it { expect(commits_by_walk).to eq(commits_by_shell) } end - context "with offset" do - let(:options) { { ref: "master", offset: 1, path: path } } + context 'with offset' do + let(:options) { {ref: 'master', offset: 1, path: path} } it { expect(commits_by_walk).to eq(commits_by_shell) } end - context "with skip_merges" do - let(:options) { { ref: "master", skip_merges: true, path: path } } + context 'with skip_merges' do + let(:options) { {ref: 'master', skip_merges: true, path: path} } it { expect(commits_by_walk).to eq(commits_by_shell) } end end - context "with path" do - let(:options) { { ref: "master", path: "encoding" } } + context 'with path' do + let(:options) { {ref: 'master', path: 'encoding'} } it { expect(commits_by_walk).to eq(commits_by_shell) } - context "with follow" do - let(:options) { { ref: "master", path: "encoding", follow: true } } + context 'with follow' do + let(:options) { {ref: 'master', path: 'encoding', follow: true} } it { expect(commits_by_walk).to eq(commits_by_shell) } end @@ -799,9 +801,9 @@ end context "where provides 'after' timestamp" do - options = { after: Time.iso8601('2014-03-03T20:15:01+00:00') } + options = {after: Time.iso8601('2014-03-03T20:15:01+00:00')} - it "should returns commits on or after that timestamp" do + it 'should returns commits on or after that timestamp' do commits = repository.log(options) expect(commits.size).to be > 0 @@ -812,9 +814,9 @@ end context "where provides 'before' timestamp" do - options = { before: Time.iso8601('2014-03-03T20:15:01+00:00') } + options = {before: Time.iso8601('2014-03-03T20:15:01+00:00')} - it "should returns commits on or before that timestamp" do + it 'should returns commits on or before that timestamp' do commits = repository.log(options) expect(commits.size).to be > 0 @@ -825,7 +827,7 @@ end end - describe "#commits_between" do + describe '#commits_between' do context 'two SHAs' do let(:first_sha) { 'b0e52af38d7ea43cf41d8a6f2471351ac036d6c9' } let(:second_sha) { '0e50ec4d3c7ce42ab74dda1d422cb2cbffe1e326' } @@ -867,7 +869,7 @@ describe '#count_commits' do context 'with after timestamp' do it 'returns the number of commits after timestamp' do - options = { ref: 'master', limit: nil, after: Time.iso8601('2013-03-03T20:15:01+00:00') } + options = {ref: 'master', limit: nil, after: Time.iso8601('2013-03-03T20:15:01+00:00')} expect(repository.count_commits(options)).to eq(25) end @@ -875,7 +877,7 @@ context 'with before timestamp' do it 'returns the number of commits after timestamp' do - options = { ref: 'feature', limit: nil, before: Time.iso8601('2015-03-03T20:15:01+00:00') } + options = {ref: 'feature', limit: nil, before: Time.iso8601('2015-03-03T20:15:01+00:00')} expect(repository.count_commits(options)).to eq(9) end @@ -883,14 +885,14 @@ context 'with path' do it 'returns the number of commits with path ' do - options = { ref: 'master', limit: nil, path: "encoding" } + options = {ref: 'master', limit: nil, path: 'encoding'} expect(repository.count_commits(options)).to eq(2) end end end - describe "branch_names_contains" do + describe 'branch_names_contains' do subject { repository.branch_names_contains(SeedRepo::LastCommit::ID) } it { is_expected.to include('master') } @@ -959,7 +961,7 @@ describe '#branches with deleted branch' do before(:each) do - ref = double() + ref = double allow(ref).to receive(:name) { 'bad-branch' } allow(ref).to receive(:target) { raise Rugged::ReferenceError } allow(repository.rugged).to receive(:branches) { [ref] } @@ -988,44 +990,44 @@ end end - describe "#ls_files" do - let(:master_file_paths) { repository.ls_files("master") } - let(:not_existed_branch) { repository.ls_files("not_existed_branch") } + describe '#ls_files' do + let(:master_file_paths) { repository.ls_files('master') } + let(:not_existed_branch) { repository.ls_files('not_existed_branch') } - it "read every file paths of master branch" do + it 'read every file paths of master branch' do expect(master_file_paths.length).to equal(40) end - it "reads full file paths of master branch" do - expect(master_file_paths).to include("files/html/500.html") + it 'reads full file paths of master branch' do + expect(master_file_paths).to include('files/html/500.html') end - it "dose not read submodule directory and empty directory of master branch" do - expect(master_file_paths).not_to include("six") + it 'dose not read submodule directory and empty directory of master branch' do + expect(master_file_paths).not_to include('six') end it "does not include 'nil'" do expect(master_file_paths).not_to include(nil) end - it "returns empty array when not existed branch" do + it 'returns empty array when not existed branch' do expect(not_existed_branch.length).to equal(0) end end - describe "#copy_gitattributes" do + describe '#copy_gitattributes' do let(:attributes_path) { File.join(TEST_REPO_PATH, 'info/attributes') } - it "raises an error with invalid ref" do - expect { repository.copy_gitattributes("invalid") }.to raise_error(Bringit::Repository::InvalidRef) + it 'raises an error with invalid ref' do + expect { repository.copy_gitattributes('invalid') }.to raise_error(Bringit::Repository::InvalidRef) end - context "with no .gitattrbutes" do + context 'with no .gitattrbutes' do before(:each) do - repository.copy_gitattributes("master") + repository.copy_gitattributes('master') end - it "does not have an info/attributes" do + it 'does not have an info/attributes' do expect(File.exist?(attributes_path)).to be_falsey end @@ -1034,17 +1036,17 @@ end end - context "with .gitattrbutes" do + context 'with .gitattrbutes' do before(:each) do - repository.copy_gitattributes("gitattributes") + repository.copy_gitattributes('gitattributes') end - it "has an info/attributes" do + it 'has an info/attributes' do expect(File.exist?(attributes_path)).to be_truthy end - it "has the same content in info/attributes as .gitattributes" do - contents = File.open(attributes_path, "rb") { |f| f.read } + it 'has the same content in info/attributes as .gitattributes' do + contents = File.open(attributes_path, 'rb', &:read) expect(contents).to eq("*.md binary\n") end @@ -1053,17 +1055,17 @@ end end - context "with updated .gitattrbutes" do + context 'with updated .gitattrbutes' do before(:each) do - repository.copy_gitattributes("gitattributes") - repository.copy_gitattributes("gitattributes-updated") + repository.copy_gitattributes('gitattributes') + repository.copy_gitattributes('gitattributes-updated') end - it "has an info/attributes" do + it 'has an info/attributes' do expect(File.exist?(attributes_path)).to be_truthy end - it "has the updated content in info/attributes" do + it 'has the updated content in info/attributes' do contents = File.read(attributes_path) expect(contents).to eq("*.txt binary\n") end @@ -1073,13 +1075,13 @@ end end - context "with no .gitattrbutes in HEAD but with previous info/attributes" do + context 'with no .gitattrbutes in HEAD but with previous info/attributes' do before(:each) do - repository.copy_gitattributes("gitattributes") - repository.copy_gitattributes("master") + repository.copy_gitattributes('gitattributes') + repository.copy_gitattributes('master') end - it "does not have an info/attributes" do + it 'does not have an info/attributes' do expect(File.exist?(attributes_path)).to be_falsey end @@ -1098,7 +1100,7 @@ File.write(attributes_path, "*.md -diff\n") end - it "should return true for files which are text and do not have attributes" do + it 'should return true for files which are text and do not have attributes' do blob = Bringit::Blob.find( repository, '33bcff41c232a11727ac6d660bd4b0c2ba86d63d', @@ -1107,7 +1109,7 @@ expect(repository.diffable?(blob)).to be_truthy end - it "should return false for binary files which do not have attributes" do + it 'should return false for binary files which do not have attributes' do blob = Bringit::Blob.find( repository, '33bcff41c232a11727ac6d660bd4b0c2ba86d63d', @@ -1116,7 +1118,7 @@ expect(repository.diffable?(blob)).to be_falsey end - it "should return false for text files which have been marked as not being diffable in attributes" do + it 'should return false for text files which have been marked as not being diffable in attributes' do blob = Bringit::Blob.find( repository, '33bcff41c232a11727ac6d660bd4b0c2ba86d63d', @@ -1186,18 +1188,18 @@ def commit_options(repo, index, message) options = {} options[:tree] = index.write_tree(repo) options[:author] = { - email: "test@example.com", - name: "Test Author", - time: Time.gm(2014, "mar", 3, 20, 15, 1) + email: 'test@example.com', + name: 'Test Author', + time: Time.gm(2014, 'mar', 3, 20, 15, 1), } options[:committer] = { - email: "test@example.com", - name: "Test Author", - time: Time.gm(2014, "mar", 3, 20, 15, 1) + email: 'test@example.com', + name: 'Test Author', + time: Time.gm(2014, 'mar', 3, 20, 15, 1), } options[:message] ||= message options[:parents] = repo.empty? ? [] : [repo.head.target].compact - options[:update_ref] = "HEAD" + options[:update_ref] = 'HEAD' options end @@ -1205,15 +1207,15 @@ def commit_options(repo, index, message) # Writes a new commit to the repo and returns a Rugged::Commit. Replaces the # contents of CHANGELOG with a single new line of text. def new_commit_edit_old_file(repo) - oid = repo.write("I replaced the changelog with this text", :blob) + oid = repo.write('I replaced the changelog with this text', :blob) index = repo.index index.read_tree(repo.head.target.tree) - index.add(path: "CHANGELOG", oid: oid, mode: 0100644) + index.add(path: 'CHANGELOG', oid: oid, mode: 0o100644) options = commit_options( repo, index, - "Edit CHANGELOG in its original location" + 'Edit CHANGELOG in its original location' ) sha = Rugged::Commit.create(repo, options) @@ -1226,9 +1228,9 @@ def new_commit_edit_new_file(repo) oid = repo.write("I'm a new changelog with different text", :blob) index = repo.index index.read_tree(repo.head.target.tree) - index.add(path: "encoding/CHANGELOG", oid: oid, mode: 0100644) + index.add(path: 'encoding/CHANGELOG', oid: oid, mode: 0o100644) - options = commit_options(repo, index, "Edit encoding/CHANGELOG") + options = commit_options(repo, index, 'Edit encoding/CHANGELOG') sha = Rugged::Commit.create(repo, options) repo.lookup(sha) @@ -1237,15 +1239,15 @@ def new_commit_edit_new_file(repo) # Writes a new commit to the repo and returns a Rugged::Commit. Moves the # CHANGELOG file to the encoding/ directory. def new_commit_move_file(repo) - blob_oid = repo.head.target.tree.detect { |i| i[:name] == "CHANGELOG" }[:oid] + blob_oid = repo.head.target.tree.detect { |i| i[:name] == 'CHANGELOG' }[:oid] file_content = repo.lookup(blob_oid).content oid = repo.write(file_content, :blob) index = repo.index index.read_tree(repo.head.target.tree) - index.add(path: "encoding/CHANGELOG", oid: oid, mode: 0100644) - index.remove("CHANGELOG") + index.add(path: 'encoding/CHANGELOG', oid: oid, mode: 0o100644) + index.remove('CHANGELOG') - options = commit_options(repo, index, "Move CHANGELOG to encoding/") + options = commit_options(repo, index, 'Move CHANGELOG to encoding/') sha = Rugged::Commit.create(repo, options) repo.lookup(sha) diff --git a/spec/rev_list_spec.rb b/spec/rev_list_spec.rb index bdac030..0d25b54 100644 --- a/spec/rev_list_spec.rb +++ b/spec/rev_list_spec.rb @@ -1,34 +1,36 @@ +# frozen_string_literal: true + require 'spec_helper' describe Bringit::RevList, seed_helper: true do let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } - context "validations" do + context 'validations' do described_class::ALLOWED_VARIABLES.each do |var| context var do - it "accepts values starting with the repository path" do - env = { var => "#{repository.path}/objects" } + it 'accepts values starting with the repository path' do + env = {var => "#{repository.path}/objects"} rev_list = described_class.new('oldrev', 'newrev', repository: repository, env: env) expect(rev_list).to be_valid end - it "rejects values starting not with the repository repo path" do - env = { var => "/some/other/path" } + it 'rejects values starting not with the repository repo path' do + env = {var => '/some/other/path'} rev_list = described_class.new('oldrev', 'newrev', repository: repository, env: env) expect(rev_list).not_to be_valid end - it "rejects values containing the repository path but not starting with it" do - env = { var => "/some/other/path/#{repository.path}" } + it 'rejects values containing the repository path but not starting with it' do + env = {var => "/some/other/path/#{repository.path}"} rev_list = described_class.new('oldrev', 'newrev', repository: repository, env: env) expect(rev_list).not_to be_valid end - it "ignores nil values" do - env = { var => nil } + it 'ignores nil values' do + env = {var => nil} rev_list = described_class.new('oldrev', 'newrev', repository: repository, env: env) expect(rev_list).to be_valid @@ -37,11 +39,11 @@ end end - context "#execute" do - let(:env) { { "GIT_OBJECT_DIRECTORY" => repository.path } } + context '#execute' do + let(:env) { {'GIT_OBJECT_DIRECTORY' => repository.path} } let(:rev_list) { Bringit::RevList.new('oldrev', 'newrev', repository: repository, env: env) } - it "calls out to `popen` without environment variables if the record is invalid" do + it 'calls out to `popen` without environment variables if the record is invalid' do allow(rev_list).to receive(:valid?).and_return(false) expect(Open3).to receive(:popen3).with(hash_excluding(env), any_args) @@ -49,7 +51,7 @@ rev_list.execute end - it "calls out to `popen` with environment variables if the record is valid" do + it 'calls out to `popen` with environment variables if the record is valid' do allow(rev_list).to receive(:valid?).and_return(true) expect(Open3).to receive(:popen3).with(hash_including(env), any_args) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 977400b..fbb6864 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if RUBY_ENGINE == 'ruby' # not 'rbx' require 'simplecov' SimpleCov.start @@ -9,7 +11,7 @@ require 'pry' require 'fuubar' -Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f } +Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f } RSpec.configure do |config| config.run_all_when_everything_filtered = true diff --git a/spec/support/matchers/be_valid_commit.rb b/spec/support/matchers/be_valid_commit.rb index 3696e4d..b59339d 100644 --- a/spec/support/matchers/be_valid_commit.rb +++ b/spec/support/matchers/be_valid_commit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec::Matchers.define :be_valid_commit do match do |actual| actual && diff --git a/spec/support/seed_helper.rb b/spec/support/seed_helper.rb index 84f3772..8d705d5 100644 --- a/spec/support/seed_helper.rb +++ b/spec/support/seed_helper.rb @@ -1,18 +1,18 @@ +# frozen_string_literal: true + # This file is specific to specs in spec/lib/gitlab/git/ SEED_REPOSITORY_PATH = File.expand_path('../../tmp/repositories', __dir__) TEST_REPO_PATH = File.join(SEED_REPOSITORY_PATH, 'gitlab-git-test.git') -TEST_NORMAL_REPO_PATH = File.join(SEED_REPOSITORY_PATH, "not-bare-repo.git") -TEST_MUTABLE_REPO_PATH = File.join(SEED_REPOSITORY_PATH, "mutable-repo.git") -TEST_BROKEN_REPO_PATH = File.join(SEED_REPOSITORY_PATH, "broken-repo.git") +TEST_NORMAL_REPO_PATH = File.join(SEED_REPOSITORY_PATH, 'not-bare-repo.git') +TEST_MUTABLE_REPO_PATH = File.join(SEED_REPOSITORY_PATH, 'mutable-repo.git') +TEST_BROKEN_REPO_PATH = File.join(SEED_REPOSITORY_PATH, 'broken-repo.git') module SeedHelper - GITLAB_URL = "https://gitlab.com/gitlab-org/gitlab-git-test.git" + GITLAB_URL = 'https://gitlab.com/gitlab-org/gitlab-git-test.git' def ensure_seeds - if File.exist?(SEED_REPOSITORY_PATH) - FileUtils.rm_r(SEED_REPOSITORY_PATH) - end + FileUtils.rm_r(SEED_REPOSITORY_PATH) if File.exist?(SEED_REPOSITORY_PATH) FileUtils.mkdir_p(SEED_REPOSITORY_PATH) @@ -25,32 +25,32 @@ def ensure_seeds end def create_bare_seeds - system(git_env, *%W(git clone --bare #{GITLAB_URL}), + system(git_env, 'git', 'clone', '--bare', GITLAB_URL.to_s, chdir: SEED_REPOSITORY_PATH, out: '/dev/null', err: '/dev/null') end def create_normal_seeds - system(git_env, *%W(git clone #{TEST_REPO_PATH} #{TEST_NORMAL_REPO_PATH}), + system(git_env, 'git', 'clone', TEST_REPO_PATH.to_s, TEST_NORMAL_REPO_PATH.to_s, out: '/dev/null', err: '/dev/null') end def create_mutable_seeds - system(git_env, *%W(git clone #{TEST_REPO_PATH} #{TEST_MUTABLE_REPO_PATH}), + system(git_env, 'git', 'clone', TEST_REPO_PATH.to_s, TEST_MUTABLE_REPO_PATH.to_s, out: '/dev/null', err: '/dev/null') - system(git_env, *%w(git branch -t feature origin/feature), + system(git_env, 'git', 'branch', '-t', 'feature', 'origin/feature', chdir: TEST_MUTABLE_REPO_PATH, out: '/dev/null', err: '/dev/null') - system(git_env, *%W(git remote add expendable #{GITLAB_URL}), + system(git_env, 'git', 'remote', 'add', 'expendable', GITLAB_URL.to_s, chdir: TEST_MUTABLE_REPO_PATH, out: '/dev/null', err: '/dev/null') end def create_broken_seeds - system(git_env, *%W(git clone --bare #{TEST_REPO_PATH} #{TEST_BROKEN_REPO_PATH}), + system(git_env, 'git', 'clone', '--bare', TEST_REPO_PATH.to_s, TEST_BROKEN_REPO_PATH.to_s, out: '/dev/null', err: '/dev/null') @@ -65,21 +65,21 @@ def create_git_attributes FileUtils.mkdir_p(dir) File.open(File.join(dir, 'attributes'), 'w') do |handle| - handle.write <<-EOF.strip -# This is a comment, it should be ignored. - -*.txt text -*.jpg -text -*.sh eol=lf bringit-language=shell -*.haml.* bringit-language=haml -foo/bar.* foo -*.cgi key=value?p1=v1&p2=v2 -/*.png bringit-language=png -*.binary binary - -# This uses a tab instead of spaces to ensure the parser also supports this. -*.md\tbringit-language=markdown -bla/bla.txt + handle.write <<~EOF.strip + # This is a comment, it should be ignored. + + *.txt text + *.jpg -text + *.sh eol=lf bringit-language=shell + *.haml.* bringit-language=haml + foo/bar.* foo + *.cgi key=value?p1=v1&p2=v2 + /*.png bringit-language=png + *.binary binary + + # This uses a tab instead of spaces to ensure the parser also supports this. + *.md\tbringit-language=markdown + bla/bla.txt EOF end end @@ -99,7 +99,7 @@ def create_invalid_git_attributes # Prevent developer git configurations from being persisted to test # repositories def git_env - { 'GIT_TEMPLATE_DIR' => '' } + {'GIT_TEMPLATE_DIR' => ''} end end diff --git a/spec/support/seed_repo.rb b/spec/support/seed_repo.rb index 9f2cd7c..4a7bdc1 100644 --- a/spec/support/seed_repo.rb +++ b/spec/support/seed_repo.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Seed repo: # 0e50ec4d3c7ce42ab74dda1d422cb2cbffe1e326 Merge branch 'lfs_pointers' into 'master' # 33bcff41c232a11727ac6d660bd4b0c2ba86d63d Add valid and invalid lfs pointers @@ -25,65 +27,65 @@ module SeedRepo module BigCommit - ID = "913c66a37b4a45b9769037c55c2d238bd0942d2e" - PARENT_ID = "cfe32cf61b73a0d5e9f13e774abde7ff789b1660" - MESSAGE = "Files, encoding and much more" - AUTHOR_FULL_NAME = "Dmitriy Zaporozhets" + ID = '913c66a37b4a45b9769037c55c2d238bd0942d2e' + PARENT_ID = 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660' + MESSAGE = 'Files, encoding and much more' + AUTHOR_FULL_NAME = 'Dmitriy Zaporozhets' FILES_COUNT = 2 end module Commit - ID = "570e7b2abdd848b95f2f578043fc23bd6f6fd24d" - PARENT_ID = "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9" + ID = '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' + PARENT_ID = '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9' MESSAGE = "Change some files\n\nSigned-off-by: Dmitriy Zaporozhets \n" - AUTHOR_FULL_NAME = "Dmitriy Zaporozhets" - FILES = ["files/ruby/popen.rb", "files/ruby/regex.rb"] + AUTHOR_FULL_NAME = 'Dmitriy Zaporozhets' + FILES = ['files/ruby/popen.rb', 'files/ruby/regex.rb'].freeze FILES_COUNT = 2 - C_FILE_PATH = "files/ruby" - C_FILES = ["popen.rb", "regex.rb", "version_info.rb"] - BLOB_FILE = %{%h3= @key.title\n%hr\n%pre= @key.key\n.actions\n = link_to 'Remove', @key, :confirm => 'Are you sure?', :method => :delete, :class => \"btn danger delete-key\"\n\n\n} - BLOB_FILE_PATH = "app/views/keys/show.html.haml" + C_FILE_PATH = 'files/ruby' + C_FILES = ['popen.rb', 'regex.rb', 'version_info.rb'].freeze + BLOB_FILE = %(%h3= @key.title\n%hr\n%pre= @key.key\n.actions\n = link_to 'Remove', @key, :confirm => 'Are you sure?', :method => :delete, :class => \"btn danger delete-key\"\n\n\n) + BLOB_FILE_PATH = 'app/views/keys/show.html.haml' end module EmptyCommit - ID = "b0e52af38d7ea43cf41d8a6f2471351ac036d6c9" - PARENT_ID = "40f4a7a617393735a95a0bb67b08385bc1e7c66d" - MESSAGE = "Empty commit" - AUTHOR_FULL_NAME = "Rémy Coutable" - FILES = [] + ID = 'b0e52af38d7ea43cf41d8a6f2471351ac036d6c9' + PARENT_ID = '40f4a7a617393735a95a0bb67b08385bc1e7c66d' + MESSAGE = 'Empty commit' + AUTHOR_FULL_NAME = 'Rémy Coutable' + FILES = [].freeze FILES_COUNT = FILES.count end module EncodingCommit - ID = "40f4a7a617393735a95a0bb67b08385bc1e7c66d" - PARENT_ID = "66028349a123e695b589e09a36634d976edcc5e8" - MESSAGE = "Add ISO-8859-encoded file" - AUTHOR_FULL_NAME = "Stan Hu" - FILES = ["encoding/iso8859.txt"] + ID = '40f4a7a617393735a95a0bb67b08385bc1e7c66d' + PARENT_ID = '66028349a123e695b589e09a36634d976edcc5e8' + MESSAGE = 'Add ISO-8859-encoded file' + AUTHOR_FULL_NAME = 'Stan Hu' + FILES = ['encoding/iso8859.txt'].freeze FILES_COUNT = FILES.count end module FirstCommit - ID = "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863" + ID = '1a0b36b3cdad1d2ee32457c102a8c0b7056fa863' PARENT_ID = nil - MESSAGE = "Initial commit" - AUTHOR_FULL_NAME = "Dmitriy Zaporozhets" - FILES = ["LICENSE", ".gitignore", "README.md"] + MESSAGE = 'Initial commit' + AUTHOR_FULL_NAME = 'Dmitriy Zaporozhets' + FILES = ['LICENSE', '.gitignore', 'README.md'].freeze FILES_COUNT = 3 end module LastCommit - ID = "4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6" - PARENT_ID = "0e1b353b348f8477bdbec1ef47087171c5032cd9" + ID = '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' + PARENT_ID = '0e1b353b348f8477bdbec1ef47087171c5032cd9' MESSAGE = "Merge branch 'master' into 'master'" - AUTHOR_FULL_NAME = "Stan Hu" - FILES = ["bin/executable"] + AUTHOR_FULL_NAME = 'Stan Hu' + FILES = ['bin/executable'].freeze FILES_COUNT = FILES.count end module Repo - HEAD = "master" - BRANCHES = %w[ + HEAD = 'master' + BRANCHES = %w( feature fix fix-blob-path @@ -93,51 +95,51 @@ module Repo gitattributes-updated master merge-test - ] - TAGS = %w[v1.0.0 v1.1.0 v1.2.0 v1.2.1] + ).freeze + TAGS = %w(v1.0.0 v1.1.0 v1.2.0 v1.2.1).freeze end module RubyBlob - ID = "7e3e39ebb9b2bf433b4ad17313770fbe4051649c" - NAME = "popen.rb" - CONTENT = <<-eos -require 'fileutils' -require 'open3' - -module Popen - extend self - - def popen(cmd, path=nil) - unless cmd.is_a?(Array) - raise RuntimeError, "System commands must be given as an array of strings" - end - - path ||= Dir.pwd - - vars = { - "PWD" => path - } - - options = { - chdir: path - } - - unless File.directory?(path) - FileUtils.mkdir_p(path) - end - - @cmd_output = "" - @cmd_status = 0 - - Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| - @cmd_output << stdout.read - @cmd_output << stderr.read - @cmd_status = wait_thr.value.exitstatus - end - - return @cmd_output, @cmd_status - end -end + ID = '7e3e39ebb9b2bf433b4ad17313770fbe4051649c' + NAME = 'popen.rb' + CONTENT = <<~eos + require 'fileutils' + require 'open3' + + module Popen + extend self + + def popen(cmd, path=nil) + unless cmd.is_a?(Array) + raise RuntimeError, "System commands must be given as an array of strings" + end + + path ||= Dir.pwd + + vars = { + "PWD" => path + } + + options = { + chdir: path + } + + unless File.directory?(path) + FileUtils.mkdir_p(path) + end + + @cmd_output = "" + @cmd_status = 0 + + Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| + @cmd_output << stdout.read + @cmd_output << stderr.read + @cmd_status = wait_thr.value.exitstatus + end + + return @cmd_output, @cmd_status + end + end eos end end diff --git a/spec/tag_spec.rb b/spec/tag_spec.rb index e5a27da..ad35675 100644 --- a/spec/tag_spec.rb +++ b/spec/tag_spec.rb @@ -1,4 +1,6 @@ -require "spec_helper" +# frozen_string_literal: true + +require 'spec_helper' describe Bringit::Tag, seed_helper: true do let(:repository) { Bringit::Repository.new(TEST_REPO_PATH) } @@ -6,19 +8,19 @@ describe 'first tag' do let(:tag) { repository.tags.first } - it { expect(tag.name).to eq("v1.0.0") } - it { expect(tag.target).to eq("f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8") } - it { expect(tag.dereferenced_target.sha).to eq("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") } - it { expect(tag.message).to eq("Release") } + it { expect(tag.name).to eq('v1.0.0') } + it { expect(tag.target).to eq('f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8') } + it { expect(tag.dereferenced_target.sha).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } + it { expect(tag.message).to eq('Release') } end describe 'last tag' do let(:tag) { repository.tags.last } - it { expect(tag.name).to eq("v1.2.1") } - it { expect(tag.target).to eq("2ac1f24e253e08135507d0830508febaaccf02ee") } - it { expect(tag.dereferenced_target.sha).to eq("fa1b1e6c004a68b7d8763b86455da9e6b23e36d6") } - it { expect(tag.message).to eq("Version 1.2.1") } + it { expect(tag.name).to eq('v1.2.1') } + it { expect(tag.target).to eq('2ac1f24e253e08135507d0830508febaaccf02ee') } + it { expect(tag.dereferenced_target.sha).to eq('fa1b1e6c004a68b7d8763b86455da9e6b23e36d6') } + it { expect(tag.message).to eq('Version 1.2.1') } end describe 'find' do diff --git a/spec/tree_spec.rb b/spec/tree_spec.rb index e291066..516e4f7 100644 --- a/spec/tree_spec.rb +++ b/spec/tree_spec.rb @@ -1,4 +1,6 @@ -require "spec_helper" +# frozen_string_literal: true + +require 'spec_helper' describe Bringit::Tree, seed_helper: true do context :repo do diff --git a/spec/util_spec.rb b/spec/util_spec.rb index 3d8e925..181aa68 100644 --- a/spec/util_spec.rb +++ b/spec/util_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'spec_helper' describe Bringit::Util do describe :count_lines do [ - ["", 0], - ["foo", 1], + ['', 0], + ['foo', 1], ["foo\n", 1], ["foo\n\n", 2], ].each do |string, line_count| diff --git a/spec/wrapper_spec.rb b/spec/wrapper_spec.rb index 9855fed..2ae36a1 100644 --- a/spec/wrapper_spec.rb +++ b/spec/wrapper_spec.rb @@ -431,10 +431,8 @@ it 'has the correct number of branches' do expect do - begin - subject.create_branch("#{name}.", branch) - rescue Bringit::InvalidRefName - end + subject.create_branch("#{name}.", branch) + rescue Bringit::InvalidRefName end.not_to(change { subject.branches.size }) end end @@ -594,10 +592,8 @@ it 'has the correct number of tags' do expect do - begin - subject.create_tag("#{name}.", branch) - rescue Bringit::InvalidRefName - end + subject.create_tag("#{name}.", branch) + rescue Bringit::InvalidRefName end.not_to(change { subject.tags.size }) end end @@ -633,7 +629,7 @@ FactoryBot.create(:git_commit_info)[:author] end before do - subject.create_tag(name, branch, {message: message, tagger: tagger}) + subject.create_tag(name, branch, message: message, tagger: tagger) end it_behaves_like 'a valid tag' do @@ -717,7 +713,7 @@ context 'diff' do let(:num_setup_commits) { 6 } - let!(:file_range) { (0 .. num_setup_commits - 1) } + let!(:file_range) { (0..num_setup_commits - 1) } let!(:old_files) { file_range.map { generate(:filepath) } } let!(:old_contents) { file_range.map { generate(:content) } } let!(:setup_commits) do @@ -763,7 +759,7 @@ end context 'with nil revisions' do - it "is empty if both revisions are nil" do + it 'is empty if both revisions are nil' do expect(subject.diff(nil, nil)).to be_empty end @@ -810,7 +806,7 @@ context 'with paths' do context 'from root' do let(:diffs) do - subject.diff(nil, setup_commits.last, {}, *(old_files[0..3])) + subject.diff(nil, setup_commits.last, {}, *old_files[0..3]) end it 'is of the correct class' do @@ -831,7 +827,7 @@ context 'from a commit' do let(:diffs) do subject.diff(setup_commits.first, setup_commits.last, {}, - *(old_files[0..3])) + *old_files[0..3]) end it 'is of the correct class' do @@ -891,7 +887,7 @@ context 'log' do let(:num_setup_commits) { 6 } - let!(:file_range) { (0 .. num_setup_commits - 1) } + let!(:file_range) { (0..num_setup_commits - 1) } let!(:old_files) { file_range.map { generate(:filepath) } } let!(:old_contents) { file_range.map { generate(:content) } } let!(:setup_commits) do