8
8
9
9
from stgit import argparse , utils
10
10
from stgit .argparse import opt
11
- from stgit .commands import common
11
+ from stgit .commands .common import (
12
+ CmdException ,
13
+ DirectoryHasRepositoryLib ,
14
+ run_commit_msg_hook ,
15
+ )
12
16
from stgit .config import config
13
- from stgit .lib import edit , transaction
17
+ from stgit .lib . edit import auto_edit_patch , interactive_edit_patch
14
18
from stgit .lib .git import CommitData , IndexAndWorktree
19
+ from stgit .lib .transaction import StackTransaction , TransactionHalted
15
20
from stgit .out import out
16
21
17
22
__copyright__ = """
124
129
+ argparse .author_options ()
125
130
)
126
131
127
- directory = common . DirectoryHasRepositoryLib ()
132
+ directory = DirectoryHasRepositoryLib ()
128
133
129
134
130
135
def get_patch (stack , given_patch ):
131
136
"""Get the name of the patch we are to refresh."""
132
137
if given_patch :
133
138
patch_name = given_patch
134
139
if not stack .patches .exists (patch_name ):
135
- raise common . CmdException ('%s: no such patch' % patch_name )
140
+ raise CmdException ('%s: no such patch' % patch_name )
136
141
return patch_name
137
142
else :
138
143
if not stack .patchorder .applied :
139
- raise common . CmdException (
144
+ raise CmdException (
140
145
'Cannot refresh top patch because no patches are applied' )
141
146
return stack .patchorder .applied [- 1 ]
142
147
@@ -197,8 +202,7 @@ def make_temp_patch(stack, patch_name, paths, temp_index):
197
202
)
198
203
)
199
204
temp_name = utils .make_patch_name ('refresh-temp' , stack .patches .exists )
200
- trans = transaction .StackTransaction (stack ,
201
- 'refresh (create temporary patch)' )
205
+ trans = StackTransaction (stack , 'refresh (create temporary patch)' )
202
206
trans .patches [temp_name ] = commit
203
207
trans .applied .append (temp_name )
204
208
return (
@@ -241,7 +245,7 @@ def absorb_applied(trans, iw, patch_name, temp_name, edit_fun):
241
245
# Push back any patch we were forced to pop earlier.
242
246
for pn in to_pop :
243
247
trans .push_patch (pn , iw )
244
- except transaction . TransactionHalted :
248
+ except TransactionHalted :
245
249
pass
246
250
return temp_absorbed
247
251
@@ -295,7 +299,7 @@ def absorb(stack, patch_name, temp_name, edit_fun, annotate=None):
295
299
log_msg = 'refresh\n \n ' + annotate
296
300
else :
297
301
log_msg = 'refresh'
298
- trans = transaction . StackTransaction (stack , log_msg )
302
+ trans = StackTransaction (stack , log_msg )
299
303
iw = stack .repository .default_iw
300
304
if patch_name in trans .applied :
301
305
absorb_func = absorb_applied
@@ -319,19 +323,19 @@ def func(parser, options, args):
319
323
# Catch illegal argument combinations.
320
324
path_limiting = bool (args or options .update )
321
325
if options .index and path_limiting :
322
- raise common . CmdException (
326
+ raise CmdException (
323
327
'Only full refresh is available with the --index option' )
324
328
325
329
if options .index and options .force :
326
- raise common . CmdException (
330
+ raise CmdException (
327
331
'You cannot --force a full refresh when using --index mode' )
328
332
329
333
if options .update and options .submodules :
330
- raise common . CmdException (
334
+ raise CmdException (
331
335
'--submodules is meaningless when only updating modified files' )
332
336
333
337
if options .index and options .submodules :
334
- raise common . CmdException (
338
+ raise CmdException (
335
339
'--submodules is meaningless when keeping the current index' )
336
340
337
341
# If submodules was not specified on the command line, infer a default
@@ -353,14 +357,13 @@ def func(parser, options, args):
353
357
# Make sure there are no conflicts in the files we want to
354
358
# refresh.
355
359
if stack .repository .default_index .conflicts () & paths :
356
- raise common .CmdException (
357
- 'Cannot refresh -- resolve conflicts first' )
360
+ raise CmdException ('Cannot refresh -- resolve conflicts first' )
358
361
359
362
# Make sure the index is clean before performing a full refresh
360
363
if not options .index and not options .force :
361
364
if not (stack .repository .default_index .is_clean (stack .head ) or
362
365
stack .repository .default_iw .worktree_clean ()):
363
- raise common . CmdException (
366
+ raise CmdException (
364
367
'The index is dirty. Did you mean --index? '
365
368
'To force a full refresh use --force.'
366
369
)
@@ -373,7 +376,7 @@ def func(parser, options, args):
373
376
374
377
def edit_fun (cd ):
375
378
orig_msg = cd .message
376
- cd , failed_diff = edit . auto_edit_patch (
379
+ cd , failed_diff = auto_edit_patch (
377
380
stack .repository , cd ,
378
381
msg = (None if options .message is None else
379
382
options .message .encode ('utf-8' )),
@@ -383,7 +386,7 @@ def edit_fun(cd):
383
386
sign_str = options .sign_str )
384
387
assert not failed_diff
385
388
if options .edit :
386
- cd , failed_diff = edit . interactive_edit_patch (
389
+ cd , failed_diff = interactive_edit_patch (
387
390
stack .repository ,
388
391
cd ,
389
392
edit_diff = False ,
@@ -392,7 +395,7 @@ def edit_fun(cd):
392
395
)
393
396
assert not failed_diff
394
397
if not options .no_verify and (options .edit or cd .message != orig_msg ):
395
- cd = common . run_commit_msg_hook (stack .repository , cd , options .edit )
398
+ cd = run_commit_msg_hook (stack .repository , cd , options .edit )
396
399
return cd
397
400
398
401
return absorb (stack , patch_name , temp_name , edit_fun ,
0 commit comments