diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -19,34 +19,45 @@ def _local(path): return (os.path.isfile(path) and bundlerepo or localrepo) def addbranchrevs(lrepo, repo, branches, revs): - if not branches: + hashbranch, branches = branches + if not hashbranch and not branches: return revs or None, revs and revs[0] or None revs = revs and list(revs) or [] if not repo.capable('branchmap'): - revs.extend(branches) + if branches: + raise util.Abort(_("remote branch lookup not supported")) + revs.append(hashbranch) return revs, revs[0] branchmap = repo.branchmap() - for branch in branches: - if branch == '.': + + def primary(butf8): + if butf8 == '.': if not lrepo or not lrepo.local(): raise util.Abort(_("dirstate branch not accessible")) butf8 = lrepo.dirstate.branch() - branch = encoding.tolocal(butf8) - else: - butf8 = encoding.fromlocal(branch) if butf8 in branchmap: revs.extend(node.hex(r) for r in reversed(branchmap[butf8])) + return True else: - revs.append(branch) + return False + + for branch in branches: + butf8 = encoding.fromlocal(branch) + if not primary(butf8): + raise error.RepoLookupError(_("unknown branch '%s'") % branch) + if hashbranch: + butf8 = encoding.fromlocal(hashbranch) + if not primary(butf8): + revs.append(hashbranch) return revs, revs[0] def parseurl(url, branches=None): - '''parse url#branch, returning url, branches+[branch]''' + '''parse url#branch, returning (url, (branch, branches))''' if '#' not in url: - return url, branches or [] + return url, (None, branches or []) url, branch = url.split('#', 1) - return url, (branches or []) + [branch] + return url, (branch, branches or []) schemes = { 'bundle': bundlerepo, diff --git a/tests/test-branch-option b/tests/test-branch-option --- a/tests/test-branch-option +++ b/tests/test-branch-option @@ -12,6 +12,7 @@ hg up 0 hg branch c echo c > foo hg ci -d '0 0' -mc +hg tag -l z cd .. hg clone -r 0 branch branch2 cd branch2 @@ -32,6 +33,10 @@ hg branch -f b echo b2 > foo hg ci -d '0 0' -mb2 +echo unknown branch and fallback +hg in -qbz +hg in -q ../branch#z +hg out -qbz echo in rev c branch a hg in -qr c ../branch#a hg in -qr c -b a diff --git a/tests/test-branch-option.out b/tests/test-branch-option.out --- a/tests/test-branch-option.out +++ b/tests/test-branch-option.out @@ -15,9 +15,14 @@ 1 files updated, 0 files merged, 0 files marked working directory as branch æ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved marked working directory as branch æ +created new head 1 files updated, 0 files merged, 0 files removed, 0 files unresolved marked working directory as branch b created new head +unknown branch and fallback +abort: unknown branch 'z'! +2:f25d57ab0566 +abort: unknown branch 'z'! in rev c branch a 1:dd6e60a716c6 2:f25d57ab0566 diff --git a/tests/test-hg-parseurl.py.out b/tests/test-hg-parseurl.py.out --- a/tests/test-hg-parseurl.py.out +++ b/tests/test-hg-parseurl.py.out @@ -1,5 +1,5 @@ -http://example.com/no/anchor, branches: [] -http://example.com/an/anchor, branches: ['foo'] -http://example.com/no/anchor/branches, branches: ['foo'] -http://example.com/an/anchor/branches, branches: ['foo', 'bar'] -http://example.com/an/anchor/branches-None, branches: ['foo'] +http://example.com/no/anchor, branches: (None, []) +http://example.com/an/anchor, branches: ('foo', []) +http://example.com/no/anchor/branches, branches: (None, ['foo']) +http://example.com/an/anchor/branches, branches: ('bar', ['foo']) +http://example.com/an/anchor/branches-None, branches: ('foo', [])