예제 #1
0
파일: stack.py 프로젝트: snits/stgit
 def get_parent_branch(self):
     value = config.get('branch.%s.stgit.parentbranch' % self.get_name())
     if value:
         return value
     elif git.rev_parse('heads/origin'):
         out.note(('No parent branch declared for stack "%s",'
                   ' defaulting to "heads/origin".' % self.get_name()),
                  ('Consider setting "branch.%s.stgit.parentbranch"'
                   ' with "git config".' % self.get_name()))
         return 'heads/origin'
     else:
         raise StackException('Cannot find a parent branch for "%s"' %
                              self.get_name())
예제 #2
0
 def get_parent_branch(self):
     value = config.get('branch.%s.stgit.parentbranch' % self.get_name())
     if value:
         return value
     elif git.rev_parse('heads/origin'):
         out.note(('No parent branch declared for stack "%s",'
                   ' defaulting to "heads/origin".' % self.get_name()),
                  ('Consider setting "branch.%s.stgit.parentbranch"'
                   ' with "git config".' % self.get_name()))
         return 'heads/origin'
     else:
         raise StackException('Cannot find a parent branch for "%s"' %
                              self.get_name())
예제 #3
0
파일: stack.py 프로젝트: snits/stgit
 def get_parent_remote(self):
     value = config.get('branch.%s.remote' % self.get_name())
     if value:
         return value
     elif 'origin' in git.remotes_list():
         out.note(('No parent remote declared for stack "%s",'
                   ' defaulting to "origin".' % self.get_name()),
                  ('Consider setting "branch.%s.remote" and'
                   ' "branch.%s.merge" with "git config".'
                   % (self.get_name(), self.get_name())))
         return 'origin'
     else:
         raise StackException('Cannot find a parent remote for "%s"' %
                              self.get_name())
예제 #4
0
 def get_parent_remote(self):
     value = config.get('branch.%s.remote' % self.get_name())
     if value:
         return value
     elif 'origin' in git.remotes_list():
         out.note(('No parent remote declared for stack "%s",'
                   ' defaulting to "origin".' % self.get_name()),
                  ('Consider setting "branch.%s.remote" and'
                   ' "branch.%s.merge" with "git config".'
                   % (self.get_name(), self.get_name())))
         return 'origin'
     else:
         raise StackException('Cannot find a parent remote for "%s"' %
                              self.get_name())
예제 #5
0
def func(parser, options, args):
    """Pull the changes from a remote repository
    """
    repository = directory.repository
    iw = repository.default_iw
    stack = repository.get_stack()
    policy = (config.get('branch.%s.stgit.pull-policy' % stack.name)
              or config.get('stgit.pull-policy'))

    if policy == 'rebase':
        # parent is local
        if len(args) == 1:
            parser.error(
                'specifying a repository is meaningless for policy="%s"' %
                (policy, ))
        elif len(args) > 0:
            parser.error('incorrect number of arguments')
    else:
        # parent is remote
        if len(args) > 1:
            parser.error('incorrect number of arguments')

        if len(args) >= 1:
            remote_name = args[0]
        else:
            remote_name = stack.parent_remote

    if stack.protected:
        raise CmdException('This branch is protected. Pulls are not permitted')

    if policy not in ['pull', 'fetch-rebase', 'rebase']:
        raise GitConfigException('Unsupported pull-policy "%s"' % policy)

    applied = stack.patchorder.applied

    retval = prepare_rebase(stack, 'pull')
    if retval:
        return retval

    # pull the remote changes
    if policy == 'pull':
        out.info('Pulling from "%s"' % remote_name)
        pull(repository, remote_name)
    elif policy == 'fetch-rebase':
        out.info('Fetching from "%s"' % remote_name)
        fetch(repository, remote_name)
        try:
            target = repository.rev_parse('FETCH_HEAD')
        except RepositoryException:
            out.error('Could not find the remote head to rebase onto - '
                      'fix branch.%s.merge in .git/config' % stack.name)
            out.error('Pushing any patches back...')
            post_rebase(stack, applied, 'pull', check_merged=False)
            raise

        rebase(stack, iw, target)
    elif policy == 'rebase':
        value = config.get('branch.%s.stgit.parentbranch' % stack.name)
        if value:
            parent_commit = git_commit(value, repository)
        else:
            try:
                parent_commit = repository.rev_parse('heads/origin')
            except RepositoryException:
                raise CmdException('Cannot find a parent branch for "%s"' %
                                   stack.name)
            else:
                out.note(
                    'No parent branch declared for stack "%s", defaulting to'
                    '"heads/origin".' % stack.name,
                    'Consider setting "branch.%s.stgit.parentbranch" with '
                    '"git config".' % stack.name,
                )
        rebase(stack, iw, parent_commit)

    if not options.nopush:
        post_rebase(stack, applied, 'pull', check_merged=options.merged)

    # maybe tidy up
    if config.getbool('stgit.keepoptimized'):
        repository.repack()