1 """Function/variables commmon to all the commands
5 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 from optparse
import OptionParser
, make_option
24 from stgit
.utils
import *
25 from stgit
import stack
, git
28 # Command exception class
29 class CmdException(Exception):
40 string_list
= string
.split('/')
42 if len(string_list
) == 1:
44 git_id
= string_list
[0]
49 return read_string(crt_series
.get_base_file())
51 for path
in [os
.path
.join(git
.base_dir
, 'refs', 'heads'),
52 os
.path
.join(git
.base_dir
, 'refs', 'tags')]:
53 id_file
= os
.path
.join(path
, git_id
)
54 if os
.path
.isfile(id_file
):
55 return read_string(id_file
)
57 # maybe GIT know more about this id
59 elif len(string_list
) == 2:
60 patch_name
= string_list
[0]
62 patch_name
= crt_series
.get_current()
63 git_id
= string_list
[1]
66 raise CmdException
, 'No patches applied'
67 elif not (patch_name
in crt_series
.get_applied()
68 + crt_series
.get_unapplied()):
69 raise CmdException
, 'Unknown patch "%s"' % patch_name
71 if git_id
== 'bottom':
72 return crt_series
.get_patch(patch_name
).get_bottom()
74 return crt_series
.get_patch(patch_name
).get_top()
76 raise CmdException
, 'Unknown id: %s' % string
78 def check_local_changes():
79 if git
.local_changes():
81 'local changes in the tree. Use "refresh" to commit them'
83 def check_head_top_equal():
84 if not crt_series
.head_top_equal():
86 'HEAD and top are not the same. You probably committed\n' \
87 ' changes to the tree ouside of StGIT. If you know what you\n' \
88 ' are doing, use the "refresh -f" command'
90 def check_conflicts():
91 if os
.path
.exists(os
.path
.join(git
.base_dir
, 'conflicts')):
92 raise CmdException
, 'Unsolved conflicts. Please resolve them first'
94 def print_crt_patch():
95 patch
= crt_series
.get_current()
97 print 'Now at patch "%s"' % patch
99 print 'No patches applied'
101 def resolved(filename
):
102 git
.update_cache([filename
])
103 for ext
in ['.local', '.older', '.remote']:
105 if os
.path
.isfile(fn
):
109 conflicts
= git
.get_conflicts()
111 for filename
in conflicts
:
113 os
.remove(os
.path
.join(git
.base_dir
, 'conflicts'))
115 def name_email(string
):
116 """Return a tuple consisting of the name and email parsed from a
117 standard 'name <email>' string
119 names
= re
.split('([^<>]*)<([^<>]*)>', string
)
121 raise CmdException
, 'Incorrect "name <email>" string: %s' % string
123 return tuple([names
[1].strip(), names
[2].strip()])