diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
index a051f8a6a7ccd93bce8aa856f8e48b7a1ca01f46_bWVyY3VyaWFsL2xvY2FscmVwby5weQ==..a21ccf4412d58bdcf2451186f418594900ff15c6_bWVyY3VyaWFsL2xvY2FscmVwby5weQ== 100644
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -79,7 +79,7 @@
 
         self.sharedpath = self.path
         try:
-            s = os.path.realpath(self.opener.read("sharedpath"))
+            s = os.path.realpath(self.opener.read("sharedpath").rstrip('\n'))
             if not os.path.exists(s):
                 raise error.RepoError(
                     _('.hg/sharedpath points to nonexistent directory %s') % s)
diff --git a/tests/test-share.t b/tests/test-share.t
index a051f8a6a7ccd93bce8aa856f8e48b7a1ca01f46_dGVzdHMvdGVzdC1zaGFyZS50..a21ccf4412d58bdcf2451186f418594900ff15c6_dGVzdHMvdGVzdC1zaGFyZS50 100644
--- a/tests/test-share.t
+++ b/tests/test-share.t
@@ -28,6 +28,15 @@
   $ cat .hg/sharedpath; echo
   $TESTTMP/repo1/.hg
 
+trailing newline on .hg/sharedpath is ok
+  $ hg tip -q
+  0:d3873e73d99e
+  $ echo '' >> .hg/sharedpath
+  $ cat .hg/sharedpath
+  $TESTTMP/repo1/.hg
+  $ hg tip -q
+  0:d3873e73d99e
+
 commit in shared clone
 
   $ echo a >> a