blob: e17ab2b664855c988c5900e6dfc5cb5df5b960fa [file] [log] [blame]
Shawn O. Pearce9fa44db2008-11-03 11:24:59 -08001#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import sys
17from command import Command
18from git_command import git
Shawn O. Pearce552ac892009-04-18 15:15:24 -070019from progress import Progress
Shawn O. Pearce9fa44db2008-11-03 11:24:59 -080020
21class Abandon(Command):
22 common = True
23 helpSummary = "Permanently abandon a development branch"
24 helpUsage = """
25%prog <branchname> [<project>...]
26
27This subcommand permanently abandons a development branch by
28deleting it (and all its history) from your local repository.
29
30It is equivalent to "git branch -D <branchname>".
31"""
32
33 def Execute(self, opt, args):
34 if not args:
35 self.Usage()
36
37 nb = args[0]
38 if not git.check_ref_format('heads/%s' % nb):
39 print >>sys.stderr, "error: '%s' is not a valid name" % nb
40 sys.exit(1)
41
Shawn O. Pearce552ac892009-04-18 15:15:24 -070042 nb = args[0]
43 err = []
Doug Andersondafb1d62011-04-07 11:46:59 -070044 success = []
David Pursehouse5c6eeac2012-10-11 16:44:48 +090045 all_projects = self.GetProjects(args[1:])
Shawn O. Pearce552ac892009-04-18 15:15:24 -070046
David Pursehouse5c6eeac2012-10-11 16:44:48 +090047 pm = Progress('Abandon %s' % nb, len(all_projects))
48 for project in all_projects:
Shawn O. Pearce552ac892009-04-18 15:15:24 -070049 pm.update()
Doug Andersondafb1d62011-04-07 11:46:59 -070050
51 status = project.AbandonBranch(nb)
52 if status is not None:
53 if status:
54 success.append(project)
55 else:
56 err.append(project)
Shawn O. Pearce552ac892009-04-18 15:15:24 -070057 pm.end()
58
59 if err:
Doug Andersondafb1d62011-04-07 11:46:59 -070060 for p in err:
61 print >>sys.stderr,\
62 "error: %s/: cannot abandon %s" \
63 % (p.relpath, nb)
Shawn O. Pearce552ac892009-04-18 15:15:24 -070064 sys.exit(1)
Doug Andersondafb1d62011-04-07 11:46:59 -070065 elif not success:
66 print >>sys.stderr, 'error: no project has branch %s' % nb
67 sys.exit(1)
68 else:
69 print >>sys.stderr, 'Abandoned in %d project(s):\n %s' % (
70 len(success), '\n '.join(p.relpath for p in success))