Skip to content

Commit

Permalink
Merge pull request #24 from KyleFin/addDeleteBranchCommand
Browse files Browse the repository at this point in the history
Add a Teardown command
  • Loading branch information
lavoiesl authored Feb 13, 2023
2 parents 7ffbf19 + e4ae00b commit e1c0ef1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/git_chain/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Commands
autoload :Prune, "git_chain/commands/prune"
autoload :Push, "git_chain/commands/push"
autoload :Setup, "git_chain/commands/setup"
autoload :Teardown, "git_chain/commands/teardown"

ArgError = Class.new(ArgumentError)

Expand Down
32 changes: 32 additions & 0 deletions lib/git_chain/commands/teardown.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true
require "optparse"

module GitChain
module Commands
class Teardown < Command
include Options::ChainName

def description
"Teardown chain"
end

def run(options)
if Git.rebase_in_progress?
raise(Abort, "A rebase is in progress. Please finish the rebase first and run 'git chain rebase' after.")
end

chain = current_chain(options)

puts_debug("Tearing down chain #{chain.formatted}}}")

chain.branch_names.each do |b|
Git.set_config("branch.#{b}.chain", nil, scope: :local)
Git.set_config("branch.#{b}.parentBranch", nil, scope: :local)
Git.set_config("branch.#{b}.branchPoint", nil, scope: :local)
end

puts_success("Removed chain #{chain.formatted}")
end
end
end
end
35 changes: 35 additions & 0 deletions test/git_chain/command/teardown_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true
require "test_helper"

module GitChain
module Commands
class TeardownTest < MiniTest::Test
include RepositoryTestHelper

def test_tearing_down_a_clean_chain
capture_io do
with_test_repository("a-b-chain") do
assert_equal(%w(master a b), Models::Chain.from_config("default").branch_names)

Teardown.new.call

assert(Models::Chain.from_config("default").empty?)
end
end
end

def test_rebase_in_progress
capture_io do
with_test_repository("a-b-conflicts") do
%x(git rebase --onto a b^ b)
exception = assert_raises(Abort) do
Teardown.new.call
end

assert_match(/rebase is in progress/, exception.message)
end
end
end
end
end
end

0 comments on commit e1c0ef1

Please sign in to comment.