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