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', | |
39 | action = 'store_true')] | |
40 | ||
41 | ||
42 | def func(parser, options, args): | |
43 | """Import a commit object as a new patch | |
44 | """ | |
45 | if len(args) != 1: | |
46 | parser.error('incorrect number of arguments') | |
47 | ||
48 | check_local_changes() | |
49 | check_conflicts() | |
50 | check_head_top_equal() | |
51 | ||
52 | commit_str = args[0] | |
53 | patch_branch = commit_str.split('@') | |
54 | ||
55 | if len(patch_branch) == 2: | |
56 | patch = patch_branch[0] | |
57 | elif options.name: | |
58 | patch = options.name | |
59 | else: | |
60 | raise CmdException, 'Unkown patch name' | |
61 | ||
62 | commit_id = git_id(commit_str) | |
63 | commit = git.Commit(commit_id) | |
64 | ||
65 | if not options.reverse: | |
66 | bottom = commit.get_parent() | |
67 | top = commit_id | |
68 | else: | |
69 | bottom = commit_id | |
70 | top = commit.get_parent() | |
71 | ||
72 | message = commit.get_log() | |
73 | author_name, author_email, author_date = \ | |
74 | name_email_date(commit.get_author()) | |
75 | ||
76 | print 'Importing commit %s...' % commit_id, | |
77 | sys.stdout.flush() | |
78 | ||
79 | crt_series.new_patch(patch, message = message, can_edit = False, | |
80 | unapplied = True, bottom = bottom, top = top, | |
81 | author_name = author_name, | |
82 | author_email = author_email, | |
83 | author_date = author_date) | |
84 | crt_series.push_patch(patch) | |
85 | ||
86 | print 'done' | |
87 | print_crt_patch() |