blob: 8af61327e904d0b4b764ad57a6749d2dc6b1122b [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 = []
44 all = self.GetProjects(args[1:])
45
46 pm = Progress('Abandon %s' % nb, len(all))
47 for project in all:
48 pm.update()
49 if not project.AbandonBranch(nb):
50 err.append(project)
51 pm.end()
52
53 if err:
54 if len(err) == len(all):
55 print >>sys.stderr, 'error: no project has branch %s' % nb
56 else:
57 for p in err:
58 print >>sys.stderr,\
59 "error: %s/: cannot abandon %s" \
60 % (p.relpath, nb)
61 sys.exit(1)