Checkout the branch for the given issue.

    It is an error if the branch does no exist yet.
342002
def checkout(lancet, force, issue):
    
    issue = get_issue(lancet, issue)

    # Get the working branch
    branch = get_branch(lancet, issue, create=force)

    with taskstatus("Checking out working branch") as ts:
        if not branch:
            ts.abort("Working branch not found")
        lancet.repo.checkout(branch.name)
        ts.ok('Checked out "{}"', branch.name)
1316422
def run!
      raise_error_if_development_or_master
      story = @configuration.story
      fail("Could not find story associated with branch") unless story
      story.can_merge?
      commit_message = options[:commit_message]
      if story.release?
        story.merge_release!(commit_message, @options)
      else
        story.merge_to_roots!(commit_message, @options)
      end
      return 0
    end
236009
def create_branch(self, branch_name: str):
        
        LOGGER.info('creating branch: %s', branch_name)
        self._validate_branch_name(branch_name)
        if branch_name in self.list_branches():
            LOGGER.error('branch already exists')
            sys.exit(-1)
        new_branch = self.repo.create_head(branch_name)
        new_branch.commit = self.repo.head.commit
603546
def branch(self, branch_name, start_point='HEAD', force=True,
               checkout=False):
        
        return git_branch(
            self.repo_dir, branch_name, start_point, force=force,
            checkout=checkout)
711647
def checkout(self, revision, options):
        
        rev = revision.key
        self.repo.git.checkout(rev)
345817
def checkout(self, branch_name):
        
        try:
            find(
                self.repo.branches, lambda b: b.name == branch_name
            ).checkout()
        except OrigCheckoutError as e:
            raise CheckoutError(branch_name, details=e)
613158
def checkoutbranch(accountable, options):
    
    issue = accountable.checkout_branch(options)
    headers = sorted(['id', 'key', 'self'])
    rows = [headers, [itemgetter(header)(issue) for header in headers]]
    print_table(SingleTable(rows))
256662
def status():
    
    import pdb; pdb.set_trace()
    branch = git.branch
    issue = jira.get_issue(branch)
    if not issue:
        return

    # Print the title
    title = issue.fields.summary
    print "(%s) %s" % (branch, title)

    # Print the status
    status = issue.fields.status.name
    assignee = issue.fields.assignee.name
    in_progress = jira.get_datetime_issue_in_progress(issue)

    if in_progress:
        in_progress_string = in_progress.strftime("%a %x %I:%M %p")
        print '  Status: %s as of %s' % (status, in_progress_string)
    else:
        print '  Status: %s' % status

    print '  Assignee: %s' % assignee

    # Print the worklogs

    # Get the timespent and return 0m if it does not exist
    time_spent = '0m'
    try:
        time_spent = issue.fields.timetracking.timeSpent
    except:
        pass

    worklogs = jira.get_worklog(issue)
    print "\nTime logged (%s):" % time_spent
    if worklogs:
        for worklog in worklogs:
            worklog_hash = worklog.raw

            author = worklog_hash['author']['name']

            time_spent = worklog_hash.get('timeSpent', '0m')

            created = dateutil.parser.parse(worklog_hash['started'])
            created_pattern = '%a %x         '  # Adding extra space for formatting
            if not created.hour == created.minute == created.second == 0:
                created = created.astimezone(tzlocal())
                created_pattern = '%a %x %I:%M %p'
            comment = worklog_hash.get('comment', '<no comment>')

            updated_string = created.strftime(created_pattern)
            print "  %s - %s (%s): %s" % (updated_string, author, time_spent, comment)
    else:
        print "  No worklogs"

    cycle_time = jira.get_cycle_time(issue)
    if cycle_time:
        print '\nCycle Time: %.1f days' % cycle_time

    # Print the time elapsed since the last mark
    elapsed_time = jira.get_elapsed_time(issue)
    if elapsed_time:
        print '\n\033[0;32m%s elapsed\033[00m (use "jtime log ." to log elapsed time or "jtime log <duration> (ex. 30m, 1h etc.)" to log a specific amount of time)' % (elapsed_time)
    else:
        print '\n\033[0;32m0m elapsed\033[00m'
210579
def checkout_branch(self, branch):
        """"""

        _, stdout, stderr = self.git_exec(
            ['checkout', branch],
            with_extended_output=True)
        return '\n'.join([stderr, stdout])
695993
def closed_issue(issue, after=None):
    """"""
    if issue['state'] == 'closed':
        if after is None or parse_timestamp(issue['closed_at']) > after:
            return True
    return False
1016710
def checkout(self, _hash: str) -> None:
        
        with self.lock:
            self._delete_tmp_branch()
            self.git.checkout('-f', _hash, b='_PD')
1005859
def checkout_task(current_target):
    
    try:
        scm = _make_scm(current_target)
        src_dir = current_target.config.get("dp.src_dir")
        shared_dir = current_target.config.get("dp.src_dir_shared")
        scm.checkout(repo_dir=src_dir, shared_dir=shared_dir)
        scm.update(repo_dir=src_dir)
    except devpipeline_core.toolsupport.MissingToolKey as mtk:
        current_target.executor.warning(mtk)
190133
def _check_branch(self, revision, branch):
        '''
        
        '''

        # Get a changelog
        clog_url = self.hg_url / branch / 'json-log' / revision
        try:
            Log.note("Searching through changelog {{url}}", url=clog_url)
            clog_obj = http.get_json(clog_url, retry=RETRY)
            if isinstance(clog_obj, (text_type, str)):
                Log.note(
                    "Revision {{cset}} does not exist in the {{branch}} branch",
                    cset=revision, branch=branch
                )
                return False
        except Exception as e:
            Log.note("Unexpected error getting changset-log for {{url}}: {{error}}", url=clog_url, error=e)
            return False
        return True
1301208
def checkout(number, branch = true)
      request = server.get_request_by_number(number)
      puts 'Checking out changes to your local repository.'
      puts 'To get back to your original state, just run:'
      puts
      puts '  git checkout master'.pink
      puts
      # Ensure we are looking at the right remote.
      remote = local.remote_for_request(request)
      git_call "fetch #{remote}"
      # Checkout the right branch.
      branch_name = request.head.ref
      if branch
        if local.branch_exists?(:local, branch_name)
          if local.source_branch == branch_name
            puts "On branch #{branch_name}."
          else
            git_call "checkout #{branch_name}"
          end
        else
          git_call "checkout --track -b #{branch_name} #{remote}/#{branch_name}"
        end
      else
        git_call "checkout #{remote}/#{branch_name}"
      end
    end
1329897
def sender(self, issues):
        

        for issue in issues:
            state = self.get_state(issue.state)
            if issue.number:
                try:
                    gh_issue = self.repo.get_issue(issue.number)
                    original_state = gh_issue.state
                    if original_state == state:
                        action = 'Updated'
                    elif original_state == 'closed':
                        action = 'Reopened'
                    else:
                        action = 'Closed'

                    gh_issue.edit(title=issue.title,
                                  body=issue.body,
                                  labels=issue.labels,
                                  milestone=self.get_milestone(issue.milestone),
                                  assignee=self.get_assignee(issue.assignee),
                                  state=self.get_state(issue.state)
                                  )
                    print('{} #{}: {}'.format(action, gh_issue.number, gh_issue.title))
                except GithubException:
                    print('Not found #{}: {} (ignored)'.format(issue.number, issue.title))
                    continue
            else:
                gh_issue = self.repo.create_issue(title=issue.title,
                                                  body=issue.body,
                                                  labels=issue.labels,
                                                  milestone=self.get_milestone(issue.milestone),
                                                  assignee=self.get_assignee(issue.assignee))
                print('Created #{}: {}'.format(gh_issue.number, gh_issue.title))
137207
def cleanup_branch(self, branch):
        
        set_state(WORKFLOW_STATES.REMOVING_BACKPORT_BRANCH)
        self.checkout_default_branch()
        try:
            self.delete_branch(branch)
        except subprocess.CalledProcessError:
            click.echo(f"branch {branch} NOT deleted.")
            set_state(WORKFLOW_STATES.REMOVING_BACKPORT_BRANCH_FAILED)
        else:
            click.echo(f"branch {branch} has been deleted.")
            set_state(WORKFLOW_STATES.REMOVED_BACKPORT_BRANCH)
492476
def checkout(self):
        '''
        
        '''
        tgt_ref = self.get_checkout_target()
        local_ref = 'refs/heads/' + tgt_ref
        remote_ref = 'refs/remotes/origin/' + tgt_ref
        tag_ref = 'refs/tags/' + tgt_ref

        try:
            local_head = self.repo.lookup_reference('HEAD')
        except KeyError:
            log.warning(
                'HEAD not present in %s remote \'%s\'', self.role, self.id
            )
            return None

        try:
            head_sha = self.peel(local_head).hex
        except AttributeError:
            # Shouldn't happen, but just in case a future pygit2 API change
            # breaks things, avoid a traceback and log an error.
            log.error(
                'Unable to get SHA of HEAD for %s remote \'%s\'',
                self.role, self.id
            )
            return None
        except KeyError:
            head_sha = None

        refs = self.repo.listall_references()

        def _perform_checkout(checkout_ref, branch=True):
            '''
            DRY function for checking out either a branch or a tag
            '''
            try:
                with self.gen_lock(lock_type='checkout'):
                    # Checkout the local branch corresponding to the
                    # remote ref.
                    self.repo.checkout(checkout_ref)
                    if branch:
                        self.repo.reset(oid, pygit2.GIT_RESET_HARD)
                return True
            except GitLockError as exc:
                if exc.errno == errno.EEXIST:
                    # Re-raise with a different strerror containing a
                    # more meaningful error message for the calling
                    # function.
                    raise GitLockError(
                        exc.errno,
                        'Checkout lock exists for {0} remote \'{1}\''
                        .format(self.role, self.id)
                    )
                else:
                    log.error(
                        'Error %d encountered obtaining checkout lock '
                        'for %s remote \'%s\'',
                        exc.errno,
                        self.role,
                        self.id
                    )
            return False

        try:
            if remote_ref in refs:
                # Get commit id for the remote ref
                oid = self.peel(self.repo.lookup_reference(remote_ref)).id
                if local_ref not in refs:
                    # No local branch for this remote, so create one and point
                    # it at the commit id of the remote ref
                    self.repo.create_reference(local_ref, oid)

                try:
                    target_sha = \
                        self.peel(self.repo.lookup_reference(remote_ref)).hex
                except KeyError:
                    log.error(
                        'pygit2 was unable to get SHA for %s in %s remote '
                        '\'%s\'', local_ref, self.role, self.id,
                        exc_info=True
                    )
                    return None

                # Only perform a checkout if HEAD and target are not pointing
                # at the same SHA1.
                if head_sha != target_sha:
                    # Check existence of the ref in refs/heads/ which
                    # corresponds to the local HEAD. Checking out local_ref
                    # below when no local ref for HEAD is missing will raise an
                    # exception in pygit2 >= 0.21. If this ref is not present,
                    # create it. The "head_ref != local_ref" check ensures we
                    # don't try to add this ref if it is not necessary, as it
                    # would have been added above already. head_ref would be
                    # the same as local_ref if the branch name was changed but
                    # the cachedir was not (for example if a "name" parameter
                    # was used in a git_pillar remote, or if we are using
                    # winrepo which takes the basename of the repo as the
                    # cachedir).
                    head_ref = local_head.target
                    # If head_ref is not a string, it will point to a
                    # pygit2.Oid object and we are in detached HEAD mode.
                    # Therefore, there is no need to add a local reference. If
                    # head_ref == local_ref, then the local reference for HEAD
                    # in refs/heads/ already exists and again, no need to add.
                    if isinstance(head_ref, six.string_types) \
                            and head_ref not in refs and head_ref != local_ref:
                        branch_name = head_ref.partition('refs/heads/')[-1]
                        if not branch_name:
                            # Shouldn't happen, but log an error if it does
                            log.error(
                                'pygit2 was unable to resolve branch name from '
                                'HEAD ref \'%s\' in %s remote \'%s\'',
                                head_ref, self.role, self.id
                            )
                            return None
                        remote_head = 'refs/remotes/origin/' + branch_name
                        if remote_head not in refs:
                            # No remote ref for HEAD exists. This can happen in
                            # the first-time git_pillar checkout when when the
                            # remote repo does not have a master branch. Since
                            # we need a HEAD reference to keep pygit2 from
                            # throwing an error, and none exists in
                            # refs/remotes/origin, we'll just point HEAD at the
                            # remote_ref.
                            remote_head = remote_ref
                        self.repo.create_reference(
                            head_ref,
                            self.repo.lookup_reference(remote_head).target
                        )

                    if not _perform_checkout(local_ref, branch=True):
                        return None

                # Return the relative root, if present
                return self.check_root()

            elif tag_ref in refs:
                tag_obj = self.repo.revparse_single(tag_ref)
                if not isinstance(tag_obj, pygit2.Commit):
                    log.error(
                        '%s does not correspond to pygit2.Commit object',
                        tag_ref
                    )
                else:
                    try:
                        # If no AttributeError raised, this is an annotated tag
                        tag_sha = tag_obj.target.hex
                    except AttributeError:
                        try:
                            tag_sha = tag_obj.hex
                        except AttributeError:
                            # Shouldn't happen, but could if a future pygit2
                            # API change breaks things.
                            log.error(
                                'Unable to resolve %s from %s remote \'%s\' '
                                'to either an annotated or non-annotated tag',
                                tag_ref, self.role, self.id,
                                exc_info=True
                            )
                            return None
                    log.debug('SHA of tag %s: %s', tgt_ref, tag_sha)

                    if head_sha != tag_sha:
                        if not _perform_checkout(tag_ref, branch=False):
                            return None

                    # Return the relative root, if present
                    return self.check_root()
        except GitLockError:
            raise
        except Exception as exc:
            log.error(
                'Failed to checkout %s from %s remote \'%s\': %s',
                tgt_ref, self.role, self.id, exc,
                exc_info=True
            )
            return None
        log.error(
            'Failed to checkout %s from %s remote \'%s\': remote ref '
            'does not exist', tgt_ref, self.role, self.id
        )
        return None