2 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
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.
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.
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
19 from optparse
import OptionParser
, make_option
21 from stgit
.commands
.common
import *
22 from stgit
.utils
import *
23 from stgit
.config
import GitConfigException
24 from stgit
import stack
, git
27 help = 'pull the changes from the remote repository'
28 usage
= """%prog [options] [<repository>]
30 Pull the latest changes from the given remote repository (defaulting
31 to branch.<name>.remote, or 'origin' if not set). This command works
32 by popping all the patches from the stack, pulling the changes in the
33 parent repository, setting the base of the stack to the latest parent
34 HEAD and pushing the patches back (unless '--nopush' is specified).
35 The 'push' operation can fail if there are conflicts. They need to be
36 resolved and the patch pushed again.
38 Check the 'git fetch' documentation for the <repository> format."""
40 options
= [make_option('-n', '--nopush',
41 help = 'do not push the patches back after pulling',
42 action
= 'store_true'),
43 make_option('-m', '--merged',
44 help = 'check for patches merged upstream',
45 action
= 'store_true'),
46 make_option('--force',
47 help = 'force rebase even if the stack based was moved by (un)commits',
48 action
= 'store_true')]
50 def func(parser
, options
, args
):
51 """Pull the changes from a remote repository
53 policy
= config
.get('branch.%s.stgit.pull-policy' % crt_series
.get_name()) or \
54 config
.get('stgit.pull-policy')
56 if policy
== 'rebase':
59 parser
.error('specifying a repository is meaningless for policy="%s"' % policy
)
61 parser
.error('incorrect number of arguments')
66 parser
.error('incorrect number of arguments')
71 repository
= crt_series
.get_parent_remote()
73 if crt_series
.get_protected():
74 raise CmdException
, 'This branch is protected. Pulls are not permitted'
78 check_head_top_equal()
80 if (policy
!= 'pull') \
81 and (policy
!= 'fetch-rebase') \
82 and (policy
!= 'rebase'):
83 raise GitConfigException
, 'Unsupported pull-policy "%s"' % policy
85 applied
= prepare_rebase(force
=options
.force
)
87 # pull the remote changes
89 out
.info('Pulling from "%s"' % repository
)
91 elif policy
== 'fetch-rebase':
92 out
.info('Fetching from "%s"' % repository
)
94 rebase(git
.fetch_head())
95 elif policy
== 'rebase':
96 rebase(crt_series
.get_parent_branch())
98 post_rebase(applied
, options
.nopush
, options
.merged
)
101 if config
.get('stgit.keepoptimized') == 'yes':