コード例 #1
0
Archive branches that are merged into master.
This is done by tagging them as archive/<branchname> and removing them both locally and
remotely. Before each operation, the user is asked for confirmation.
"""
# This dependency can be found on github: https://github.com/Chiel92/python-shellout
from pyshellout import get, out, confirm


# Tag merged branches
merged_branches = [line.strip() for line in
                   get(r'git branch --merged master').n]
merged_branches = [branch for branch in merged_branches
                   if branch != '' and not '*' in branch and not branch == 'master']
archived_branches = []
for branch in merged_branches:
    if confirm('Archive branch {}?', branch):
        out('git tag archive/{} {}', branch, branch)
        archived_branches.append(branch)

if not archived_branches:
    exit('No branches archived. Bye.')

# Push archive tags to remote
print()
print('Created archive tags:')
for branch in archived_branches:
    print('    ' + branch)
if confirm('Push archive tags to remote?'):
    for branch in archived_branches:
        out('git push origin archive/{}', branch)
コード例 #2
0
import sys
from pyshellout import get, out, confirm

MASTER = 'master'
ARGS_COUNT = len(sys.argv)
REFERENCE_BRANCH = MASTER if ARGS_COUNT <= 1 else sys.argv[1]

# Tag merged branches
merged_branches = [line.strip() for line in
                   get(r'git branch --merged ' + REFERENCE_BRANCH).n]
merged_branches = [branch for branch in merged_branches
                   if branch != '' and not '*' in branch and not branch == MASTER and not branch == REFERENCE_BRANCH]
archived_branches = []
archived_branches_all = []
for branch in merged_branches:
    if confirm('Archive branch {}?', branch):
        out('git tag archive/{} {}', branch, branch)
        archived_branches.append(branch)

if not archived_branches:
    exit('No branches archived. Bye.')

print('Next tasks are: push tags to remote, delete remote and local branches')
do_not_ask = not confirm('Request confirmation for every step?')

# Push archive tags to remote
print()
print('Created archive tags:')
for branch in archived_branches:
    print('    ' + branch)
if do_not_ask or confirm('Push archive tags to remote?'):
コード例 #3
0
    target = {
        '1': 'ours',
        '2': 'common',
        '3': 'theirs',
    }[role]

    out('git show {sha} > {filename}.{target}',
        sha=sha, filename=filename, target=target, critical=True, verbose=True)


print('You can now edit the generated files per triple (common, ours and theirs).')
print('After each triple, a 3-way merge is performed.')

for filename in filenames:
    if not confirm('Edit and merge {filename}?', filename=filename):
        continue

    out('vim {filename}.common {filename}.ours {filename}.theirs',
        filename=filename, verbose=True, critical=True)
    returncode = out('{kdiff3} {filename}.common {filename}.ours {filename}.theirs'
                     ' -o {filename}.result',
                     kdiff3=kdiff3, filename=filename, verbose=True)
    if returncode == 0 and confirm('Do you want to overwrite {filename} with {filename}.result'
                                   ' and mark the file as merged?', filename=filename):
        out('cp {filename}.result {filename}', filename=filename)
        out('git add {filename}', filename=filename)
        if confirm('Do you want to remove the merge artifacts?'):
            out('rm {filename}.common {filename}.ours {filename}.theirs {filename}.result',
                filename=filename)
コード例 #4
0
import argparse

# This dependency can be found on github: https://github.com/Chiel92/python-shellout
from pyshellout import get, out, confirm


parser = argparse.ArgumentParser()
parser.add_argument('master',
                    help='Name of the master branch. Defaults to \'master\'.',
                    nargs='?', default='master')
args = parser.parse_args()
master = args.master


# Get merged branches
merged_branches = [line.strip() for line in
                   get(r'git branch --merged {}', master, critical=True).n]
merged_branches = [branch for branch in merged_branches
                   if branch != '' and not '*' in branch and not branch == master]

print('Merged local branches:')
for branch in merged_branches:
    print('    ' + branch)


print()
for branch in merged_branches:
    if confirm('Delete local branch {}?', branch):
        out('git branch -d {}', branch)