Print conflict details with the new infrastructure (bug #11181)
[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
575bbdae 19from stgit.argparse import opt
f338c3c0
CM
20from stgit.commands.common import *
21from stgit.utils import *
5e888f30 22from stgit.out import *
5a6d315e 23from stgit.config import GitConfigException
6c8a90e1 24from stgit import argparse, stack, git
f338c3c0 25
575bbdae 26help = 'Pull changes from a remote repository'
33ff9cdd 27kind = 'stack'
575bbdae
KH
28usage = ['[options] [<repository>]']
29description = """
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 39
6c8a90e1 40args = [argparse.repo]
575bbdae
KH
41options = [
42 opt('-n', '--nopush', action = 'store_true',
43 short = 'Do not push the patches back after pulling'),
44 opt('-m', '--merged', action = 'store_true',
45 short = 'Check for patches merged upstream')]
46
117ed129 47directory = DirectoryGotoToplevel(log = True)
f338c3c0
CM
48
49def func(parser, options, args):
50 """Pull the changes from a remote repository
51 """
d37ff079 52 policy = config.get('branch.%s.stgit.pull-policy' % crt_series.get_name()) or \
1fa161d6
YD
53 config.get('stgit.pull-policy')
54
55 if policy == 'rebase':
56 # parent is local
57 if len(args) == 1:
58 parser.error('specifying a repository is meaningless for policy="%s"' % policy)
59 if len(args) > 0:
60 parser.error('incorrect number of arguments')
f338c3c0 61
87c69539 62 else:
1fa161d6
YD
63 # parent is remote
64 if len(args) > 1:
65 parser.error('incorrect number of arguments')
66
67 if len(args) >= 1:
68 repository = args[0]
69 else:
70 repository = crt_series.get_parent_remote()
87c69539 71
0b4b9499
CL
72 if crt_series.get_protected():
73 raise CmdException, 'This branch is protected. Pulls are not permitted'
74
f338c3c0
CM
75 check_local_changes()
76 check_conflicts()
6972fd6b 77 check_head_top_equal(crt_series)
f338c3c0 78
64e15469 79 if policy not in ['pull', 'fetch-rebase', 'rebase']:
5a6d315e 80 raise GitConfigException, 'Unsupported pull-policy "%s"' % policy
3b3c26fa 81
6972fd6b 82 applied = prepare_rebase(crt_series)
ddbbfd84
CM
83
84 # pull the remote changes
3b3c26fa 85 if policy == 'pull':
27ac2b7e 86 out.info('Pulling from "%s"' % repository)
3b3c26fa
YD
87 git.pull(repository)
88 elif policy == 'fetch-rebase':
27ac2b7e 89 out.info('Fetching from "%s"' % repository)
3b3c26fa 90 git.fetch(repository)
764d1101
YD
91 try:
92 target = git.fetch_head()
93 except git.GitException:
b029e3cc
CM
94 out.error('Could not find the remote head to rebase onto - fix branch.%s.merge in .git/config' % crt_series.get_name())
95 out.error('Pushing any patches back...')
6972fd6b 96 post_rebase(crt_series, applied, False, False)
b029e3cc 97 raise
764d1101 98
6972fd6b 99 rebase(crt_series, target)
3b3c26fa 100 elif policy == 'rebase':
6972fd6b 101 rebase(crt_series, crt_series.get_parent_branch())
a9f3a9fc 102
6972fd6b 103 post_rebase(crt_series, applied, options.nopush, options.merged)
f338c3c0 104
925ff4a7 105 # maybe tidy up
c73e63b7 106 if config.get('stgit.keepoptimized') == 'yes':
925ff4a7
CL
107 git.repack()
108
6972fd6b 109 print_crt_patch(crt_series)