| 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.config import GitConfigException |
| 24 | from stgit import stack, git |
| 25 | |
| 26 | |
| 27 | help = 'pull the changes from the remote repository' |
| 28 | usage = """%prog [options] [<repository>] |
| 29 | |
| 30 | Pull the latest changes from the given remote repository (defaulting |
| 31 | to branch.<name>.remote, or 'origin' if not set). This command works |
| 32 | by popping all the patches from the stack, pulling the changes in the |
| 33 | parent repository, setting the base of the stack to the latest parent |
| 34 | HEAD and pushing the patches back (unless '--nopush' is specified). |
| 35 | The 'push' operation can fail if there are conflicts. They need to be |
| 36 | resolved and the patch pushed again. |
| 37 | |
| 38 | Check the 'git fetch' documentation for the <repository> 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 | make_option('--force', |
| 47 | help = 'force rebase even if the stack based was moved by (un)commits', |
| 48 | action = 'store_true')] |
| 49 | |
| 50 | def func(parser, options, args): |
| 51 | """Pull the changes from a remote repository |
| 52 | """ |
| 53 | policy = config.get('branch.%s.stgit.pull-policy' % crt_series.get_branch()) or \ |
| 54 | config.get('stgit.pull-policy') |
| 55 | |
| 56 | if policy == 'rebase': |
| 57 | # parent is local |
| 58 | if len(args) == 1: |
| 59 | parser.error('specifying a repository is meaningless for policy="%s"' % policy) |
| 60 | if len(args) > 0: |
| 61 | parser.error('incorrect number of arguments') |
| 62 | |
| 63 | else: |
| 64 | # parent is remote |
| 65 | if len(args) > 1: |
| 66 | parser.error('incorrect number of arguments') |
| 67 | |
| 68 | if len(args) >= 1: |
| 69 | repository = args[0] |
| 70 | else: |
| 71 | repository = crt_series.get_parent_remote() |
| 72 | |
| 73 | if crt_series.get_protected(): |
| 74 | raise CmdException, 'This branch is protected. Pulls are not permitted' |
| 75 | |
| 76 | check_local_changes() |
| 77 | check_conflicts() |
| 78 | check_head_top_equal() |
| 79 | |
| 80 | if policy == 'pull': |
| 81 | must_rebase = 0 |
| 82 | elif policy == 'fetch-rebase': |
| 83 | must_rebase = 1 |
| 84 | elif policy == 'rebase': |
| 85 | must_rebase = 1 |
| 86 | else: |
| 87 | raise GitConfigException, 'Unsupported pull-policy "%s"' % policy |
| 88 | |
| 89 | applied = prepare_rebase(real_rebase=must_rebase, force=options.force) |
| 90 | |
| 91 | # pull the remote changes |
| 92 | if policy == 'pull': |
| 93 | out.info('Pulling from "%s"' % repository) |
| 94 | git.pull(repository) |
| 95 | elif policy == 'fetch-rebase': |
| 96 | out.info('Fetching from "%s"' % repository) |
| 97 | git.fetch(repository) |
| 98 | rebase(git.fetch_head()) |
| 99 | elif policy == 'rebase': |
| 100 | rebase(crt_series.get_parent_branch()) |
| 101 | |
| 102 | post_rebase(applied, options.nopush, options.merged) |
| 103 | |
| 104 | # maybe tidy up |
| 105 | if config.get('stgit.keepoptimized') == 'yes': |
| 106 | git.repack() |
| 107 | |
| 108 | print_crt_patch() |