-
Notifications
You must be signed in to change notification settings - Fork 0
/
idatb.py
executable file
·65 lines (54 loc) · 1.55 KB
/
idatb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
"""
Interactively deleting all the branches.
"""
import os
import sys
from git import Repo
from PyInquirer import prompt, style_from_dict, Token
from termcolor import colored
STYLE = style_from_dict({
Token.Separator: '#cc5454',
Token.QuestionMark: '#673ab7 bold',
Token.Selected: '#cc5454', # default
Token.Pointer: '#673ab7 bold',
Token.Instruction: '', # default
Token.Answer: '#f44336 bold',
Token.Question: '',
})
# Assume we get a repo dir otherwise, get current path.
if len(sys.argv) > 1:
repo_dir = sys.argv[1]
else:
repo_dir = os.getcwd()
repo = Repo(repo_dir)
# Compile choices.
choices = []
for branch in repo.branches:
choices.append({'name': branch.name})
# Compile data for pyinquirer.
prompt_data = [
{
'type': 'checkbox',
'message': 'Select branches to delete locally.',
'name': 'local branches',
'choices': choices,
},
]
# Prompt the thing.
answers = prompt(prompt_data, style=STYLE)
# Print the choices for confirmation.
for answer in answers['local branches']:
print(colored(answer, 'red'))
# Prompt confirmation
cont = input(colored('Continue? (y/N)\n', 'green'))
if cont != 'y':
print(colored('Try again. ¯\\_(ツ)_/¯'))
sys.exit()
# Do the magic. :hurray:
for git_branch in answers['local branches']:
if repo.active_branch.name == git_branch:
print(colored('Can\'t delete current active branch \'%s\'' % git_branch, 'red'))
else:
print('Deleting locally: %s' % git_branch)
repo.git.branch('-D', git_branch)