| 1 | __copyright__ = """ |
| 2 | Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com> |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License version 2 as |
| 6 | published by the Free Software Foundation. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | """ |
| 17 | |
| 18 | import sys, os |
| 19 | from optparse import OptionParser, make_option |
| 20 | |
| 21 | from stgit.commands.common import * |
| 22 | from stgit.utils import * |
| 23 | from stgit import stack, git |
| 24 | |
| 25 | |
| 26 | help = 'pull the changes from the remote repository' |
| 27 | usage = """%prog [options] [<repository>] [<refspec>] |
| 28 | |
| 29 | Pull the latest changes from the given repository (defaulting to |
| 30 | 'origin'). This command works by popping all the patches from the |
| 31 | stack, pulling the changes in the parent repository, setting the base |
| 32 | of the stack to the latest parent HEAD and pushing the patches back |
| 33 | (unless '--nopush' is specified). The 'push' operation can fail if |
| 34 | there are conflicts. They need to be resolved and the patch pushed |
| 35 | again. |
| 36 | |
| 37 | Check the 'git pull' documentation for the <repository> and <refspec> |
| 38 | format.""" |
| 39 | |
| 40 | options = [make_option('-n', '--nopush', |
| 41 | help = 'do not push the patches back after pulling', |
| 42 | action = 'store_true'), |
| 43 | make_option('-m', '--merged', |
| 44 | help = 'check for patches merged upstream', |
| 45 | action = 'store_true')] |
| 46 | |
| 47 | def func(parser, options, args): |
| 48 | """Pull the changes from a remote repository |
| 49 | """ |
| 50 | if len(args) > 2: |
| 51 | parser.error('incorrect number of arguments') |
| 52 | |
| 53 | repository = 'origin' |
| 54 | refspec = None |
| 55 | if len(args) >= 1: |
| 56 | repository = args[0] |
| 57 | if len(args) == 2: |
| 58 | refspec = args[1] |
| 59 | |
| 60 | if crt_series.get_protected(): |
| 61 | raise CmdException, 'This branch is protected. Pulls are not permitted' |
| 62 | |
| 63 | check_local_changes() |
| 64 | check_conflicts() |
| 65 | check_head_top_equal() |
| 66 | |
| 67 | # pop all patches |
| 68 | applied = crt_series.get_applied() |
| 69 | if len(applied) > 0: |
| 70 | print 'Popping all applied patches...', |
| 71 | sys.stdout.flush() |
| 72 | crt_series.pop_patch(applied[0]) |
| 73 | print 'done' |
| 74 | |
| 75 | # pull the remote changes |
| 76 | print 'Pulling from "%s"...' % repository |
| 77 | git.pull(repository, refspec) |
| 78 | print 'done' |
| 79 | |
| 80 | # push the patches back |
| 81 | if not options.nopush: |
| 82 | push_patches(applied, options.merged) |
| 83 | |
| 84 | # maybe tidy up |
| 85 | repack = config.get('stgit', 'keepoptimized') |
| 86 | if repack == 'yes': |
| 87 | git.repack() |
| 88 | |
| 89 | print_crt_patch() |