-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce functionality to bisect branch chains (#76)
- Loading branch information
Showing
19 changed files
with
415 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ jobs: | |
ruby: | ||
- 3.0.3 | ||
- 3.1.0 | ||
- 3.2.2 | ||
- 3.3.2 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# frozen_string_literal: true | ||
|
||
# class that will attempt to locate the first branch in the current chain that | ||
# fails with a given command | ||
module Baes::Actions::Bisect | ||
class << self | ||
include Baes::Configuration::Helpers | ||
|
||
# run the command and return the first branch that fails | ||
def call(command_args) | ||
output.puts("searching for branch that fails command: `#{command_args}`") | ||
branches = generate_branches | ||
root_branch = find_root_branch(branches) | ||
Baes::Actions::BuildTree.call(branches, root_branch: root_branch) | ||
|
||
current_branch_name = git.current_branch_name | ||
current_branch = | ||
branches.find { |branch| branch.name == current_branch_name } | ||
|
||
_, _, status = Open3.capture3(command_args) | ||
|
||
if status.success? | ||
raise ArgumentError, "command must fail to find failure" | ||
end | ||
|
||
fail_branch = | ||
find_failing_branch(root_branch, current_branch, command_args) | ||
|
||
git.checkout(fail_branch.name) | ||
output.puts("first failing branch: #{fail_branch.name}") | ||
end | ||
|
||
private | ||
|
||
def generate_branches | ||
git.branch_names.map do |branch_name| | ||
Baes::Branch.new(branch_name) | ||
end | ||
end | ||
|
||
def find_root_branch(branches) | ||
if root_name | ||
branches.find { |branch| branch.name == root_name } | ||
else | ||
branches.find { |branch| ["main", "master"].include?(branch.name) } | ||
end | ||
end | ||
|
||
def find_failing_branch(success_branch, fail_branch, command_args) | ||
next_branch = find_middle_branch(success_branch, fail_branch) | ||
|
||
return fail_branch if next_branch == fail_branch || next_branch.nil? | ||
|
||
git.checkout(next_branch.name) | ||
_, _, status = Open3.capture3(command_args) | ||
|
||
if status.success? | ||
output.puts("branch #{next_branch.name} succeeded with command `#{command_args}`") | ||
find_failing_branch(next_branch, fail_branch, command_args) | ||
else | ||
output.puts("branch #{next_branch.name} failed with command `#{command_args}`") | ||
find_failing_branch(success_branch, next_branch, command_args) | ||
end | ||
end | ||
|
||
def find_middle_branch(success_branch, fail_branch) | ||
end_number = fail_branch.number | ||
start_number = success_branch.number | ||
|
||
child_branch = | ||
success_branch.children.find do |next_child_branch| | ||
next_child_branch.base_name == fail_branch.base_name | ||
end | ||
|
||
start_number ||= child_branch.number | ||
|
||
middle_number = (start_number + end_number) / 2 | ||
|
||
next_branch = child_branch | ||
|
||
while next_branch.number < middle_number | ||
next_branch = | ||
next_branch.children.find do |next_child_branch| | ||
next_child_branch.base_name == fail_branch.base_name | ||
end | ||
end | ||
|
||
next_branch | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require "optparse" | ||
|
||
# callable module to load configuration | ||
module Baes::Actions::LoadRebaseConfiguration | ||
class << self | ||
# loads options, typically passed via the command line | ||
def call(options) | ||
parser = OptionParser.new | ||
|
||
configure_dry_run(parser) | ||
configure_help(parser) | ||
configure_root_name(parser) | ||
configure_auto_skip(parser) | ||
configure_ignored_branches(parser) | ||
|
||
parser.parse(options) | ||
end | ||
|
||
private | ||
|
||
def configure_dry_run(parser) | ||
parser.on("--dry-run", "prints branch chain without rebasing") do | ||
Baes::Configuration.dry_run = true | ||
end | ||
end | ||
|
||
def configure_help(parser) | ||
parser.on("-h", "--help", "prints this help") do | ||
Baes::Configuration.output.puts(parser) | ||
exit | ||
end | ||
end | ||
|
||
def configure_root_name(parser) | ||
message = "specify a root branch to rebase on" | ||
parser.on("-r", "--root ROOT", message) do |root_name| | ||
Baes::Configuration.root_name = root_name | ||
end | ||
end | ||
|
||
def configure_auto_skip(parser) | ||
message = "automatically skip all but the most recent commit" | ||
parser.on("--auto-skip", message) do | ||
Baes::Configuration.auto_skip = true | ||
end | ||
end | ||
|
||
def configure_ignored_branches(parser) | ||
message = "don't rebase specified branches or their child branches" | ||
parser.on("--ignore BRANCH1,BRANCH2", Array, message) do |branches| | ||
Baes::Configuration.ignored_branch_names += branches | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.