lib/git_topic.rb
# Switch to a branch for the given topic.
Switch to a branch for the given topic.
Switch to a branch for the given topic .
def work_on topic, opts={}
      opts.assert_valid_keys  :continue, :continue_given, :upstream, *GlobalOptKeys
      raise "Topic must be specified" if topic.nil?
      upstream =
        if opts[:upstream] && opts[:continue]
          raise "upstream and continue options mutually exclusive."
        elsif opts[:upstream]
          opts[:upstream]
        elsif opts[:continue]
          newest_pending_branch
        end
      wb = wip_branch( topic )
      git(
        "push origin HEAD:refs/heads/#{wb}"
      ) unless remote_branches.include? "origin/#{wb}"
      git [ switch_to_branch( wb, "origin/#{wb}" )]
      [ rejected_branch( topic ), review_branch( topic ) ].each do |b|
        if remote_branches.include? "origin/#{b}"
          git [
            "reset --hard origin/#{b}",
            "push origin :refs/heads/#{b} +HEAD:refs/heads/#{wb}",
          ]
        end
      end
      if upstream
        git "reset --hard #{upstream}"
      end
      report "Switching branches to work on #{topic}."
      if existing_comments?
        report "You have reviewer comments on this topic."
      end
    end
def work_on topic , opts = { } opts . assert_valid_keys :continue , :continue_given , :upstream , * GlobalOptKeys raise "Topic must be specified" if topic . nil? upstream = if opts [ :upstream ] && opts [ :continue ] raise "upstream and continue options mutually exclusive." elsif opts [ :upstream ] opts [ :upstream ] elsif opts [ :continue ] newest_pending_branch end wb = wip_branch ( topic ) git ( "push origin HEAD:refs/heads/#{wb}" ) unless remote_branches . include? "origin/#{wb}" git [ switch_to_branch ( wb , "origin/#{wb}" ) ] [ rejected_branch ( topic ) , review_branch ( topic ) ] . each do | b | if remote_branches . include? "origin/#{b}" git [ "reset --hard origin/#{b}" , "push origin :refs/heads/#{b} +HEAD:refs/heads/#{wb}" , ] end end if upstream git "reset --hard #{upstream}" end report "Switching branches to work on #{topic}." if existing_comments? report "You have reviewer comments on this topic." end end
Switch to a branch for the given topic.
Switch to a branch for the given topic .
# setup a remote branch, if necessary # switch to the new branch # Check for rejected or review branch # Reset upstream, if specified
topic
opts