Skip to content

Commit e1fff46

Browse files
committed
Auto-correct rubocop
1 parent 922e588 commit e1fff46

36 files changed

+237
-206
lines changed

Gemfile

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
# frozen_string_literal: true
12
source "https://rubygems.org"
23

3-
ruby '2.7.2'
4+
ruby "2.7.2"
45

56
# None of these can actually be used in a development copy of dev
67
# They are all for CI and tests
78
# `dev` uses no gems
89

910
group :development, :test do
10-
gem 'rubocop'
11-
gem 'rubocop-performance'
11+
gem "rubocop"
12+
gem "rubocop-performance"
1213
gem "rubocop-shopify", require: false
13-
gem 'rake'
14+
gem "rake"
1415
end
1516

1617
group :test do
17-
gem 'mocha', require: false
18-
gem 'minitest', '>= 5.0.0', require: false
19-
gem 'minitest-reporters', require: false
18+
gem "mocha", require: false
19+
gem "minitest", ">= 5.0.0", require: false
20+
gem "minitest-reporters", require: false
2021
end

Rakefile

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
require File.expand_path('../vendor/bootstrap.rb', __FILE__)
1+
# frozen_string_literal: true
2+
require File.expand_path("../vendor/bootstrap.rb", __FILE__)
23

3-
require 'rake'
4-
require 'rake/testtask'
4+
require "rake"
5+
require "rake/testtask"
56

67
Rake::TestTask.new do |t|
78
t.libs += %w(test)
8-
t.test_files = FileList['test/**/*_test.rb']
9+
t.test_files = FileList["test/**/*_test.rb"]
910
t.warning = false
1011
end

bin/console

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4-
require File.expand_path('../../vendor/bootstrap.rb', __FILE__)
5-
require 'git_chain'
4+
require File.expand_path("../../vendor/bootstrap.rb", __FILE__)
5+
require "git_chain"
66

77
require "irb"
88
require "irb/completion"
9-
require 'irb/ext/save-history'
9+
require "irb/ext/save-history"
1010

1111
IRB_HISTORY_SIZE = 100
12-
IRB_HISTORY_FILE = File.expand_path('../../.console_history', __FILE__)
12+
IRB_HISTORY_FILE = File.expand_path("../../.console_history", __FILE__)
1313
if File.exist?(IRB_HISTORY_FILE)
1414
lines = IO.readlines(IRB_HISTORY_FILE).collect(&:chomp)
1515
Readline::HISTORY.push(*lines)

bin/git-chain

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/ruby --disable-gems
2+
# frozen_string_literal: true
23

3-
require File.expand_path('../../vendor/bootstrap.rb', File.realpath(__FILE__))
4-
require 'git_chain'
4+
require File.expand_path("../../vendor/bootstrap.rb", File.realpath(__FILE__))
5+
require "git_chain"
56

67
exit(GitChain::EntryPoint.call(ARGV.dup))

bin/update-deps

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/ruby --disable-gems
2+
# frozen_string_literal: true
23

3-
require 'open3'
4-
require 'fileutils'
4+
require "open3"
5+
require "fileutils"
56

67
def bail(msg)
78
$stderr.puts("[ERROR] #{msg}")
@@ -13,12 +14,12 @@ def warn(msg)
1314
end
1415

1516
deps = {
16-
'cli-ui' => 'lib',
17-
'cli-kit' => 'lib',
17+
"cli-ui" => "lib",
18+
"cli-kit" => "lib",
1819
}
1920

2021
deps.each do |dep, copy_path|
21-
path = File.expand_path(dep, '~/src/github.com/Shopify')
22+
path = File.expand_path(dep, "~/src/github.com/Shopify")
2223

2324
unless Dir.exist?(path)
2425
bail("dependency is not checked out: #{dep} {{bold:{{blue:(try {{green:dev clone}})}}}}")
@@ -28,18 +29,18 @@ deps.each do |dep, copy_path|
2829
dirty = false
2930

3031
Dir.chdir(path) do
31-
_, _, stat = Open3.capture3('git fetch origin master')
32+
_, _, stat = Open3.capture3("git fetch origin master")
3233
bail("couldn't git fetch in dependency: #{dep}") unless stat.success?
3334

34-
head_sha, stat = Open3.capture2('git rev-parse HEAD')
35+
head_sha, stat = Open3.capture2("git rev-parse HEAD")
3536
bail("couldn't determine HEAD: #{dep}") unless stat.success?
3637
head_sha.chomp!
3738

38-
fetch_head_sha, stat = Open3.capture2('git rev-parse FETCH_HEAD')
39+
fetch_head_sha, stat = Open3.capture2("git rev-parse FETCH_HEAD")
3940
bail("couldn't determine FETCH_HEAD: #{dep}") unless stat.success?
4041
fetch_head_sha.chomp!
4142

42-
git_status, stat = Open3.capture2('git status --porcelain')
43+
git_status, stat = Open3.capture2("git status --porcelain")
4344
bail("couldn't determine git status: #{dep}") unless stat.success?
4445

4546
if head_sha != fetch_head_sha

lib/git_chain.rb

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
require 'cli/ui'
2-
require 'cli/kit'
1+
# frozen_string_literal: true
2+
require "cli/ui"
3+
require "cli/kit"
34

45
module GitChain
56
extend CLI::Kit::Autocall
67

78
TOOL_NAME = "git-chain"
8-
CONFIG_HOME = File.expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config'))
9+
CONFIG_HOME = File.expand_path(ENV.fetch("XDG_CONFIG_HOME", "~/.config"))
910
TOOL_CONFIG_PATH = File.join(CONFIG_HOME, TOOL_NAME)
10-
DEBUG_LOG_FILE = File.join(TOOL_CONFIG_PATH, 'logs', 'debug.log')
11+
DEBUG_LOG_FILE = File.join(TOOL_CONFIG_PATH, "logs", "debug.log")
1112

1213
autocall(:Logger) { CLI::Kit::Logger.new(debug_log_file: DEBUG_LOG_FILE) }
1314

14-
autoload :Commands, 'git_chain/commands'
15-
autoload :EntryPoint, 'git_chain/entry_point'
16-
autoload :Git, 'git_chain/git'
17-
autoload :Models, 'git_chain/models'
18-
autoload :Options, 'git_chain/options'
19-
autoload :Util, 'git_chain/util'
15+
autoload :Commands, "git_chain/commands"
16+
autoload :EntryPoint, "git_chain/entry_point"
17+
autoload :Git, "git_chain/git"
18+
autoload :Models, "git_chain/models"
19+
autoload :Options, "git_chain/options"
20+
autoload :Util, "git_chain/util"
2021

2122
GenericAbort = CLI::Kit::GenericAbort
2223
Abort = CLI::Kit::Abort

lib/git_chain/commands.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
# frozen_string_literal: true
12
module GitChain
23
module Commands
3-
autoload :Branch, 'git_chain/commands/branch'
4-
autoload :Command, 'git_chain/commands/command'
5-
autoload :List, 'git_chain/commands/list'
6-
autoload :Rebase, 'git_chain/commands/rebase'
7-
autoload :Push, 'git_chain/commands/push'
8-
autoload :Setup, 'git_chain/commands/setup'
4+
autoload :Branch, "git_chain/commands/branch"
5+
autoload :Command, "git_chain/commands/command"
6+
autoload :List, "git_chain/commands/list"
7+
autoload :Rebase, "git_chain/commands/rebase"
8+
autoload :Push, "git_chain/commands/push"
9+
autoload :Setup, "git_chain/commands/setup"
910

1011
ArgError = Class.new(ArgumentError)
1112

lib/git_chain/commands/branch.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require 'optparse'
1+
# frozen_string_literal: true
2+
require "optparse"
23

34
module GitChain
45
module Commands
@@ -39,7 +40,7 @@ def parse_branch_options(options)
3940
raise(ArgError, "Expected 1 or 2 arguments")
4041
end
4142

42-
raise(Abort, "#{start_point} is not a branch") if Git.exec('branch', '--list', start_point).empty?
43+
raise(Abort, "#{start_point} is not a branch") if Git.exec("branch", "--list", start_point).empty?
4344

4445
[start_point, branch_name]
4546
end
@@ -98,12 +99,12 @@ def run(options)
9899
end
99100

100101
begin
101-
Git.exec('checkout', start_point, '-B', branch_name)
102+
Git.exec("checkout", start_point, "-B", branch_name)
102103
rescue Git::Failure => e
103104
raise(Abort, e)
104105
end
105106

106-
Setup.new.call(['--chain', chain.name, *branch_names])
107+
Setup.new.call(["--chain", chain.name, *branch_names])
107108
end
108109
end
109110
end

lib/git_chain/commands/command.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
require 'optparse'
1+
# frozen_string_literal: true
2+
require "optparse"
23

34
module GitChain
45
module Commands
56
class Command
67
include Util::Output
78

89
def self.command_name
9-
@command_name ||= name.split('::')
10+
@command_name ||= name.split("::")
1011
.last
1112
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2')
1213
.gsub(/([a-z\d])([A-Z])/, '\1-\2')

lib/git_chain/commands/list.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require 'optparse'
1+
# frozen_string_literal: true
2+
require "optparse"
23

34
module GitChain
45
module Commands
@@ -37,14 +38,14 @@ def run(options)
3738
chain_names.each(&GitChain::Logger.method(:info))
3839
else
3940
current = current_chain
40-
prefix = ''
41+
prefix = ""
4142

4243
chain_names.each do |cn|
4344
chain = Models::Chain.from_config(cn)
4445
branches = chain.branch_names.map { |b| "{{cyan:#{b}}}" }
4546

4647
prefix = cn == current ? "{{yellow:*}} " : " " if current
47-
GitChain::Logger.info("#{prefix}{{blue:#{chain.name}}} [#{branches.join(' -> ')}]")
48+
GitChain::Logger.info("#{prefix}{{blue:#{chain.name}}} [#{branches.join(" -> ")}]")
4849
end
4950
end
5051
end

lib/git_chain/commands/push.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require 'optparse'
1+
# frozen_string_literal: true
2+
require "optparse"
23

34
module GitChain
45
module Commands
@@ -33,7 +34,7 @@ def run(options)
3334
chain.branch_names[1..-1].each do |b|
3435
upstream = Git.upstream_branch(branch: b)
3536
if upstream
36-
branch_remote, upstream_branch = upstream.split('/', 2)
37+
branch_remote, upstream_branch = upstream.split("/", 2)
3738
if remote && branch_remote != remote
3839
raise(Abort, "Multiple remotes detected: #{remote}, #{branch_remote}") if remote != branch_remote
3940
else
@@ -53,16 +54,16 @@ def run(options)
5354
pairs = upstreams.map { |b, u| "#{b}:#{u}" }
5455

5556
cmd = %w(git push)
56-
cmd << '--force-with-lease' if options[:force]
57+
cmd << "--force-with-lease" if options[:force]
5758
cmd += [remote, *pairs]
5859

59-
puts_info("Pushing {{info:#{pairs.size}}} branch#{pairs.size > 1 ? 'es' : ''} to #{remote}")
60+
puts_info("Pushing {{info:#{pairs.size}}} branch#{pairs.size > 1 ? "es" : ""} to #{remote}")
6061
puts_debug(cmd.join(" "))
6162
raise(Abort, "git push failed") unless system(*cmd)
6263

6364
if options[:set_upstream]
6465
upstreams.each do |local, upstream|
65-
args = ['branch', "--set-upstream-to=#{remote}/#{upstream}", local]
66+
args = ["branch", "--set-upstream-to=#{remote}/#{upstream}", local]
6667
puts_debug_git(*args)
6768
Git.exec(*args)
6869
end

lib/git_chain/commands/rebase.rb

+27-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require 'optparse'
1+
# frozen_string_literal: true
2+
require "optparse"
23

34
module GitChain
45
module Commands
@@ -19,7 +20,7 @@ def run(options)
1920
chain = GitChain::Models::Chain.from_config(options[:chain_name])
2021
raise(Abort, "Chain '#{options[:chain_name]}' does not exist.") if chain.empty?
2122

22-
log_names = chain.branch_names.map { |b| "{{cyan:#{b}}}" }.join(' -> ')
23+
log_names = chain.branch_names.map { |b| "{{cyan:#{b}}}" }.join(" -> ")
2324
puts_debug("Rebasing chain {{info:#{chain.name}}} [#{log_names}]")
2425

2526
branches_to_rebase = chain.branches[1..-1]
@@ -29,33 +30,31 @@ def run(options)
2930
updates = 0
3031

3132
branches_to_rebase.each do |branch|
32-
begin
33-
parent_sha = Git.rev_parse(branch.parent_branch)
34-
if parent_sha == branch.branch_point
35-
puts_debug("Branch {{info:#{branch.name}}} is already up-to-date.")
36-
next
37-
end
38-
39-
updates += 1
40-
41-
if parent_sha != branch.branch_point && forwardable_branch_point?(branch)
42-
puts_info("Auto-forwarding #{branch.name} to #{branch.parent_branch}")
43-
Git.set_config("branch.#{branch.name}.branchPoint", parent_sha)
44-
branch.branch_point = parent_sha
45-
end
46-
47-
args = ["rebase", "--keep-empty", "--onto", branch.parent_branch, branch.branch_point, branch.name]
48-
puts_debug_git(*args)
49-
Git.exec(*args)
50-
Git.set_config("branch.#{branch.name}.branchPoint", parent_sha, scope: :local)
51-
# validate the parameters
52-
rescue GitChain::Git::Failure => e
53-
puts_warning(e.message)
54-
55-
puts_error("Cannot merge #{branch.name} onto #{branch.parent_branch}.")
56-
puts_error("Fix the rebase and run {{command:git chain rebase}} again.")
57-
raise(AbortSilent)
33+
parent_sha = Git.rev_parse(branch.parent_branch)
34+
if parent_sha == branch.branch_point
35+
puts_debug("Branch {{info:#{branch.name}}} is already up-to-date.")
36+
next
5837
end
38+
39+
updates += 1
40+
41+
if parent_sha != branch.branch_point && forwardable_branch_point?(branch)
42+
puts_info("Auto-forwarding #{branch.name} to #{branch.parent_branch}")
43+
Git.set_config("branch.#{branch.name}.branchPoint", parent_sha)
44+
branch.branch_point = parent_sha
45+
end
46+
47+
args = ["rebase", "--keep-empty", "--onto", branch.parent_branch, branch.branch_point, branch.name]
48+
puts_debug_git(*args)
49+
Git.exec(*args)
50+
Git.set_config("branch.#{branch.name}.branchPoint", parent_sha, scope: :local)
51+
# validate the parameters
52+
rescue GitChain::Git::Failure => e
53+
puts_warning(e.message)
54+
55+
puts_error("Cannot merge #{branch.name} onto #{branch.parent_branch}.")
56+
puts_error("Fix the rebase and run {{command:git chain rebase}} again.")
57+
raise(AbortSilent)
5958
end
6059

6160
if updates.positive?

lib/git_chain/commands/setup.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require 'optparse'
1+
# frozen_string_literal: true
2+
require "optparse"
23

34
module GitChain
45
module Commands
@@ -25,7 +26,7 @@ def run(options)
2526
branch_names = options[:args]
2627

2728
unless (missing = branch_names - Git.branches).empty?
28-
raise(Abort, "Branch does not exist: #{missing.join(', ')}")
29+
raise(Abort, "Branch does not exist: #{missing.join(", ")}")
2930
end
3031

3132
raise(Abort, "Branches are not all connected") if Git.merge_base(*branch_names).nil?
@@ -92,10 +93,10 @@ def run(options)
9293
end
9394

9495
unless removed.empty?
95-
puts_warning("Removed #{removed.map { |b| "{{info:#{b}}}" }.join(', ')} from the chain.")
96+
puts_warning("Removed #{removed.map { |b| "{{info:#{b}}}" }.join(", ")} from the chain.")
9697
end
9798

98-
log_names = branch_names.map { |b| "{{cyan:#{b}}}" }.join(' -> ')
99+
log_names = branch_names.map { |b| "{{cyan:#{b}}}" }.join(" -> ")
99100
puts_success("Configured chain {{info:#{chain.name}}} {{reset:[#{log_names}]}}")
100101
end
101102
end

lib/git_chain/entry_point.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
module GitChain
23
module EntryPoint
34
PRELUDE = "git chain"

0 commit comments

Comments
 (0)