diff --git a/mercurial/statecheck.py b/mercurial/statecheck.py --- a/mercurial/statecheck.py +++ b/mercurial/statecheck.py @@ -69,3 +69,41 @@ def _mergepredicate(self, repo): """determines is a merge is in progress or not""" return len(repo[None].parents()) > 1 + + +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 repo.vfs.exists(state._fname): + raise error.Abort(state._statusmessage(), hint=state._hintmessage()) + + for s in unfinishedstates: + if not s._clearable or (commit and s._allowcommit): + continue + if repo.vfs.exists(s._fname): + raise error.Abort(s._statusmessage(), hint=s._hintmessage()) + +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 repo.vfs.exists(state._fname): + raise error.Abort(state._statusmessage(), hint=state._hintmessage()) + + for s in unfinishedstates: + if s._clearable and repo.vfs.exists(s._fname): + util.unlink(repo.vfs.join(s._fname))