From be68a8b6c8451aa81cd995f3e8e40c204c83cf54 Mon Sep 17 00:00:00 2001 From: rkiel Date: Sat, 6 Jun 2015 07:59:12 -0400 Subject: [PATCH] create git commands --- lib/feature/branch.rb | 2 +- lib/feature/end.rb | 8 ++++---- lib/feature/merge_to.rb | 10 +++++----- lib/feature/rebase.rb | 12 ++++++------ lib/feature/start.rb | 6 +++--- lib/shared/runnable.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 19 deletions(-) diff --git a/lib/feature/branch.rb b/lib/feature/branch.rb index 38ebbc9..8d9ba9a 100644 --- a/lib/feature/branch.rb +++ b/lib/feature/branch.rb @@ -12,7 +12,7 @@ module Feature end def execute - run_cmd "git branch" + git_show_branches end end diff --git a/lib/feature/end.rb b/lib/feature/end.rb index 5d1736c..88ce0d9 100644 --- a/lib/feature/end.rb +++ b/lib/feature/end.rb @@ -22,15 +22,15 @@ module Feature error "invalid feature branch: #{feature_branch}" if standard_branches.include? feature_branch - run_cmd "git checkout #{standard_branch}" + git_checkout standard_branch if remote_branch(feature_branch) != "" - run_cmd "git push origin :#{feature_branch}" + git_remote_branch_delete feature_branch end - run_cmd "git branch -D #{feature_branch}" + git_local_branch_delete feature_branch - run_cmd "git remote prune origin" + git_prune end end diff --git a/lib/feature/merge_to.rb b/lib/feature/merge_to.rb index 3a0b647..bc95808 100644 --- a/lib/feature/merge_to.rb +++ b/lib/feature/merge_to.rb @@ -27,11 +27,11 @@ module Feature error "invalid branch: #{merge_to_branch}" unless standard_branches.include? merge_to_branch - run_cmd "git checkout #{merge_to_branch}" - run_cmd "git pull origin #{merge_to_branch}" - run_cmd "git merge #{feature_branch}" - run_cmd "git push origin #{merge_to_branch}" - run_cmd "git checkout #{feature_branch}" + git_checkout merge_to_branch + git_pull merge_to_branch + git_merge feature_branch + git_push merge_to_branch + git_checkout feature_branch end end diff --git a/lib/feature/rebase.rb b/lib/feature/rebase.rb index 1ff918f..e58d45b 100644 --- a/lib/feature/rebase.rb +++ b/lib/feature/rebase.rb @@ -24,16 +24,16 @@ module Feature error "USAGE: feature rebase" unless standard_branch error "invalid feature branch: #{feature_branch}" if standard_branches.include? feature_branch - run_cmd "git checkout #{standard_branch}" - run_cmd "git pull origin #{standard_branch}" - run_cmd "git checkout #{feature_branch}" - run_cmd "git rebase #{standard_branch}" + git_checkout standard_branch + git_pull standard_branch + git_checkout feature_branch + git_rebase standard_branch if remote_branch != "" - run_cmd "git push origin :#{feature_branch}" + git_remote_branch_delete feature_branch end - run_cmd "git push origin #{feature_branch}" + git_push feature_branch end end diff --git a/lib/feature/start.rb b/lib/feature/start.rb index 52d602d..5514881 100644 --- a/lib/feature/start.rb +++ b/lib/feature/start.rb @@ -21,11 +21,11 @@ module Feature error "invalid base branch: #{current_branch}" unless standard_branches.include? current_branch error "invalid feature branch: #{featureh}" if standard_branches.include? feature - run_cmd "git pull origin #{current_branch}" + git_pull current_branch - run_cmd "git checkout -b #{feature_branch}" + git_local_branch_create feature_branch - run_cmd "git push origin #{feature_branch}" + git_push feature_branch end end diff --git a/lib/shared/runnable.rb b/lib/shared/runnable.rb index 534c156..4ae933e 100644 --- a/lib/shared/runnable.rb +++ b/lib/shared/runnable.rb @@ -18,6 +18,46 @@ module Shared puts exit end + + def git_show_branches + run_cmd "git branch" + end + + def git_checkout ( branch ) + run_cmd "git checkout #{branch}" + end + + def git_remote_branch_delete ( branch ) + run_cmd "git push origin :#{branch}" + end + + def git_local_branch_delete ( branch ) + run_cmd "git branch -d #{branch}" + end + + def git_prune + run_cmd "git remote prune origin" + end + + def git_pull (branch) + run_cmd "git pull origin #{branch}" + end + + def git_merge (branch) + run_cmd "git merge #{branch}" + end + + def git_push (branch) + run_cmd "git push origin #{branch}" + end + + def git_rebase (branch) + run_cmd "git rebase #{branch}" + end + + def git_local_branch_create (branch) + run_cmd "git checkout -b #{branch}" + end end end