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