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 * | |
23 | from stgit import stack, git | |
24 | ||
25 | ||
26 | help = 'pull the changes from the remote repository' | |
8f5da35b | 27 | usage = """%prog [options] [<repository>] |
26aab5b0 | 28 | |
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 CM |
38 | |
39 | options = [make_option('-n', '--nopush', | |
40 | help = 'do not push the patches back after pulling', | |
1777d8cd CM |
41 | action = 'store_true'), |
42 | make_option('-m', '--merged', | |
43 | help = 'check for patches merged upstream', | |
e5834af7 YD |
44 | action = 'store_true'), |
45 | make_option('--force', | |
46 | help = 'force rebase even if the stack based was moved by (un)commits', | |
1f5e9148 | 47 | action = 'store_true')] |
f338c3c0 CM |
48 | |
49 | def func(parser, options, args): | |
50 | """Pull the changes from a remote repository | |
51 | """ | |
8f5da35b | 52 | if len(args) > 1: |
f338c3c0 CM |
53 | parser.error('incorrect number of arguments') |
54 | ||
1f5e9148 CM |
55 | if len(args) >= 1: |
56 | repository = args[0] | |
87c69539 | 57 | else: |
254d99f8 | 58 | repository = crt_series.get_parent_remote() |
87c69539 | 59 | |
0b4b9499 CL |
60 | if crt_series.get_protected(): |
61 | raise CmdException, 'This branch is protected. Pulls are not permitted' | |
62 | ||
f338c3c0 CM |
63 | check_local_changes() |
64 | check_conflicts() | |
65 | check_head_top_equal() | |
66 | ||
e5834af7 YD |
67 | must_rebase = (config.get('stgit.pull-does-rebase') == 'yes') |
68 | applied = prepare_rebase(real_rebase=must_rebase, force=options.force) | |
ddbbfd84 CM |
69 | |
70 | # pull the remote changes | |
1f5e9148 | 71 | print 'Pulling from "%s"...' % repository |
d060dfd3 | 72 | git.fetch(repository) |
e5834af7 | 73 | if must_rebase: |
a9f3a9fc YD |
74 | rebase(git.fetch_head()) |
75 | ||
76 | post_rebase(applied, options.nopush, options.merged) | |
f338c3c0 | 77 | |
925ff4a7 | 78 | # maybe tidy up |
c73e63b7 | 79 | if config.get('stgit.keepoptimized') == 'yes': |
925ff4a7 CL |
80 | git.repack() |
81 | ||
f338c3c0 | 82 | print_crt_patch() |