Don't use refs/bases/<branchname>
[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 *
5a6d315e 23from stgit.config import GitConfigException
f338c3c0
CM
24from stgit import stack, git
25
26
27help = 'pull the changes from the remote repository'
8f5da35b 28usage = """%prog [options] [<repository>]
26aab5b0 29
d060dfd3
YD
30Pull the latest changes from the given remote repository (defaulting
31to branch.<name>.remote, or 'origin' if not set). This command works
32by popping all the patches from the stack, pulling the changes in the
33parent repository, setting the base of the stack to the latest parent
34HEAD and pushing the patches back (unless '--nopush' is specified).
35The 'push' operation can fail if there are conflicts. They need to be
36resolved and the patch pushed again.
26aab5b0 37
d060dfd3 38Check the 'git fetch' documentation for the <repository> format."""
f338c3c0
CM
39
40options = [make_option('-n', '--nopush',
41 help = 'do not push the patches back after pulling',
1777d8cd
CM
42 action = 'store_true'),
43 make_option('-m', '--merged',
44 help = 'check for patches merged upstream',
e5834af7
YD
45 action = 'store_true'),
46 make_option('--force',
47 help = 'force rebase even if the stack based was moved by (un)commits',
1f5e9148 48 action = 'store_true')]
f338c3c0
CM
49
50def func(parser, options, args):
51 """Pull the changes from a remote repository
52 """
8f5da35b 53 if len(args) > 1:
f338c3c0
CM
54 parser.error('incorrect number of arguments')
55
1f5e9148
CM
56 if len(args) >= 1:
57 repository = args[0]
87c69539 58 else:
254d99f8 59 repository = crt_series.get_parent_remote()
87c69539 60
0b4b9499
CL
61 if crt_series.get_protected():
62 raise CmdException, 'This branch is protected. Pulls are not permitted'
63
f338c3c0
CM
64 check_local_changes()
65 check_conflicts()
66 check_head_top_equal()
67
3b3c26fa
YD
68 policy = config.get('branch.%s.stgit.pull-policy' % crt_series.get_branch()) or \
69 config.get('stgit.pull-policy')
70 if policy == 'pull':
71 must_rebase = 0
72 elif policy == 'fetch-rebase':
73 must_rebase = 1
74 elif policy == 'rebase':
75 must_rebase = 1
76 else:
5a6d315e 77 raise GitConfigException, 'Unsupported pull-policy "%s"' % policy
3b3c26fa 78
e5834af7 79 applied = prepare_rebase(real_rebase=must_rebase, force=options.force)
ddbbfd84
CM
80
81 # pull the remote changes
3b3c26fa
YD
82 if policy == 'pull':
83 print 'Pulling from "%s"...' % repository
84 git.pull(repository)
85 elif policy == 'fetch-rebase':
86 print 'Fetching from "%s"...' % repository
87 git.fetch(repository)
a9f3a9fc 88 rebase(git.fetch_head())
3b3c26fa
YD
89 elif policy == 'rebase':
90 rebase(crt_series.get_parent_branch())
a9f3a9fc
YD
91
92 post_rebase(applied, options.nopush, options.merged)
f338c3c0 93
925ff4a7 94 # maybe tidy up
c73e63b7 95 if config.get('stgit.keepoptimized') == 'yes':
925ff4a7
CL
96 git.repack()
97
f338c3c0 98 print_crt_patch()