Exemplo n.º 1
0
def merged_branches(remote=None, ignore=IGNORE):
    """Sequence of branches that have been merged onto the current branch."""
    if remote:
        command = 'git branch -a --merged'
    else:
        command = 'git branch --merged'

    for name in checked_execute(command).split('\n'):
        # The command also lists the current branch, so we get rid of it
        if name.startswith('* ') or ' -> ' in name:
            continue
        name = name.strip()

        if remote and name.startswith('remotes/'):
            name = name[8:]
            if name.startswith(remote):
                branch = Branch(name=name[len(remote) + 1:], remote=remote)
            else:
                continue
        else:
            branch = Branch(name)

        if branch.name in ignore:
            continue
        yield branch
Exemplo n.º 2
0
    def merge_date(self):
        '''Returns the date when the specified branch was merged into the
        current git branch. On the console, you can try this command:

            git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" BRANCH | head -n 1
        '''
        line = checked_execute(
            'git show --pretty=format:"%ci" {} | head -n 1'
            .format(self.prefix + self.name))
        sdate = line[:10]
        year, month, day = [int(x) for x in sdate.split('-')]
        return date(year, month, day)
Exemplo n.º 3
0
    def merge_date(self):
        """Returns the date when the specified branch was merged into the
        current git branch. On the console, you can try this command:

            git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" BRANCH | head -n 1
        """
        branch_spec = repr(self)
        line = checked_execute(
            'git show --pretty=format:"%ci" {} | head -n 1'
            .format(branch_spec))
        sdate = line[:10]
        year, month, day = [int(x) for x in sdate.split('-')]
        return date(year, month, day)
Exemplo n.º 4
0
def merged_branches(remote=None):
    '''Sequence of branches that have been merged onto the current branch.'''
    if remote:
        command = 'git branch -a --merged'
        remote = 'remotes/{}/'.format(remote)
    else:
        command = 'git branch --merged'
    alist = []
    for branch in checked_execute(command).split('\n'):
        # The command also lists the current branch, so we get rid of it
        if branch.startswith('* ') or ' -> ' in branch:
            continue
        branch = branch.strip()
        if remote and branch.startswith(remote):
            branch = branch[len(remote):]
        alist.append(branch)
    unique = set(alist)
    return [Branch(branch, remote) for branch in unique]
Exemplo n.º 5
0
 def delete(self):
     if self.remote:
         checked_execute('git push {} :{}'.format(self.remote, self.name),
                         accept_codes=[0, 1])
     else:
         checked_execute('git branch -d {}'.format(self))
Exemplo n.º 6
0
 def delete_remotely(self, remote):
     checked_execute('git push {} :{}'.format(remote, self),
                     accept_codes=[0, 1])
Exemplo n.º 7
0
 def delete_locally(self):
     checked_execute('git branch -d {}'.format(self))