From 067b1b3cccaa5298b5f698e2b0e9be3cebcfae57 Mon Sep 17 00:00:00 2001 From: rkiel Date: Sat, 6 Jun 2015 08:35:35 -0400 Subject: [PATCH] feature-add-trash: force the delete of a branch --- lib/feature/commander.rb | 1 + lib/feature/trash.rb | 37 +++++++++++++++++++++++++++++++++++++ lib/shared/runnable.rb | 4 ++++ 3 files changed, 42 insertions(+) create mode 100644 lib/feature/trash.rb diff --git a/lib/feature/commander.rb b/lib/feature/commander.rb index 8c23f18..b87c3ff 100644 --- a/lib/feature/commander.rb +++ b/lib/feature/commander.rb @@ -13,6 +13,7 @@ module Feature @subcommand = case argv[0] when "start" then Feature::Start.new(argv) when "end" then Feature::End.new(argv) + when "trash" then Feature::Trash.new(argv) when "rebase" then Feature::Rebase.new(argv) when "merge" then Feature::MergeTo.new(argv) else Feature::Branch.new(argv) diff --git a/lib/feature/trash.rb b/lib/feature/trash.rb new file mode 100644 index 0000000..67bf549 --- /dev/null +++ b/lib/feature/trash.rb @@ -0,0 +1,37 @@ +require_relative './base' + +module Feature + + class Trash < Feature::Base + def valid? + argv.size == 1 + end + + def help + puts + puts "USAGE: feature trash" + puts + exit + end + + def execute + parts = parse_branch(current_branch) + + standard_branch = parts[:standard] + feature_branch = current_branch + + error "invalid feature branch: #{feature_branch}" if standard_branches.include? feature_branch + + git_checkout standard_branch + + git_local_branch_trash feature_branch + + if remote_branch(feature_branch) != "" + git_remote_branch_delete feature_branch + end + + git_prune + end + end + +end diff --git a/lib/shared/runnable.rb b/lib/shared/runnable.rb index e78e793..7cf8c4d 100644 --- a/lib/shared/runnable.rb +++ b/lib/shared/runnable.rb @@ -35,6 +35,10 @@ module Shared run_cmd "git branch -d #{branch}" end + def git_local_branch_trash ( branch ) + run_cmd "git branch -D #{branch}" + end + def git_prune run_cmd "git remote prune origin" end