movefixup.py
author Benjamin Smedberg <benjamin@smedbergs.us>
Tue, 26 Jan 2010 15:22:37 -0500
changeset 1 10d07451d4b3
parent 0 eaf0deff1a86
permissions -rw-r--r--
`hg setparents` command
import os
from mercurial import util

def dofixup(ui, repo, source, dest):
    cwd = repo.getcwd()
    abssource = util.canonpath(repo.root, cwd, source)
    absdest = util.canonpath(repo.root, cwd, dest)
    origsrc = repo.dirstate.copied(abssource) or abssource
    if repo.dirstate[origsrc] != 'r':
        raise util.Abort('source file is not removed')
    if repo.dirstate[absdest] != 'a':
        raise util.Abort('destination file is not added')

    repo.copy(abssource, absdest)
    return 0

def movefixup(ui, repo, *args):
    source, dest = args

    wlock = repo.wlock(False)
    try:
        return dofixup(ui, repo, source, dest)
    finally:
        del wlock

cmdtable = {
    'movefixup': (movefixup, [], "hg movefixup oldname newname")
}