Commit | Line | Data |
---|---|---|
fcee87cf CM |
1 | |
2 | __copyright__ = """ | |
3 | Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com> | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License version 2 as | |
7 | published by the Free Software Foundation. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program; if not, write to the Free Software | |
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 | """ | |
18 | ||
f979802d CM |
19 | from stgit.commands import common |
20 | from stgit.lib import transaction | |
21 | from stgit import argparse | |
575bbdae | 22 | from stgit.argparse import opt |
fcee87cf | 23 | |
575bbdae | 24 | help = 'Push one or more patches onto the stack' |
33ff9cdd | 25 | kind = 'stack' |
575bbdae KH |
26 | usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]'] |
27 | description = """ | |
6b1e0111 CM |
28 | Push one or more patches (defaulting to the first unapplied one) onto |
29 | the stack. The 'push' operation allows patch reordering by commuting | |
625e8de7 KH |
30 | them with the three-way merge algorithm. If there are conflicts while |
31 | pushing a patch, those conflicts are written to the work tree, and the | |
32 | command halts. Conflicts raised during the push operation have to be | |
9ab06b98 CM |
33 | fixed and the 'git add --update' command run (alternatively, you may |
34 | undo the conflicting push with 'stg undo'). | |
26aab5b0 | 35 | |
718a5e51 CM |
36 | The command also notifies when the patch becomes empty (fully merged |
37 | upstream) or is modified (three-way merged) by the 'push' operation.""" | |
fcee87cf | 38 | |
6c8a90e1 | 39 | args = [argparse.patch_range(argparse.unapplied_patches)] |
575bbdae KH |
40 | options = [ |
41 | opt('-a', '--all', action = 'store_true', | |
42 | short = 'Push all the unapplied patches'), | |
43 | opt('-n', '--number', type = 'int', | |
44 | short = 'Push the specified number of patches'), | |
45 | opt('--reverse', action = 'store_true', | |
051704b1 DK |
46 | short = 'Push the patches in reverse order'), |
47 | opt('--set-tree', action = 'store_true', | |
48 | short = 'Push the patch with the original tree', long = """ | |
49 | Push the patches, but don't perform a merge. Instead, the | |
50 | resulting tree will be identical to the tree that the patch | |
51 | previously created. | |
52 | ||
53 | This can be useful when splitting a patch by first popping the | |
54 | patch and creating a new patch with some of the | |
55 | changes. Pushing the original patch with '--set-tree' will | |
56 | avoid conflicts and only the remaining changes will be in the | |
57 | patch.""") | |
f979802d | 58 | ] + argparse.keep_option() + argparse.merged_option() |
fcee87cf | 59 | |
f979802d | 60 | directory = common.DirectoryHasRepositoryLib() |
fcee87cf CM |
61 | |
62 | def func(parser, options, args): | |
f979802d CM |
63 | """Pushes the given patches or the first unapplied onto the stack.""" |
64 | stack = directory.repository.current_stack | |
65 | iw = stack.repository.default_iw | |
66 | clean_iw = (not options.keep and iw) or None | |
67 | trans = transaction.StackTransaction(stack, 'pop', | |
68 | check_clean_iw = clean_iw) | |
69 | ||
70 | if not trans.unapplied: | |
71 | raise common.CmdException('No patches to push') | |
72 | ||
73 | if options.all: | |
74 | patches = list(trans.unapplied) | |
75 | elif options.number: | |
76 | patches = trans.unapplied[:options.number] | |
77 | elif not args: | |
78 | patches = [trans.unapplied[0]] | |
fcee87cf | 79 | else: |
f979802d | 80 | patches = common.parse_patches(args, trans.unapplied) |
fcee87cf | 81 | |
f979802d CM |
82 | if not patches: |
83 | raise common.CmdException('No patches to push') | |
fcee87cf CM |
84 | |
85 | if options.reverse: | |
86 | patches.reverse() | |
87 | ||
051704b1 | 88 | if options.set_tree: |
f979802d | 89 | for pn in patches: |
051704b1 DK |
90 | trans.push_tree(pn) |
91 | else: | |
92 | try: | |
93 | if options.merged: | |
94 | merged = set(trans.check_merged(patches)) | |
95 | else: | |
96 | merged = set() | |
97 | for pn in patches: | |
98 | trans.push_patch(pn, iw, allow_interactive = True, | |
99 | already_merged = pn in merged) | |
100 | except transaction.TransactionHalted: | |
101 | pass | |
f979802d | 102 | return trans.run(iw) |