diff --git a/README.md b/README.md index 8ec2080..9190826 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ The project id is best placed within your project's git config: ``git config -f .git/config pivotal.project-id 88888`` -If you project's access is setup to use HTTPS: +If your project's access is setup to use HTTPS: ``git config -f .git/config pivotal.use-ssl 1`` @@ -69,6 +69,10 @@ If your Pivotal Tracker user name is different than your git user name: ``git config --global pivotal.full-name 'Ben Lindsey'`` +If you prefer to have story branches deleted after they are merged by `git-finish`: + +``git config --global pivotal.delete-branch 1`` + If you would like verbose logging turned on for git commands: ``git config --global pivotal.verbose 1`` diff --git a/lib/git_pivotal_tracker/base.rb b/lib/git_pivotal_tracker/base.rb index 3783dcb..93926b1 100644 --- a/lib/git_pivotal_tracker/base.rb +++ b/lib/git_pivotal_tracker/base.rb @@ -41,7 +41,13 @@ def run! protected def integration_branch - options[:integration_branch] || 'master' + current_branch_suffix || options[:integration_branch] || 'master' + end + + def current_branch_suffix + if current_branch =~ /.*-\d+?-(.*)/ and @repository.branches.any? { |branch| branch.name == $1 } + $1 + end end def current_branch @@ -79,6 +85,7 @@ def parse_gitconfig options[:full_name] = repository.config['pivotal.full-name'] || repository.config['user.name'] options[:verbose] = repository.config['pivotal.verbose'] options[:use_ssl] = repository.config['pivotal.use-ssl'] + options[:delete_branch] = repository.config['pivotal.delete-branch'] end def parse_argv(*args) @@ -90,6 +97,7 @@ def parse_argv(*args) opts.on("-n", "--full-name=", "Your Pivotal Tracker full name") { |n| options[:full_name] = n } + opts.on("-D", "--delete-branch", "Delete store branch after merging") { |d| options[:delete_branch] = d } opts.on("-I", "--include-rejected", "Include rejected stories as well as unstarted ones") { |i| options[:include_rejected] = i } opts.on("-O", "--only-mine", "Only include stories that are assigned to me") { |o| options[:only_mine] = o } opts.on("-F", "--fast-forward", "Merge topic branch with fast forward") { |f| options[:fast_forward] = f } diff --git a/lib/git_pivotal_tracker/finish.rb b/lib/git_pivotal_tracker/finish.rb index 670d560..2175b93 100644 --- a/lib/git_pivotal_tracker/finish.rb +++ b/lib/git_pivotal_tracker/finish.rb @@ -28,6 +28,7 @@ def run! puts "Marking Story #{story_id} as finished..." if story.update(:current_state => finished_state) + delete_current_branch if options[:delete_branch] puts "Success" return 0 else @@ -41,5 +42,10 @@ def run! def finished_state story.story_type == "chore" ? "accepted" : "finished" end + + def delete_current_branch + puts "Deleting #{current_branch}" + log repository.git.branch({:raise => true, :d => true}, current_branch) + end end end diff --git a/spec/git_pivotal_tracker/base_spec.rb b/spec/git_pivotal_tracker/base_spec.rb index 36b2e66..49f003d 100644 --- a/spec/git_pivotal_tracker/base_spec.rb +++ b/spec/git_pivotal_tracker/base_spec.rb @@ -40,6 +40,10 @@ it "leaves only_mine nil" do subject.options[:only_mine].should be_nil end + + it "leaves delete_branch nil" do + subject.options[:delete_branch].should be_nil + end end it "sets the api_token" do @@ -91,6 +95,11 @@ GitPivotalTracker::Base.new("--verbose").options[:verbose].should be GitPivotalTracker::Base.new("-V").options[:verbose].should be end + + it "sets delete_branch" do + GitPivotalTracker::Base.new("--delete-branch").options[:delete_branch].should be + GitPivotalTracker::Base.new("-D").options[:delete_branch].should be + end end describe "#parse_gitconfig" do diff --git a/spec/git_pivotal_tracker/finish_spec.rb b/spec/git_pivotal_tracker/finish_spec.rb index 25bffda..2d94046 100644 --- a/spec/git_pivotal_tracker/finish_spec.rb +++ b/spec/git_pivotal_tracker/finish_spec.rb @@ -57,6 +57,11 @@ @repo.commits.first.parents.should have(2).items @repo.heads.detect { |h| h.name == @current_head.name }.commit.sha.should == @sha end + + it "does not delete story branch" do + finish.run!.should == 0 + @repo.git.branch.should match @new_branch + end context "when I have rebase turned on" do before do @@ -80,5 +85,16 @@ @repo.heads.detect { |h| h.name == @current_head.name }.commit.sha.should == @sha end end + + context "when I have delete branch turned on" do + before do + finish.options[:delete_branch] = 1 + end + + it "deletes the story branch after merging" do + finish.run!.should == 0 + @repo.git.branch.should_not match @new_branch + end + end end end