From 407bf0a244e3b39fc69081c5df8265d812b3fea1 Mon Sep 17 00:00:00 2001 From: Peter Grayson Date: Mon, 1 Nov 2021 23:39:53 -0400 Subject: [PATCH] Check bad head and clean iw before StackTransaction StackTransaction.__init__() no longer performs bad head or clean iw checks. These checks are now performed explictly by the various commands instead of relying on default arguments to StackTransaction. This reduces the complexity of StackTransaction by avoiding side effects in its initializer. Signed-off-by: Peter Grayson --- stgit/commands/branch.py | 9 ++------- stgit/commands/clean.py | 11 +++-------- stgit/commands/commit.py | 16 ++++++++-------- stgit/commands/common.py | 36 +++++++++++++++--------------------- stgit/commands/float.py | 27 ++++++++++++++------------- stgit/commands/goto.py | 21 ++++++++++++--------- stgit/commands/hide.py | 15 +++++++-------- stgit/commands/imprt.py | 8 +------- stgit/commands/new.py | 10 +++------- stgit/commands/pick.py | 11 ++++------- stgit/commands/pop.py | 20 +++++++++++--------- stgit/commands/push.py | 24 ++++++++++++------------ stgit/commands/redo.py | 8 +------- stgit/commands/refresh.py | 29 ++++++++--------------------- stgit/commands/repair.py | 8 +------- stgit/commands/reset.py | 8 +------- stgit/commands/sink.py | 22 +++++++++++++--------- stgit/commands/squash.py | 11 ++++------- stgit/commands/sync.py | 26 +++++++++++--------------- stgit/commands/uncommit.py | 8 +------- stgit/commands/undo.py | 8 +------- stgit/commands/unhide.py | 16 ++++++++-------- stgit/lib/edit.py | 9 ++------- stgit/lib/transaction.py | 20 +------------------- 24 files changed, 144 insertions(+), 237 deletions(-) diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py index aab440e..d130982 100644 --- a/stgit/commands/branch.py +++ b/stgit/commands/branch.py @@ -355,14 +355,9 @@ def func(parser, options, args): out.start('Cloning current branch to "%s"' % clone_name) if stack: + check_head_top_equal(stack) clone = stack.clone(clone_name, 'branch clone of %s' % cur_branch.name) - trans = StackTransaction( - clone, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + trans = StackTransaction(clone) try: for pn in stack.patchorder.applied: trans.push_patch(pn) diff --git a/stgit/commands/clean.py b/stgit/commands/clean.py index ba2a140..6c2443a 100644 --- a/stgit/commands/clean.py +++ b/stgit/commands/clean.py @@ -1,5 +1,5 @@ from stgit.argparse import opt -from stgit.commands.common import DirectoryHasRepository +from stgit.commands.common import DirectoryHasRepository, check_head_top_equal from stgit.lib import transaction __copyright__ = """ @@ -46,13 +46,8 @@ directory = DirectoryHasRepository() def _clean(stack, clean_applied, clean_unapplied): - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=True, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = transaction.StackTransaction(stack, allow_conflicts=True) def del_patch(pn): if pn in stack.patchorder.applied: diff --git a/stgit/commands/commit.py b/stgit/commands/commit.py index efa02f7..ca84211 100644 --- a/stgit/commands/commit.py +++ b/stgit/commands/commit.py @@ -1,5 +1,10 @@ from stgit.argparse import opt, patch_range -from stgit.commands.common import CmdException, DirectoryHasRepository, parse_patches +from stgit.commands.common import ( + CmdException, + DirectoryHasRepository, + check_head_top_equal, + parse_patches, +) from stgit.lib import transaction from stgit.out import out @@ -105,13 +110,8 @@ def func(parser, options, args): # run "stg commit" with conflicts in the index. return len(trans.applied) >= 1 - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=allow_conflicts, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = transaction.StackTransaction(stack, allow_conflicts=allow_conflicts) try: common_prefix = 0 for i in range(min(len(stack.patchorder.applied), len(patches))): diff --git a/stgit/commands/common.py b/stgit/commands/common.py index b4a1563..95d6e84 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -129,6 +129,14 @@ def check_conflicts(iw): ) +def check_index_and_worktree_clean(stack): + iw = stack.repository.default_iw + if not iw.worktree_clean(): + raise CmdException('Worktree not clean. Use "refresh" or "reset --hard"') + if not iw.index.is_clean(stack.head): + raise CmdException('Index not clean. Use "refresh" or "reset --hard"') + + def print_current_patch(stack): if stack.patchorder.applied: out.info('Now at patch "%s"' % stack.patchorder.applied[-1]) @@ -263,14 +271,10 @@ def apply_patch(stack, diff, base=None, reject=False, strip=None, context_lines= def prepare_rebase(stack, cmd_name): # pop all patches + check_head_top_equal(stack) + check_index_and_worktree_clean(stack) iw = stack.repository.default_iw - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=iw, - ) + trans = StackTransaction(stack) out.start('Popping all applied patches') try: trans.reorder_patches( @@ -313,13 +317,8 @@ def rebase(stack, iw, target_commit=None): def post_rebase(stack, applied, cmd_name, check_merged): iw = stack.repository.default_iw - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = StackTransaction(stack) try: if check_merged: merged = set(trans.check_merged(applied)) @@ -342,13 +341,8 @@ def delete_patches(stack, iw, patches): else: return not trans.applied - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=allow_conflicts, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = StackTransaction(stack, allow_conflicts=allow_conflicts) try: to_push = trans.delete_patches(lambda pn: pn in patches) for pn in to_push: diff --git a/stgit/commands/float.py b/stgit/commands/float.py index ef01dc9..b6fa06d 100644 --- a/stgit/commands/float.py +++ b/stgit/commands/float.py @@ -3,7 +3,13 @@ import re import sys from stgit.argparse import keep_option, opt, patch_range -from stgit.commands.common import CmdException, DirectoryHasRepository, parse_patches +from stgit.commands.common import ( + CmdException, + DirectoryHasRepository, + check_head_top_equal, + check_index_and_worktree_clean, + parse_patches, +) from stgit.lib import transaction __copyright__ = """ @@ -80,19 +86,14 @@ def func(parser, options, args): raise CmdException('No patches to float') iw = stack.repository.default_iw - if options.keep or ( - options.noapply and not any(pn in stack.patchorder.applied for pn in patches) + check_head_top_equal(stack) + + if not options.keep and ( + not options.noapply or any(pn in stack.patchorder.applied for pn in patches) ): - clean_iw = None - else: - clean_iw = iw - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=clean_iw, - ) + check_index_and_worktree_clean(stack) + + trans = transaction.StackTransaction(stack) if options.noapply: applied = [p for p in trans.applied if p not in patches] diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py index 2d24b92..0f4f3e7 100644 --- a/stgit/commands/goto.py +++ b/stgit/commands/goto.py @@ -1,7 +1,12 @@ import re from stgit import argparse -from stgit.commands.common import CmdException, DirectoryHasRepository +from stgit.commands.common import ( + CmdException, + DirectoryHasRepository, + check_head_top_equal, + check_index_and_worktree_clean, +) from stgit.lib import transaction from stgit.out import out @@ -41,14 +46,12 @@ def func(parser, options, args): stack = directory.repository.current_stack iw = stack.repository.default_iw - clean_iw = (not options.keep and iw) or None - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=clean_iw, - ) + + check_head_top_equal(stack) + if not options.keep: + check_index_and_worktree_clean(stack) + + trans = transaction.StackTransaction(stack) if name not in trans.all_patches: candidates = [pn for pn in trans.all_patches if name in pn] diff --git a/stgit/commands/hide.py b/stgit/commands/hide.py index 6a7d373..2b5064c 100644 --- a/stgit/commands/hide.py +++ b/stgit/commands/hide.py @@ -1,5 +1,9 @@ from stgit.argparse import opt, patch_range -from stgit.commands.common import DirectoryHasRepository, parse_patches +from stgit.commands.common import ( + DirectoryHasRepository, + check_head_top_equal, + parse_patches, +) from stgit.lib import transaction from stgit.out import out @@ -42,13 +46,8 @@ directory = DirectoryHasRepository() def func(parser, options, args): """Hide a range of patch in the series.""" stack = directory.repository.current_stack - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = transaction.StackTransaction(stack) if not args: parser.error('No patches specified') diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py index d8dbf5e..31c9db6 100644 --- a/stgit/commands/imprt.py +++ b/stgit/commands/imprt.py @@ -248,13 +248,7 @@ def __create_patch( ) commit = stack.repository.commit(cd) - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + trans = StackTransaction(stack) try: if options.replace and name in stack.patchorder.unapplied: diff --git a/stgit/commands/new.py b/stgit/commands/new.py index 43f4357..588a293 100644 --- a/stgit/commands/new.py +++ b/stgit/commands/new.py @@ -3,6 +3,7 @@ from stgit.argparse import opt from stgit.commands.common import ( CmdException, DirectoryHasRepository, + check_head_top_equal, run_commit_msg_hook, update_commit_data, ) @@ -117,13 +118,8 @@ def func(parser, options, args): name = stack.patches.make_name(cd.message_str) # Write the new patch. - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = StackTransaction(stack) trans.patches[name] = stack.repository.commit(cd) trans.applied.append(name) return trans.run('new: %s' % name) diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py index c631b0f..87fd631 100644 --- a/stgit/commands/pick.py +++ b/stgit/commands/pick.py @@ -224,13 +224,10 @@ def __pick_commit(stack, ref_stack, iw, commit, patchname, options): ) ) - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + if not options.unapplied: + check_head_top_equal(stack) + + trans = StackTransaction(stack) trans.patches[patchname] = new_commit trans.unapplied.append(patchname) diff --git a/stgit/commands/pop.py b/stgit/commands/pop.py index 506607d..4aedc4b 100644 --- a/stgit/commands/pop.py +++ b/stgit/commands/pop.py @@ -1,5 +1,11 @@ from stgit.argparse import keep_option, opt, patch_range -from stgit.commands.common import CmdException, DirectoryHasRepository, parse_patches +from stgit.commands.common import ( + CmdException, + DirectoryHasRepository, + check_head_top_equal, + check_index_and_worktree_clean, + parse_patches, +) from stgit.lib import transaction __copyright__ = """ @@ -66,14 +72,10 @@ def func(parser, options, args): """Pop the given patches or the topmost one from the stack.""" stack = directory.repository.current_stack iw = stack.repository.default_iw - clean_iw = (not options.keep and not options.spill and iw) or None - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=clean_iw, - ) + check_head_top_equal(stack) + if not options.keep and not options.spill: + check_index_and_worktree_clean(stack) + trans = transaction.StackTransaction(stack) if options.number == 0: # explicitly allow this without any warning/error message diff --git a/stgit/commands/push.py b/stgit/commands/push.py index d78ab93..fca827e 100644 --- a/stgit/commands/push.py +++ b/stgit/commands/push.py @@ -1,5 +1,11 @@ from stgit.argparse import keep_option, merged_option, opt, patch_range -from stgit.commands.common import CmdException, DirectoryHasRepository, parse_patches +from stgit.commands.common import ( + CmdException, + DirectoryHasRepository, + check_head_top_equal, + check_index_and_worktree_clean, + parse_patches, +) from stgit.lib import transaction __copyright__ = """ @@ -123,17 +129,11 @@ def func(parser, options, args): assert patches - if options.keep or options.noapply: - clean_iw = None - else: - clean_iw = iw - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=clean_iw, - ) + check_head_top_equal(stack) + if not options.keep and not options.noapply: + check_index_and_worktree_clean(stack) + + trans = transaction.StackTransaction(stack) if options.reverse: patches.reverse() diff --git a/stgit/commands/redo.py b/stgit/commands/redo.py index 00c8ec9..33fd803 100644 --- a/stgit/commands/redo.py +++ b/stgit/commands/redo.py @@ -54,13 +54,7 @@ def func(parser, options, args): if options.number < 1: raise CmdException('Bad number of undos to redo') state = log.undo_state(stack, -options.number) - trans = transaction.StackTransaction( - stack, - discard_changes=options.hard, - allow_conflicts=False, - allow_bad_head=True, - check_clean_iw=None, - ) + trans = transaction.StackTransaction(stack, discard_changes=options.hard) try: log.reset_stack(trans, stack.repository.default_iw, state) except transaction.TransactionHalted: diff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py index 5809063..ccbf421 100644 --- a/stgit/commands/refresh.py +++ b/stgit/commands/refresh.py @@ -3,6 +3,7 @@ from stgit.argparse import opt from stgit.commands.common import ( CmdException, DirectoryHasRepository, + check_head_top_equal, run_commit_msg_hook, ) from stgit.config import config @@ -223,13 +224,7 @@ def make_temp_patch(stack, patch_name, tree): ) ) temp_name = stack.patches.make_name('refresh-temp') - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + trans = StackTransaction(stack) trans.patches[temp_name] = commit trans.applied.append(temp_name) return ( @@ -336,13 +331,8 @@ def absorb(stack, patch_name, temp_name, edit_fun, annotate=None): if annotate: log_msg += '\n\n' + annotate - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = StackTransaction(stack) iw = stack.repository.default_iw if patch_name in trans.applied: absorb_func = absorb_applied @@ -382,13 +372,8 @@ def __refresh_spill(annotate): if annotate: log_msg += '\n\n' + annotate - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=True, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = StackTransaction(stack, allow_conflicts=True) trans.patches[patchname] = stack.repository.commit(cd) try: # Either a complete success, or a conflict during push. But in @@ -450,6 +435,8 @@ def __refresh( 'To force a full refresh use --force.' ) + check_head_top_equal(stack) + # Update index and write tree tree = write_tree(stack, paths, use_temp_index=use_temp_index) diff --git a/stgit/commands/repair.py b/stgit/commands/repair.py index 01cd587..df0d53c 100644 --- a/stgit/commands/repair.py +++ b/stgit/commands/repair.py @@ -160,13 +160,7 @@ def func(parser, options, args): i = orig_order.get(p, len(orig_order)) return i, p - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=True, - check_clean_iw=None, - ) + trans = StackTransaction(stack) try: trans.applied = applied trans.unapplied = sorted(unapplied, key=patchname_key) diff --git a/stgit/commands/reset.py b/stgit/commands/reset.py index 2bad750..b574c45 100644 --- a/stgit/commands/reset.py +++ b/stgit/commands/reset.py @@ -57,13 +57,7 @@ def func(parser, options, args): else: raise CmdException('Wrong options or number of arguments') - trans = transaction.StackTransaction( - stack, - discard_changes=options.hard, - allow_conflicts=False, - allow_bad_head=True, - check_clean_iw=None, - ) + trans = transaction.StackTransaction(stack, discard_changes=options.hard) try: if patches: log.reset_stack_partially(trans, iw, state, patches) diff --git a/stgit/commands/sink.py b/stgit/commands/sink.py index e0cb941..c1773a9 100644 --- a/stgit/commands/sink.py +++ b/stgit/commands/sink.py @@ -1,5 +1,11 @@ from stgit.argparse import keep_option, opt, patch_range -from stgit.commands.common import CmdException, DirectoryHasRepository, parse_patches +from stgit.commands.common import ( + CmdException, + DirectoryHasRepository, + check_head_top_equal, + check_index_and_worktree_clean, + parse_patches, +) from stgit.lib import transaction __copyright__ = """ @@ -92,14 +98,12 @@ def func(parser, options, args): unapplied = [p for p in stack.patchorder.unapplied if p not in patches] iw = stack.repository.default_iw - clean_iw = (not options.keep and iw) or None - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=clean_iw, - ) + + check_head_top_equal(stack) + if not options.keep: + check_index_and_worktree_clean(stack) + + trans = transaction.StackTransaction(stack) try: trans.reorder_patches(applied, unapplied, iw=iw, allow_interactive=True) diff --git a/stgit/commands/squash.py b/stgit/commands/squash.py index 6e7f106..1ca57e8 100644 --- a/stgit/commands/squash.py +++ b/stgit/commands/squash.py @@ -3,6 +3,7 @@ from stgit.argparse import opt, patch_range from stgit.commands.common import ( CmdException, DirectoryHasRepository, + check_head_top_equal, parse_patches, run_commit_msg_hook, strip_comments, @@ -113,13 +114,9 @@ def squash(stack, patches, name=None, msg=None, no_verify=False): iw = stack.repository.default_iw - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=True, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + + trans = StackTransaction(stack, allow_conflicts=True) push_new_patch = bool(set(patches) & set(trans.applied)) new_patch_name = None try: diff --git a/stgit/commands/sync.py b/stgit/commands/sync.py index e1042eb..6c5ee05 100644 --- a/stgit/commands/sync.py +++ b/stgit/commands/sync.py @@ -3,7 +3,13 @@ import os import re from stgit.argparse import opt, patch_range -from stgit.commands.common import CmdException, DirectoryGotoTopLevel, parse_patches +from stgit.commands.common import ( + CmdException, + DirectoryGotoTopLevel, + check_head_top_equal, + check_index_and_worktree_clean, + parse_patches, +) from stgit.lib.git import CommitData from stgit.lib.transaction import StackTransaction, TransactionHalted from stgit.out import out @@ -156,19 +162,15 @@ def func(parser, options, args): raise CmdException('No common patches to be synchronised') iw = repository.default_iw + check_head_top_equal(stack) + check_index_and_worktree_clean(stack) # pop to the one before the first patch to be synchronised first_patch = sync_patches[0] if first_patch in applied: to_pop = applied[applied.index(first_patch) + 1 :] if to_pop: - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=iw, - ) + trans = StackTransaction(stack) popped_extra = trans.pop_patches(lambda pn: pn in to_pop) assert not popped_extra retval = trans.run('sync (pop)', iw) @@ -179,13 +181,7 @@ def func(parser, options, args): pushed = [] popped = to_pop + [p for p in patches if p in unapplied] - trans = StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=iw, - ) + trans = StackTransaction(stack) try: for p in pushed + popped: if p in popped: diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py index 2100a56..9e679d0 100644 --- a/stgit/commands/uncommit.py +++ b/stgit/commands/uncommit.py @@ -153,13 +153,7 @@ def func(parser, options, args): taken_names.add(pn) patchnames.reverse() - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=True, - allow_bad_head=True, - check_clean_iw=None, - ) + trans = transaction.StackTransaction(stack, allow_conflicts=True) for commit, pn in zip(commits, patchnames): trans.patches[pn] = commit trans.applied = list(reversed(patchnames)) + trans.applied diff --git a/stgit/commands/undo.py b/stgit/commands/undo.py index e11aa40..25aa6ff 100644 --- a/stgit/commands/undo.py +++ b/stgit/commands/undo.py @@ -50,13 +50,7 @@ def func(parser, options, args): if options.number < 1: raise CmdException('Bad number of commands to undo') state = log.undo_state(stack, options.number) - trans = transaction.StackTransaction( - stack, - discard_changes=options.hard, - allow_conflicts=False, - allow_bad_head=True, - check_clean_iw=None, - ) + trans = transaction.StackTransaction(stack, discard_changes=options.hard) try: log.reset_stack(trans, stack.repository.default_iw, state) except transaction.TransactionHalted: diff --git a/stgit/commands/unhide.py b/stgit/commands/unhide.py index 016e627..35d473f 100644 --- a/stgit/commands/unhide.py +++ b/stgit/commands/unhide.py @@ -1,5 +1,10 @@ from stgit.argparse import opt, patch_range -from stgit.commands.common import CmdException, DirectoryHasRepository, parse_patches +from stgit.commands.common import ( + CmdException, + DirectoryHasRepository, + check_head_top_equal, + parse_patches, +) from stgit.lib import transaction __copyright__ = """ @@ -41,13 +46,8 @@ directory = DirectoryHasRepository() def func(parser, options, args): """Unhide a range of patch in the series.""" stack = directory.repository.current_stack - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=False, - allow_bad_head=False, - check_clean_iw=None, - ) + check_head_top_equal(stack) + trans = transaction.StackTransaction(stack) if not args: parser.error('No patches specified') diff --git a/stgit/lib/edit.py b/stgit/lib/edit.py index 00710fb..87faf29 100644 --- a/stgit/lib/edit.py +++ b/stgit/lib/edit.py @@ -179,13 +179,8 @@ def perform_edit( # Rewrite the StGit patch with the given diff (and any patches on top of # it). iw = stack.repository.default_iw - trans = transaction.StackTransaction( - stack, - discard_changes=False, - allow_conflicts=True, - allow_bad_head=False, - check_clean_iw=None, - ) + common.check_head_top_equal(stack) + trans = transaction.StackTransaction(stack, allow_conflicts=True) if orig_patchname in trans.applied: popped = trans.applied[trans.applied.index(orig_patchname) + 1 :] popped_extra = trans.pop_patches(lambda pn: pn in popped) diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py index 0f31167..ae44548 100644 --- a/stgit/lib/transaction.py +++ b/stgit/lib/transaction.py @@ -92,14 +92,7 @@ class StackTransaction: """ - def __init__( - self, - stack, - discard_changes, - allow_conflicts, - allow_bad_head, - check_clean_iw, - ): + def __init__(self, stack, discard_changes=False, allow_conflicts=False): """Initialize a new :class:`StackTransaction`. :param discard_changes: Discard any changes in index+worktree @@ -129,11 +122,6 @@ class StackTransaction: else: self._allow_conflicts = allow_conflicts - if not allow_bad_head: - self._assert_head_top_equal() - if check_clean_iw: - self._assert_index_worktree_clean(check_clean_iw) - @property def applied(self): return self._applied @@ -208,12 +196,6 @@ class StackTransaction: ) raise TransactionAborted() - def _assert_index_worktree_clean(self, iw): - if not iw.worktree_clean(): - self._halt('Worktree not clean. Use "refresh" or "reset --hard"') - if not iw.index.is_clean(self.stack.head): - self._halt('Index not clean. Use "refresh" or "reset --hard"') - def _checkout(self, tree, iw, allow_bad_head): assert iw is not None if not allow_bad_head: -- 2.11.4.GIT