Mercurial > hg
comparison hgext/mq.py @ 7398:2cd1308cb588
mq: gracefully abort qpush/qgoto to guarded patch (issue1186)
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 23 Nov 2008 00:44:31 -0800 |
parents | b6f5490effbf |
children | e71bda2d2087 |
comparison
equal
deleted
inserted
replaced
7397:4c92d8971809 | 7398:2cd1308cb588 |
---|---|
822 if i + off < len(self.series): | 822 if i + off < len(self.series): |
823 return self.series[i + off] | 823 return self.series[i + off] |
824 raise util.Abort(_("patch %s not in series") % patch) | 824 raise util.Abort(_("patch %s not in series") % patch) |
825 | 825 |
826 def push(self, repo, patch=None, force=False, list=False, | 826 def push(self, repo, patch=None, force=False, list=False, |
827 mergeq=None): | 827 mergeq=None, all=False): |
828 wlock = repo.wlock() | 828 wlock = repo.wlock() |
829 if repo.dirstate.parents()[0] != repo.changelog.tip(): | 829 if repo.dirstate.parents()[0] != repo.changelog.tip(): |
830 self.ui.status(_("(working directory not at tip)\n")) | 830 self.ui.status(_("(working directory not at tip)\n")) |
831 | |
832 if not self.series: | |
833 self.ui.warn(_('no patches in series\n')) | |
834 return 0 | |
831 | 835 |
832 try: | 836 try: |
833 patch = self.lookup(patch) | 837 patch = self.lookup(patch) |
834 # Suppose our series file is: A B C and the current 'top' | 838 # Suppose our series file is: A B C and the current 'top' |
835 # patch is B. qpush C should be performed (moving forward) | 839 # patch is B. qpush C should be performed (moving forward) |
839 info = self.isapplied(patch) | 843 info = self.isapplied(patch) |
840 if info: | 844 if info: |
841 if info[0] < len(self.applied) - 1: | 845 if info[0] < len(self.applied) - 1: |
842 raise util.Abort( | 846 raise util.Abort( |
843 _("cannot push to a previous patch: %s") % patch) | 847 _("cannot push to a previous patch: %s") % patch) |
844 if info[0] < len(self.series) - 1: | 848 self.ui.warn( |
845 self.ui.warn( | 849 _('qpush: %s is already at the top\n') % patch) |
846 _('qpush: %s is already at the top\n') % patch) | 850 return |
851 pushable, reason = self.pushable(patch) | |
852 if not pushable: | |
853 if reason: | |
854 reason = _('guarded by %r') % reason | |
847 else: | 855 else: |
848 self.ui.warn(_('all patches are currently applied\n')) | 856 reason = _('no matching guards') |
849 return | 857 self.ui.warn(_("cannot push '%s' - %s\n") % (patch, reason)) |
858 return 1 | |
859 elif all: | |
860 patch = self.series[-1] | |
861 if self.isapplied(patch): | |
862 self.ui.warn(_('all patches are currently applied\n')) | |
863 return 0 | |
850 | 864 |
851 # Following the above example, starting at 'top' of B: | 865 # Following the above example, starting at 'top' of B: |
852 # qpush should be performed (pushes C), but a subsequent | 866 # qpush should be performed (pushes C), but a subsequent |
853 # qpush without an argument is an error (nothing to | 867 # qpush without an argument is an error (nothing to |
854 # apply). This allows a loop of "...while hg qpush..." to | 868 # apply). This allows a loop of "...while hg qpush..." to |
855 # work as it detects an error when done | 869 # work as it detects an error when done |
856 if self.series_end() == len(self.series): | 870 start = self.series_end() |
871 if start == len(self.series): | |
857 self.ui.warn(_('patch series already fully applied\n')) | 872 self.ui.warn(_('patch series already fully applied\n')) |
858 return 1 | 873 return 1 |
859 if not force: | 874 if not force: |
860 self.check_localchanges(repo) | 875 self.check_localchanges(repo) |
861 | 876 |
862 self.applied_dirty = 1; | 877 self.applied_dirty = 1 |
863 start = self.series_end() | |
864 if start > 0: | 878 if start > 0: |
865 self.check_toppatch(repo) | 879 self.check_toppatch(repo) |
866 if not patch: | 880 if not patch: |
867 patch = self.series[start] | 881 patch = self.series[start] |
868 end = start + 1 | 882 end = start + 1 |
1998 When --force is applied, all local changes in patched files will be lost. | 2012 When --force is applied, all local changes in patched files will be lost. |
1999 """ | 2013 """ |
2000 q = repo.mq | 2014 q = repo.mq |
2001 mergeq = None | 2015 mergeq = None |
2002 | 2016 |
2003 if opts['all']: | |
2004 if not q.series: | |
2005 ui.warn(_('no patches in series\n')) | |
2006 return 0 | |
2007 patch = q.series[-1] | |
2008 if opts['merge']: | 2017 if opts['merge']: |
2009 if opts['name']: | 2018 if opts['name']: |
2010 newpath = repo.join(opts['name']) | 2019 newpath = repo.join(opts['name']) |
2011 else: | 2020 else: |
2012 newpath, i = lastsavename(q.path) | 2021 newpath, i = lastsavename(q.path) |
2014 ui.warn(_("no saved queues found, please use -n\n")) | 2023 ui.warn(_("no saved queues found, please use -n\n")) |
2015 return 1 | 2024 return 1 |
2016 mergeq = queue(ui, repo.join(""), newpath) | 2025 mergeq = queue(ui, repo.join(""), newpath) |
2017 ui.warn(_("merging with queue at: %s\n") % mergeq.path) | 2026 ui.warn(_("merging with queue at: %s\n") % mergeq.path) |
2018 ret = q.push(repo, patch, force=opts['force'], list=opts['list'], | 2027 ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
2019 mergeq=mergeq) | 2028 mergeq=mergeq, all=opts.get('all')) |
2020 return ret | 2029 return ret |
2021 | 2030 |
2022 def pop(ui, repo, patch=None, **opts): | 2031 def pop(ui, repo, patch=None, **opts): |
2023 """pop the current patch off the stack | 2032 """pop the current patch off the stack |
2024 | 2033 |