rubycritic icon indicating copy to clipboard operation
rubycritic copied to clipboard

Update references to 'master' in codebase

Open nunosilva800 opened this issue 4 years ago • 9 comments

Example:

https://github.com/whitesmith/rubycritic/blob/d673a2c75e4fb1d7f6776b77c63401a4aedf0112/lib/rubycritic/cli/options/file.rb#L41

The new default should be main.

nunosilva800 avatar Jan 26 '21 08:01 nunosilva800

@nunosilva800 Can I work on the issue?

96RadhikaJadhav avatar Jan 26 '21 15:01 96RadhikaJadhav

@nunosilva800 Can I work on the issue?

Of course, be my guest! 😄

nunosilva800 avatar Jan 26 '21 18:01 nunosilva800

@nunosilva800 All the instances of master should be changed to main? There are around 37 instances of it in 14 files. Or else you can specify the files where it needs to be changed.

96RadhikaJadhav avatar Jan 27 '21 13:01 96RadhikaJadhav

It's not a find all and replace kind of thing I'm afraid.

The ones I know that should changes are:

  • mentions to the master branch in documentation
  • the default value for the flag -b / --branch

anything else can probably remain as master, but feel free to propose a change in a PR where it can be analysed and discussed properly :)

nunosilva800 avatar Jan 28 '21 08:01 nunosilva800

I wonder if there is a "smarter way" to find the base branch for the project that is using rubycritic.

I see that we are using master in these files:

  • https://github.com/whitesmith/rubycritic/blob/d673a2c75e4fb1d7f6776b77c63401a4aedf0112/lib/rubycritic/cli/options/argv.rb#L79-L84
  • https://github.com/whitesmith/rubycritic/blob/d673a2c75e4fb1d7f6776b77c63401a4aedf0112/lib/rubycritic/cli/options/file.rb#L40-L44

Not sure if changing that to main is going to cause a lot of headaches for people using RubyCritic.

Either way, this change will require us to release a new major or minor release. Probably minor should be enough.

etagwerker avatar Jan 28 '21 15:01 etagwerker

Yes, it would be a major one. Possibly even the release that removes support for older ruby versions and adds ruby3.

nunosilva800 avatar Jan 28 '21 15:01 nunosilva800

@nunosilva800 Good point. Now that you mentioned that, I got things started over here: https://github.com/whitesmith/rubycritic/pull/385 👍

etagwerker avatar Jan 28 '21 15:01 etagwerker

Hello @nunosilva800 @etagwerker I think this can be addressed while maintaining backward compatibility. Adding an example here as a comment, if it's found suitable i'll put up a PR.

# lib/rubycritic/cli/options
# frozen_string_literal: true

require 'yaml'

module RubyCritic
  module Cli
    class Options
      class Argv
        def parse
         ...
           opts.on('-m', '--mode-ci [BASE_BRANCH]',
                         'Use CI mode (faster, analyses diffs w.r.t base_branch (default: main))') do |branch|
              self.base_branch = branch || SourceControlSystem::Git.main_branch
              set_current_branch
              self.mode = :ci
           end
        end
       end
      end
    end
# lib/rubycritic/source_contro_systems/git.rb
# frozen_string_literal: true

require 'tty/which'
require 'rubycritic/source_control_systems/git/churn'

module RubyCritic
module SourceControlSystem
    class Git < Base
    ...
      def self.main_branch
        is_main = `([ -n "$(git rev-parse --verify --quiet main)" ] && echo 'main')`
        is_master = `([ -n "$(git rev-parse --verify --quiet master)" ] && echo 'master')`
        is_main || is_master
      end
    end

tcarac avatar Jul 23 '22 11:07 tcarac

@tcarac I see where that is going, and I like it :D

nunosilva800 avatar Jul 25 '22 09:07 nunosilva800