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