-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from KyleFin/addDeleteBranchCommand
Add a Teardown command
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 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
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,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 |
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,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 |