summaryrefslogtreecommitdiffstats
path: root/subcmds/abandon.py
diff options
context:
space:
mode:
authorKyunam.jo <kyunam.jo@lge.com>2016-10-12 16:33:19 +0900
committerKyunam Jo <kyunam.jo@lge.com>2016-10-17 02:29:42 +0000
commit2e14792a9481736e4b532da64813a7cb856c48a0 (patch)
treeeb9c9db4514da7032f3a172873ce6dc1247beca0 /subcmds/abandon.py
parent699bcd40be2c10e7e55d955e245f0621b8fab110 (diff)
downloadgit-repo-2e14792a9481736e4b532da64813a7cb856c48a0.tar.gz
implement optional '--all' in the abandon command
when you want to delete all local branches, you should be find all branches' name, and type them behind 'repo abandon' command. Usage: repo abandon --all [<project>...] Change-Id: I4d391f37fb9d89b8095488c585468eafc1a35f31
Diffstat (limited to 'subcmds/abandon.py')
-rw-r--r--subcmds/abandon.py70
1 files changed, 49 insertions, 21 deletions
diff --git a/subcmds/abandon.py b/subcmds/abandon.py
index 84517b91..6f78da74 100644
--- a/subcmds/abandon.py
+++ b/subcmds/abandon.py
@@ -16,6 +16,7 @@
16from __future__ import print_function 16from __future__ import print_function
17import sys 17import sys
18from command import Command 18from command import Command
19from collections import defaultdict
19from git_command import git 20from git_command import git
20from progress import Progress 21from progress import Progress
21 22
@@ -23,48 +24,75 @@ class Abandon(Command):
23 common = True 24 common = True
24 helpSummary = "Permanently abandon a development branch" 25 helpSummary = "Permanently abandon a development branch"
25 helpUsage = """ 26 helpUsage = """
26%prog <branchname> [<project>...] 27%prog [--all | <branchname>] [<project>...]
27 28
28This subcommand permanently abandons a development branch by 29This subcommand permanently abandons a development branch by
29deleting it (and all its history) from your local repository. 30deleting it (and all its history) from your local repository.
30 31
31It is equivalent to "git branch -D <branchname>". 32It is equivalent to "git branch -D <branchname>".
32""" 33"""
34 def _Options(self, p):
35 p.add_option('--all',
36 dest='all', action='store_true',
37 help='delete all branches in all projects')
33 38
34 def Execute(self, opt, args): 39 def Execute(self, opt, args):
35 if not args: 40 if not opt.all and not args:
36 self.Usage() 41 self.Usage()
37 42
38 nb = args[0] 43 if not opt.all:
39 if not git.check_ref_format('heads/%s' % nb): 44 nb = args[0]
40 print("error: '%s' is not a valid name" % nb, file=sys.stderr) 45 if not git.check_ref_format('heads/%s' % nb):
41 sys.exit(1) 46 print("error: '%s' is not a valid name" % nb, file=sys.stderr)
47 sys.exit(1)
48 else:
49 args.insert(0,None)
50 nb = "'All local branches'"
42 51
43 err = [] 52 err = defaultdict(list)
44 success = [] 53 success = defaultdict(list)
45 all_projects = self.GetProjects(args[1:]) 54 all_projects = self.GetProjects(args[1:])
46 55
47 pm = Progress('Abandon %s' % nb, len(all_projects)) 56 pm = Progress('Abandon %s' % nb, len(all_projects))
48 for project in all_projects: 57 for project in all_projects:
49 pm.update() 58 pm.update()
50 59
51 status = project.AbandonBranch(nb) 60 if opt.all:
52 if status is not None: 61 branches = project.GetBranches().keys()
53 if status: 62 else:
54 success.append(project) 63 branches = [nb]
55 else: 64
56 err.append(project) 65 for name in branches:
66 status = project.AbandonBranch(name)
67 if status is not None:
68 if status:
69 success[name].append(project)
70 else:
71 err[name].append(project)
57 pm.end() 72 pm.end()
58 73
74 width = 25
75 for name in branches:
76 if width < len(name):
77 width = len(name)
78
59 if err: 79 if err:
60 for p in err: 80 for br in err.keys():
61 print("error: %s/: cannot abandon %s" % (p.relpath, nb), 81 err_msg = "error: cannot abandon %s" %br
62 file=sys.stderr) 82 print(err_msg, file=sys.stderr)
83 for proj in err[br]:
84 print(' '*len(err_msg) + " | %s" % p.relpath, file=sys.stderr)
63 sys.exit(1) 85 sys.exit(1)
64 elif not success: 86 elif not success:
65 print('error: no project has branch %s' % nb, file=sys.stderr) 87 print('error: no project has local branch(es) : %s' % nb,
88 file=sys.stderr)
66 sys.exit(1) 89 sys.exit(1)
67 else: 90 else:
68 print('Abandoned in %d project(s):\n %s' 91 print('Abandoned branches:', file=sys.stderr)
69 % (len(success), '\n '.join(p.relpath for p in success)), 92 for br in success.keys():
70 file=sys.stderr) 93 if len(all_projects) > 1 and len(all_projects) == len(success[br]):
94 result = "all project"
95 else:
96 result = "%s" % (
97 ('\n'+' '*width + '| ').join(p.relpath for p in success[br]))
98 print("%s%s| %s\n" % (br,' '*(width-len(br)), result),file=sys.stderr)