blob: 84517b9103b72adee004c1fd69aca8680acaacbc [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
Sarah Owenscecd1d82012-11-01 22:59:27 -070016from __future__ import print_function
Shawn O. Pearce9fa44db2008-11-03 11:24:59 -080017import sys
18from command import Command
19from git_command import git
Shawn O. Pearce552ac892009-04-18 15:15:24 -070020from progress import Progress
Shawn O. Pearce9fa44db2008-11-03 11:24:59 -080021
22class Abandon(Command):
23 common = True
24 helpSummary = "Permanently abandon a development branch"
25 helpUsage = """
26%prog <branchname> [<project>...]
27
28This subcommand permanently abandons a development branch by
29deleting it (and all its history) from your local repository.
30
31It is equivalent to "git branch -D <branchname>".
32"""
33
34 def Execute(self, opt, args):
35 if not args:
36 self.Usage()
37
38 nb = args[0]
39 if not git.check_ref_format('heads/%s' % nb):
Sarah Owenscecd1d82012-11-01 22:59:27 -070040 print("error: '%s' is not a valid name" % nb, file=sys.stderr)
Shawn O. Pearce9fa44db2008-11-03 11:24:59 -080041 sys.exit(1)
42
Shawn O. Pearce552ac892009-04-18 15:15:24 -070043 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:
Sarah Owenscecd1d82012-11-01 22:59:27 -070061 print("error: %s/: cannot abandon %s" % (p.relpath, nb),
62 file=sys.stderr)
Shawn O. Pearce552ac892009-04-18 15:15:24 -070063 sys.exit(1)
Doug Andersondafb1d62011-04-07 11:46:59 -070064 elif not success:
Sarah Owenscecd1d82012-11-01 22:59:27 -070065 print('error: no project has branch %s' % nb, file=sys.stderr)
Doug Andersondafb1d62011-04-07 11:46:59 -070066 sys.exit(1)
67 else:
Sarah Owenscecd1d82012-11-01 22:59:27 -070068 print('Abandoned in %d project(s):\n %s'
69 % (len(success), '\n '.join(p.relpath for p in success)),
70 file=sys.stderr)