blob: b94ccdd3be41e69cd8e217dc94438af5d763ab1b [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 nb = args[0]
44 err = []
Doug Andersondafb1d62011-04-07 11:46:59 -070045 success = []
David Pursehouse5c6eeac2012-10-11 16:44:48 +090046 all_projects = self.GetProjects(args[1:])
Shawn O. Pearce552ac892009-04-18 15:15:24 -070047
David Pursehouse5c6eeac2012-10-11 16:44:48 +090048 pm = Progress('Abandon %s' % nb, len(all_projects))
49 for project in all_projects:
Shawn O. Pearce552ac892009-04-18 15:15:24 -070050 pm.update()
Doug Andersondafb1d62011-04-07 11:46:59 -070051
52 status = project.AbandonBranch(nb)
53 if status is not None:
54 if status:
55 success.append(project)
56 else:
57 err.append(project)
Shawn O. Pearce552ac892009-04-18 15:15:24 -070058 pm.end()
59
60 if err:
Doug Andersondafb1d62011-04-07 11:46:59 -070061 for p in err:
Sarah Owenscecd1d82012-11-01 22:59:27 -070062 print("error: %s/: cannot abandon %s" % (p.relpath, nb),
63 file=sys.stderr)
Shawn O. Pearce552ac892009-04-18 15:15:24 -070064 sys.exit(1)
Doug Andersondafb1d62011-04-07 11:46:59 -070065 elif not success:
Sarah Owenscecd1d82012-11-01 22:59:27 -070066 print('error: no project has branch %s' % nb, file=sys.stderr)
Doug Andersondafb1d62011-04-07 11:46:59 -070067 sys.exit(1)
68 else:
Sarah Owenscecd1d82012-11-01 22:59:27 -070069 print('Abandoned in %d project(s):\n %s'
70 % (len(success), '\n '.join(p.relpath for p in success)),
71 file=sys.stderr)