Commit | Line | Data |
---|---|---|
0618ea9c CM |
1 | __copyright__ = """ |
2 | Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com> | |
3 | ||
4 | This program is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License version 2 as | |
6 | published by the Free Software Foundation. | |
7 | ||
8 | This program is distributed in the hope that it will be useful, | |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | GNU General Public License for more details. | |
12 | ||
13 | You should have received a copy of the GNU General Public License | |
14 | along with this program; if not, write to the Free Software | |
15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | """ | |
17 | ||
18 | import sys, os | |
19 | from optparse import OptionParser, make_option | |
20 | ||
21 | from stgit.commands.common import * | |
22 | from stgit.utils import * | |
23 | from stgit import stack, git | |
24 | ||
25 | ||
26 | help = 'import a patch from a different branch or a commit object' | |
27 | usage = """%prog [options] [<patch@branch>|<commit>] | |
28 | ||
29 | Import a patch from a different branch or a commit object into the | |
30 | current series. By default, the name of the imported patch is used as | |
31 | the name of the current patch. It can be overriden with the '--name' | |
32 | option. A commit object can be reverted with the '--reverse' | |
33 | option. The log and author information are those of the commit object.""" | |
34 | ||
35 | options = [make_option('-n', '--name', | |
36 | help = 'use NAME as the patch name'), | |
37 | make_option('-r', '--reverse', | |
38 | help = 'reverse the commit object before importing', | |
ba524d4c CM |
39 | action = 'store_true'), |
40 | make_option('--fold', | |
41 | help = 'fold the commit object into the current patch', | |
0618ea9c CM |
42 | action = 'store_true')] |
43 | ||
44 | ||
45 | def func(parser, options, args): | |
46 | """Import a commit object as a new patch | |
47 | """ | |
48 | if len(args) != 1: | |
49 | parser.error('incorrect number of arguments') | |
50 | ||
51 | check_local_changes() | |
52 | check_conflicts() | |
53 | check_head_top_equal() | |
54 | ||
55 | commit_str = args[0] | |
0618ea9c | 56 | |
ba524d4c CM |
57 | if options.fold: |
58 | if not crt_series.get_current(): | |
59 | raise CmdException, 'No patches applied' | |
0618ea9c | 60 | else: |
ba524d4c CM |
61 | patch_branch = commit_str.split('@') |
62 | if len(patch_branch) == 2: | |
63 | patch = patch_branch[0] | |
64 | elif options.name: | |
65 | patch = options.name | |
66 | else: | |
67 | raise CmdException, 'Unkown patch name' | |
0618ea9c CM |
68 | |
69 | commit_id = git_id(commit_str) | |
70 | commit = git.Commit(commit_id) | |
71 | ||
72 | if not options.reverse: | |
73 | bottom = commit.get_parent() | |
74 | top = commit_id | |
75 | else: | |
76 | bottom = commit_id | |
77 | top = commit.get_parent() | |
78 | ||
ba524d4c CM |
79 | if options.fold: |
80 | print 'Folding commit %s...' % commit_id, | |
81 | sys.stdout.flush() | |
0618ea9c | 82 | |
ba524d4c CM |
83 | git.merge(bottom, git.get_head(), top) |
84 | else: | |
85 | message = commit.get_log() | |
86 | author_name, author_email, author_date = \ | |
87 | name_email_date(commit.get_author()) | |
88 | ||
89 | print 'Importing commit %s...' % commit_id, | |
90 | sys.stdout.flush() | |
0618ea9c | 91 | |
ba524d4c CM |
92 | crt_series.new_patch(patch, message = message, can_edit = False, |
93 | unapplied = True, bottom = bottom, top = top, | |
94 | author_name = author_name, | |
95 | author_email = author_email, | |
96 | author_date = author_date) | |
97 | crt_series.push_patch(patch) | |
0618ea9c CM |
98 | |
99 | print 'done' | |
ba524d4c | 100 | |
0618ea9c | 101 | print_crt_patch() |