The user does not want to mess with the refspecs.
[stgit] / stgit / commands / pull.py
CommitLineData
f338c3c0
CM
1__copyright__ = """
2Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License version 2 as
6published by the Free Software Foundation.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16"""
17
18import sys, os
19from optparse import OptionParser, make_option
20
21from stgit.commands.common import *
22from stgit.utils import *
23from stgit import stack, git
24
25
26help = 'pull the changes from the remote repository'
8f5da35b 27usage = """%prog [options] [<repository>]
26aab5b0 28
1f5e9148 29Pull the latest changes from the given repository (defaulting to
3899a8e2
CM
30'origin'). This command works by popping all the patches from the
31stack, pulling the changes in the parent repository, setting the base
d33c40f1 32of 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
34there are conflicts. They need to be resolved and the patch pushed
35again.
26aab5b0 36
8f5da35b 37Check the 'git pull' documentation for the <repository> format."""
f338c3c0
CM
38
39options = [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',
1f5e9148 44 action = 'store_true')]
f338c3c0
CM
45
46def func(parser, options, args):
47 """Pull the changes from a remote repository
48 """
8f5da35b 49 if len(args) > 1:
f338c3c0
CM
50 parser.error('incorrect number of arguments')
51
1f5e9148
CM
52 if len(args) >= 1:
53 repository = args[0]
87c69539 54 else:
254d99f8 55 repository = crt_series.get_parent_remote()
87c69539 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:
a34b42e8 67 print 'Popping all applied patches...',
ddbbfd84
CM
68 sys.stdout.flush()
69 crt_series.pop_patch(applied[0])
70 print 'done'
71
72 # pull the remote changes
1f5e9148 73 print 'Pulling from "%s"...' % repository
8f5da35b 74 git.pull(repository)
f338c3c0
CM
75 print 'done'
76
ddbbfd84 77 # push the patches back
1777d8cd
CM
78 if not options.nopush:
79 push_patches(applied, options.merged)
f338c3c0 80
925ff4a7 81 # maybe tidy up
c73e63b7 82 if config.get('stgit.keepoptimized') == 'yes':
925ff4a7
CL
83 git.repack()
84
f338c3c0 85 print_crt_patch()