diff --git a/mercurial/state.py b/mercurial/state.py --- a/mercurial/state.py +++ b/mercurial/state.py @@ -139,7 +139,7 @@ else: return _('%s in progress') % (self.cmdname) - def inunfinished(self, repo, mergecheck=False): + def isunfinished(self, repo, mergecheck=False): """determines whether a multi-step operation is in progress or not mergecheck flag helps in determining state specifically for merge @@ -149,4 +149,39 @@ else: return repo.vfs.exists(self.fname) +unfinishedstates=[] +unfinishedstates.append(statecheck('graft','graftstate', clearable=True, + allowcommit=False, stopflag=True)) +unfinishedstates.append(statecheck('update', 'updatestate', clearable=True, + allowcommit=False, stopflag=False)) +def checkunfinished(repo, commit=False): + '''Look for an unfinished multistep operation, like graft, and abort + if found. It's probably good to check this right before + bailifchanged(). + ''' + # Check for non-clearable states first, so things like rebase will take + # precedence over update. + for state in unfinishedstates: + if state.clearable or (commit and state.allowcommit): + continue + if state.isunfinished(repo): + raise error.Abort(state.msg(), hint=state.hint()) + + for s in unfinishedstates: + if not s.clearable or (commit and s.allowcommit): + continue + if s.isunfinished(repo): + raise error.Abort(s.msg(), hint=s.hint()) + +def clearunfinished(repo): + '''Check for unfinished operations (as above), and clear the ones + that are clearable. + ''' + for state in unfinishedstates: + if not state.clearable and state.isunfinished(repo): + raise error.Abort(state.msg(), hint=state.msg()) + + for s in unfinishedstates: + if s.clearable and s.isunfinished(repo): + util.unlink(repo.vfs.join(s.fname))