Class: GitPivotalTracker::Finish

Inherits:
Base
  • Object
show all
Defined in:
lib/git_pivotal_tracker/finish.rb

Constant Summary

Constants inherited from Base

Base::GIT_DIR

Instance Attribute Summary

Attributes inherited from Base

#options, #repository

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from GitPivotalTracker::Base

Instance Method Details

#run!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git_pivotal_tracker/finish.rb', line 4

def run!
  return 1 if super

  unless story_id
    puts "Branch name must contain a Pivotal Tracker story id"
    return 1
  end

  if options[:rebase]
    puts "Fetching origin and rebasing #{current_branch}"
    log repository.git.checkout({:raise => true}, integration_branch)
    log repository.git.pull({:raise => true})
    log repository.git.rebase({:raise => true}, integration_branch, current_branch)
  end

  puts "Merging #{current_branch} into #{integration_branch}"
  log repository.git.checkout({:raise => true}, integration_branch)

  merge_options = {:raise => true}
  merge_options[:no_ff] = true unless options[:fast_forward]
  log repository.git.merge(merge_options, current_branch)

  puts "Pushing #{integration_branch}"
  log repository.git.push({:raise => true}, 'origin', integration_branch)

  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
    puts "Unable to mark Story #{story_id} as finished"
    return 1
  end
rescue Grit::Git::CommandFailed => e
  puts "git error: #{e.err}"
  return 1
end