lfutil: provide a hint if the largefiles/lfs cache path cannot be determined
authorMatt Harbison <matt_harbison@yahoo.com>
Mon, 24 Feb 2020 14:52:46 -0500
changeset 44410 ca82929e433d
parent 44409 56f089e40c5a
child 44411 dda2341d6664
lfutil: provide a hint if the largefiles/lfs cache path cannot be determined A coworker hit this error using an LFS repo in a stripped down environment, and didn't know how to resolve it. The final conditional is a bit fast and loose, but there is currently no 'posix' test in hghave, and it doesn't seem like it's worth adding for this since I think Windows is the only non-POSIX platform we run tests on. Differential Revision: https://phab.mercurial-scm.org/D8145
hgext/largefiles/lfutil.py
tests/test-lfs-bundle.t
--- a/hgext/largefiles/lfutil.py	Mon Feb 24 17:43:34 2020 -0500
+++ b/hgext/largefiles/lfutil.py	Mon Feb 24 14:52:46 2020 -0500
@@ -92,16 +92,30 @@
     path = ui.configpath(name, b'usercache')
     if path:
         return path
+
+    hint = None
+
     if pycompat.iswindows:
         appdata = encoding.environ.get(
             b'LOCALAPPDATA', encoding.environ.get(b'APPDATA')
         )
         if appdata:
             return os.path.join(appdata, name)
+
+        hint = _(b"define %s or %s in the environment, or set %s.usercache") % (
+            b"LOCALAPPDATA",
+            b"APPDATA",
+            name,
+        )
     elif pycompat.isdarwin:
         home = encoding.environ.get(b'HOME')
         if home:
             return os.path.join(home, b'Library', b'Caches', name)
+
+        hint = _(b"define %s in the environment, or set %s.usercache") % (
+            b"HOME",
+            name,
+        )
     elif pycompat.isposix:
         path = encoding.environ.get(b'XDG_CACHE_HOME')
         if path:
@@ -109,11 +123,18 @@
         home = encoding.environ.get(b'HOME')
         if home:
             return os.path.join(home, b'.cache', name)
+
+        hint = _(b"define %s or %s in the environment, or set %s.usercache") % (
+            b"XDG_CACHE_HOME",
+            b"HOME",
+            name,
+        )
     else:
         raise error.Abort(
             _(b'unknown operating system: %s\n') % pycompat.osname
         )
-    raise error.Abort(_(b'unknown %s usercache location') % name)
+
+    raise error.Abort(_(b'unknown %s usercache location') % name, hint=hint)
 
 
 def inusercache(ui, hash):
--- a/tests/test-lfs-bundle.t	Mon Feb 24 17:43:34 2020 -0500
+++ b/tests/test-lfs-bundle.t	Mon Feb 24 14:52:46 2020 -0500
@@ -95,3 +95,32 @@
   OK
   ---- Applying src-lfs.bundle to dst-lfs ----
   OK
+
+Hint if the cache location cannot be inferred from the environment
+
+#if windows
+  $ unset LOCALAPPDATA
+  $ unset APPDATA
+  $ HGRCPATH= hg config lfs --debug
+  abort: unknown lfs usercache location
+  (define LOCALAPPDATA or APPDATA in the environment, or set lfs.usercache)
+  [255]
+#endif
+
+#if osx
+  $ unset HOME
+  $ HGRCPATH= hg config lfs --debug
+  abort: unknown lfs usercache location
+  (define HOME in the environment, or set lfs.usercache)
+  [255]
+#endif
+
+#if no-windows no-osx
+  $ unset XDG_CACHE_HOME
+  $ unset HOME
+  $ HGRCPATH= hg config lfs --debug
+  abort: unknown lfs usercache location
+  (define XDG_CACHE_HOME or HOME in the environment, or set lfs.usercache)
+  [255]
+#endif
+