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' | |
1f5e9148 | 27 | usage = """%prog [options] [<repository>] [<refspec>] |
26aab5b0 | 28 | |
1f5e9148 | 29 | Pull the latest changes from the given repository (defaulting to |
3899a8e2 CM |
30 | 'origin'). This command works by popping all the patches from the |
31 | stack, pulling the changes in the parent repository, setting the base | |
d33c40f1 | 32 | of the stack to the latest parent HEAD and pushing the patches back |
3899a8e2 CM |
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. | |
26aab5b0 | 36 | |
1f5e9148 CM |
37 | Check the 'git pull' documentation for the <repository> and <refspec> |
38 | format.""" | |
f338c3c0 CM |
39 | |
40 | options = [make_option('-n', '--nopush', | |
41 | help = 'do not push the patches back after pulling', | |
1f5e9148 | 42 | action = 'store_true')] |
f338c3c0 CM |
43 | |
44 | def func(parser, options, args): | |
45 | """Pull the changes from a remote repository | |
46 | """ | |
1f5e9148 | 47 | if len(args) > 2: |
f338c3c0 CM |
48 | parser.error('incorrect number of arguments') |
49 | ||
1f5e9148 CM |
50 | repository = 'origin' |
51 | refspec = None | |
52 | if len(args) >= 1: | |
53 | repository = args[0] | |
54 | if len(args) == 2: | |
55 | refspec = args[1] | |
56 | ||
0b4b9499 CL |
57 | if crt_series.get_protected(): |
58 | raise CmdException, 'This branch is protected. Pulls are not permitted' | |
59 | ||
f338c3c0 CM |
60 | check_local_changes() |
61 | check_conflicts() | |
62 | check_head_top_equal() | |
63 | ||
ddbbfd84 CM |
64 | # pop all patches |
65 | applied = crt_series.get_applied() | |
66 | if len(applied) > 0: | |
67 | print 'Popping all patches...', | |
68 | sys.stdout.flush() | |
69 | crt_series.pop_patch(applied[0]) | |
70 | print 'done' | |
71 | ||
72 | # pull the remote changes | |
1f5e9148 CM |
73 | print 'Pulling from "%s"...' % repository |
74 | git.pull(repository, refspec) | |
f338c3c0 CM |
75 | print 'done' |
76 | ||
ddbbfd84 CM |
77 | # push the patches back |
78 | if options.nopush: | |
79 | applied = [] | |
80 | for p in applied: | |
81 | print 'Pushing patch "%s"...' % p, | |
82 | sys.stdout.flush() | |
83 | crt_series.push_patch(p) | |
84 | if crt_series.empty_patch(p): | |
85 | print 'done (empty patch)' | |
86 | else: | |
f338c3c0 CM |
87 | print 'done' |
88 | ||
f338c3c0 | 89 | print_crt_patch() |