# HG changeset patch # User Alexis S. L. Carvalho # Date 2006-11-21 22:00:15 # Node ID 8d603f8567aeadd709fff63157ccc3295ceeae07 # Parent 6398ff7cb705421cb883607a66d9ce1744a27cf1 make hg commit work again diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -8,7 +8,7 @@ from demandload import demandload from node import * from i18n import gettext as _ -demandload(globals(), "os re sys signal imp urllib pdb shlex") +demandload(globals(), "bisect os re sys signal imp urllib pdb shlex stat") demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo") demandload(globals(), "difflib patch time") demandload(globals(), "traceback errno version atexit") @@ -423,12 +423,28 @@ def commit(ui, repo, *pats, **opts): status = repo.status(files=fns, match=match) modified, added, removed, deleted, unknown = status[:5] files = modified + added + removed + slist = None for f in fns: - if f not in modified + added + removed: + if f not in files: + rf = repo.wjoin(f) if f in unknown: - raise util.Abort(_("file %s not tracked!") % f) - else: - raise util.Abort(_("file %s not found!") % f) + raise util.Abort(_("file %s not tracked!") % rf) + try: + mode = os.lstat(rf)[stat.ST_MODE] + except OSError: + raise util.Abort(_("file %s not found!") % rf) + if stat.S_ISDIR(mode): + name = f + '/' + if slist is None: + slist = list(files) + slist.sort() + i = bisect.bisect(slist, name) + if i >= len(slist) or not slist[i].startswith(name): + raise util.Abort(_("no match under directory %s!") + % rf) + elif not stat.S_ISREG(mode): + raise util.Abort(_("can't commit %s: " + "unsupported file type!") % rf) else: files = [] try: diff --git a/tests/test-commit b/tests/test-commit --- a/tests/test-commit +++ b/tests/test-commit @@ -1,5 +1,10 @@ #!/bin/sh +cleanpath() +{ + sed -e "s:/.*\(/test/.*\):...\1:" +} + echo % commit date test hg init test cd test @@ -17,7 +22,35 @@ echo % partial commit test echo bar > bar hg add bar rm bar -hg commit -d "1000000 0" -m commit-8 2>&1 | sed -e "s:/.*\(/test/.*\):...\1:" +hg commit -d "1000000 0" -m commit-8 2>&1 | cleanpath + +hg -q revert -a --no-backup + +mkdir dir +echo boo > dir/file +hg add +hg -v commit -d '0 0' -m commit-9 dir + +echo > dir.file +hg add +hg commit -d '0 0' -m commit-10 dir dir.file 2>&1 | cleanpath + +echo >> dir/file +mkdir bleh +mkdir dir2 +cd bleh +hg commit -d '0 0' -m commit-11 . 2>&1 | cleanpath +hg commit -d '0 0' -m commit-12 ../dir ../dir2 2>&1 | cleanpath +hg -v commit -d '0 0' -m commit-13 ../dir +cd .. + +hg commit -d '0 0' -m commit-14 does-not-exist 2>&1 | cleanpath +ln -s foo baz +hg commit -d '0 0' -m commit-15 baz 2>&1 | cleanpath +touch quux +hg commit -d '0 0' -m commit-16 quux 2>&1 | cleanpath +echo >> dir/file +hg -v commit -d '0 0' -m commit-17 dir/file cd .. echo % partial subdir commit test diff --git a/tests/test-commit.out b/tests/test-commit.out --- a/tests/test-commit.out +++ b/tests/test-commit.out @@ -17,6 +17,19 @@ rollback completed % partial commit test trouble committing bar! abort: No such file or directory: .../test/bar +adding dir/file +dir/file +adding dir.file +abort: no match under directory .../test/dir! +abort: no match under directory .../test/bleh! +abort: no match under directory .../test/dir2! +dir/file +does-not-exist: No such file or directory +abort: file .../test/does-not-exist not found! +baz: unsupported file type (type is symbolic link) +abort: can't commit .../test/baz: unsupported file type! +abort: file .../test/quux not tracked! +dir/file % partial subdir commit test adding bar/bar adding foo/foo