diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt --- a/mercurial/help/config.txt +++ b/mercurial/help/config.txt @@ -56,6 +56,7 @@ ones. - ``/.hg/hgrc`` (per-repository) - ``$HOME/.hgrc`` (per-user) + - ``${XDG_CONFIG_HOME:-$HOME/.config}/hg/hgrc`` (per-user) - ``/etc/mercurial/hgrc`` (per-installation) - ``/etc/mercurial/hgrc.d/*.rc`` (per-installation) - ``/etc/mercurial/hgrc`` (per-system) diff --git a/mercurial/scmposix.py b/mercurial/scmposix.py --- a/mercurial/scmposix.py +++ b/mercurial/scmposix.py @@ -40,8 +40,15 @@ def systemrcpath(): def userrcpath(): if pycompat.sysplatform == 'plan9': return [encoding.environ['home'] + '/lib/hgrc'] + elif pycompat.sysplatform == 'darwin': + return [os.path.expanduser('~/.hgrc')] else: - return [os.path.expanduser('~/.hgrc')] + confighome = encoding.environ.get('XDG_CONFIG_HOME') + if confighome is None or not os.path.isabs(confighome): + confighome = os.path.expanduser('~/.config') + + return [os.path.expanduser('~/.hgrc'), + os.path.join(confighome, 'hg', 'hgrc')] def termsize(ui): try: diff --git a/tests/test-xdg.t b/tests/test-xdg.t new file mode 100644 --- /dev/null +++ b/tests/test-xdg.t @@ -0,0 +1,11 @@ +#if no-windows no-osx + + $ mkdir -p xdgconf/hg + $ echo '[ui]' > xdgconf/hg/hgrc + $ echo 'username = foobar' >> xdgconf/hg/hgrc + $ XDG_CONFIG_HOME="`pwd`/xdgconf" ; export XDG_CONFIG_HOME + $ unset HGRCPATH + $ hg config ui.username + foobar + +#endif