changeset 7757:af6a63438a8a

identify: have consistent output for local repositories Also, add some extensive testing for it (hardly any in the suite so far).
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 13 Feb 2009 11:32:33 +0100
parents db6a03225177
children e81e6c996e99
files mercurial/commands.py tests/test-identify tests/test-identify.out
diffstat 3 files changed, 73 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Feb 12 18:26:09 2009 +0100
+++ b/mercurial/commands.py	Fri Feb 13 11:32:33 2009 +0100
@@ -1538,9 +1538,12 @@
     default = not (num or id or branch or tags)
     output = []
 
+    revs = []
     if source:
         source, revs, checkout = hg.parseurl(ui.expandpath(source), [])
-        srepo = hg.repository(ui, source)
+        repo = hg.repository(ui, source)
+
+    if not repo.local():
         if not rev and revs:
             rev = revs[0]
         if not rev:
@@ -1548,7 +1551,7 @@
         if num or branch or tags:
             raise util.Abort(
                 "can't query remote revision number, branch, or tags")
-        output = [hexfunc(srepo.lookup(rev))]
+        output = [hexfunc(repo.lookup(rev))]
     elif not rev:
         ctx = repo[None]
         parents = ctx.parents()
@@ -1568,7 +1571,7 @@
         if num:
             output.append(str(ctx.rev()))
 
-    if not source and default and not ui.quiet:
+    if repo.local() and default and not ui.quiet:
         b = util.tolocal(ctx.branch())
         if b != 'default':
             output.append("(%s)" % b)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-identify	Fri Feb 13 11:32:33 2009 +0100
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+echo % no repo
+hg id
+
+echo % create repo
+hg init test
+cd test
+echo a > a
+hg ci -Ama
+
+echo % basic id usage
+hg id
+hg id --debug
+hg id -q
+hg id -v
+
+echo % with options
+hg id -r.
+hg id -n
+hg id -t
+hg id -b
+hg id -i
+hg id -n -t -b -i
+
+echo % with modifications
+echo b > a
+hg id -n -t -b -i
+
+echo % other local repo
+cd ..
+hg -R test id
+hg id test
+
+echo % with remote http repo
+cd test
+hg serve -p $HGPORT1 -d --pid-file=hg.pid
+cat hg.pid >> $DAEMON_PIDS
+hg id http://localhost:$HGPORT1/
+
+echo % remote with tags?
+hg id -t http://localhost:$HGPORT1/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-identify.out	Fri Feb 13 11:32:33 2009 +0100
@@ -0,0 +1,25 @@
+% no repo
+abort: There is no Mercurial repository here (.hg not found)
+% create repo
+adding a
+% basic id usage
+cb9a9f314b8b tip
+cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b tip
+cb9a9f314b8b
+cb9a9f314b8b tip
+% with options
+cb9a9f314b8b tip
+0
+tip
+default
+cb9a9f314b8b
+cb9a9f314b8b 0 default tip
+% with modifications
+cb9a9f314b8b+ 0+ default tip
+% other local repo
+cb9a9f314b8b+ tip
+cb9a9f314b8b+ tip
+% with remote http repo
+cb9a9f314b8b
+% remote with tags?
+abort: can't query remote revision number, branch, or tags