Commit | Line | Data |
---|---|---|
f338c3c0 CM |
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 | |
575bbdae | 19 | from stgit.argparse import opt |
f338c3c0 CM |
20 | from stgit.commands.common import * |
21 | from stgit.utils import * | |
5e888f30 | 22 | from stgit.out import * |
5a6d315e | 23 | from stgit.config import GitConfigException |
f338c3c0 CM |
24 | from stgit import stack, git |
25 | ||
575bbdae KH |
26 | help = 'Pull changes from a remote repository' |
27 | usage = ['[options] [<repository>]'] | |
28 | description = """ | |
d060dfd3 YD |
29 | Pull the latest changes from the given remote repository (defaulting |
30 | to branch.<name>.remote, or 'origin' if not set). This command works | |
31 | by popping all the patches from the stack, pulling the changes in the | |
32 | parent repository, setting the base of the stack to the latest parent | |
33 | HEAD and pushing the patches back (unless '--nopush' is specified). | |
34 | The 'push' operation can fail if there are conflicts. They need to be | |
35 | resolved and the patch pushed again. | |
26aab5b0 | 36 | |
d060dfd3 | 37 | Check the 'git fetch' documentation for the <repository> format.""" |
f338c3c0 | 38 | |
575bbdae KH |
39 | options = [ |
40 | opt('-n', '--nopush', action = 'store_true', | |
41 | short = 'Do not push the patches back after pulling'), | |
42 | opt('-m', '--merged', action = 'store_true', | |
43 | short = 'Check for patches merged upstream')] | |
44 | ||
7b601c9e | 45 | directory = DirectoryGotoToplevel() |
f338c3c0 CM |
46 | |
47 | def func(parser, options, args): | |
48 | """Pull the changes from a remote repository | |
49 | """ | |
d37ff079 | 50 | policy = config.get('branch.%s.stgit.pull-policy' % crt_series.get_name()) or \ |
1fa161d6 YD |
51 | config.get('stgit.pull-policy') |
52 | ||
53 | if policy == 'rebase': | |
54 | # parent is local | |
55 | if len(args) == 1: | |
56 | parser.error('specifying a repository is meaningless for policy="%s"' % policy) | |
57 | if len(args) > 0: | |
58 | parser.error('incorrect number of arguments') | |
f338c3c0 | 59 | |
87c69539 | 60 | else: |
1fa161d6 YD |
61 | # parent is remote |
62 | if len(args) > 1: | |
63 | parser.error('incorrect number of arguments') | |
64 | ||
65 | if len(args) >= 1: | |
66 | repository = args[0] | |
67 | else: | |
68 | repository = crt_series.get_parent_remote() | |
87c69539 | 69 | |
0b4b9499 CL |
70 | if crt_series.get_protected(): |
71 | raise CmdException, 'This branch is protected. Pulls are not permitted' | |
72 | ||
f338c3c0 CM |
73 | check_local_changes() |
74 | check_conflicts() | |
6972fd6b | 75 | check_head_top_equal(crt_series) |
f338c3c0 | 76 | |
64e15469 | 77 | if policy not in ['pull', 'fetch-rebase', 'rebase']: |
5a6d315e | 78 | raise GitConfigException, 'Unsupported pull-policy "%s"' % policy |
3b3c26fa | 79 | |
6972fd6b | 80 | applied = prepare_rebase(crt_series) |
ddbbfd84 CM |
81 | |
82 | # pull the remote changes | |
3b3c26fa | 83 | if policy == 'pull': |
27ac2b7e | 84 | out.info('Pulling from "%s"' % repository) |
3b3c26fa YD |
85 | git.pull(repository) |
86 | elif policy == 'fetch-rebase': | |
27ac2b7e | 87 | out.info('Fetching from "%s"' % repository) |
3b3c26fa | 88 | git.fetch(repository) |
764d1101 YD |
89 | try: |
90 | target = git.fetch_head() | |
91 | except git.GitException: | |
b029e3cc CM |
92 | out.error('Could not find the remote head to rebase onto - fix branch.%s.merge in .git/config' % crt_series.get_name()) |
93 | out.error('Pushing any patches back...') | |
6972fd6b | 94 | post_rebase(crt_series, applied, False, False) |
b029e3cc | 95 | raise |
764d1101 | 96 | |
6972fd6b | 97 | rebase(crt_series, target) |
3b3c26fa | 98 | elif policy == 'rebase': |
6972fd6b | 99 | rebase(crt_series, crt_series.get_parent_branch()) |
a9f3a9fc | 100 | |
6972fd6b | 101 | post_rebase(crt_series, applied, options.nopush, options.merged) |
f338c3c0 | 102 | |
925ff4a7 | 103 | # maybe tidy up |
c73e63b7 | 104 | if config.get('stgit.keepoptimized') == 'yes': |
925ff4a7 CL |
105 | git.repack() |
106 | ||
6972fd6b | 107 | print_crt_patch(crt_series) |