5 from stgit
.argparse
import opt
6 from stgit
.commands
.common
import (
8 DirectoryHasRepository
,
15 from stgit
.out
import out
18 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
20 This program is free software; you can redistribute it and/or modify
21 it under the terms of the GNU General Public License version 2 as
22 published by the Free Software Foundation.
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, see http://www.gnu.org/licenses/.
33 help = 'Integrate a GNU diff patch into the current patch'
35 usage
= ['[options] [--] [<file>]']
37 Apply the given GNU diff file (or the standard input) onto the top of
38 the current patch. With the '--threeway' option, the patch is applied
39 onto the bottom of the current patch and a three-way merge is
40 performed with the current top. With the --base option, the patch is
41 applied onto the specified base and a three-way merged is performed
42 with the current top."""
50 short
='Perform a three-way merge with the current patch',
56 short
='Use BASE instead of HEAD when applying the patch',
63 short
='Remove N leading slashes from diff paths (default 1)',
70 short
='Ensure N lines of surrounding context for each change',
75 short
='Leave the rejected hunks in corresponding *.rej files',
79 directory
= DirectoryHasRepository()
82 def func(parser
, options
, args
):
83 """Integrate a GNU diff patch into the current patch"""
85 parser
.error('incorrect number of arguments')
87 repository
= directory
.repository
88 stack
= repository
.get_stack()
90 check_local_changes(repository
)
91 check_conflicts(repository
.default_iw
)
92 check_head_top_equal(stack
)
99 applied
= stack
.patchorder
.applied
101 raise CmdException('No patches applied')
103 current
= applied
[-1]
106 if os
.path
.exists(filename
):
107 out
.start('Folding patch "%s"' % filename
)
108 with io
.open(filename
, 'rb') as f
:
111 raise CmdException('No such file: %s' % filename
)
113 out
.start('Folding patch from stdin')
114 diff
= sys
.stdin
.buffer.read()
120 base
=stack
.patches
[current
].data
.parent
,
122 reject
=options
.reject
,
123 context_lines
=options
.context_lines
,
129 base
=git_commit(options
.base
, repository
),
130 reject
=options
.reject
,
132 context_lines
=options
.context_lines
,
139 reject
=options
.reject
,
140 context_lines
=options
.context_lines
,