Shawn O. Pearce | 9fa44db | 2008-11-03 11:24:59 -0800 | [diff] [blame] | 1 | # |
| 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 | |
| 16 | import sys |
| 17 | from command import Command |
| 18 | from git_command import git |
Shawn O. Pearce | 552ac89 | 2009-04-18 15:15:24 -0700 | [diff] [blame] | 19 | from progress import Progress |
Shawn O. Pearce | 9fa44db | 2008-11-03 11:24:59 -0800 | [diff] [blame] | 20 | |
| 21 | class Abandon(Command): |
| 22 | common = True |
| 23 | helpSummary = "Permanently abandon a development branch" |
| 24 | helpUsage = """ |
| 25 | %prog <branchname> [<project>...] |
| 26 | |
| 27 | This subcommand permanently abandons a development branch by |
| 28 | deleting it (and all its history) from your local repository. |
| 29 | |
| 30 | It 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. Pearce | 552ac89 | 2009-04-18 15:15:24 -0700 | [diff] [blame] | 42 | nb = args[0] |
| 43 | err = [] |
Doug Anderson | dafb1d6 | 2011-04-07 11:46:59 -0700 | [diff] [blame] | 44 | success = [] |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 45 | all_projects = self.GetProjects(args[1:]) |
Shawn O. Pearce | 552ac89 | 2009-04-18 15:15:24 -0700 | [diff] [blame] | 46 | |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 47 | pm = Progress('Abandon %s' % nb, len(all_projects)) |
| 48 | for project in all_projects: |
Shawn O. Pearce | 552ac89 | 2009-04-18 15:15:24 -0700 | [diff] [blame] | 49 | pm.update() |
Doug Anderson | dafb1d6 | 2011-04-07 11:46:59 -0700 | [diff] [blame] | 50 | |
| 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. Pearce | 552ac89 | 2009-04-18 15:15:24 -0700 | [diff] [blame] | 57 | pm.end() |
| 58 | |
| 59 | if err: |
Doug Anderson | dafb1d6 | 2011-04-07 11:46:59 -0700 | [diff] [blame] | 60 | for p in err: |
| 61 | print >>sys.stderr,\ |
| 62 | "error: %s/: cannot abandon %s" \ |
| 63 | % (p.relpath, nb) |
Shawn O. Pearce | 552ac89 | 2009-04-18 15:15:24 -0700 | [diff] [blame] | 64 | sys.exit(1) |
Doug Anderson | dafb1d6 | 2011-04-07 11:46:59 -0700 | [diff] [blame] | 65 | 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)) |