diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1538,9 +1538,12 @@ def identify(ui, repo, source=None,
     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 @@ def identify(ui, repo, source=None,
         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 @@ def identify(ui, repo, source=None,
         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)
diff --git a/tests/test-identify b/tests/test-identify
new file mode 100755
--- /dev/null
+++ b/tests/test-identify
@@ -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/
diff --git a/tests/test-identify.out b/tests/test-identify.out
new file mode 100644
--- /dev/null
+++ b/tests/test-identify.out
@@ -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