Patchwork D12579: chg: make `chg --cwd $anything -R $relativepath` behave better

login
register
mail settings
Submitter phabricator
Date April 20, 2022, 3:34 p.m.
Message ID <differential-rev-PHID-DREV-mw5qxpb735ho7ndpzxjb-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50927/
State New
Headers show

Comments

phabricator - April 20, 2022, 3:34 p.m.
valentin.gatienbaron created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We're seeing this kind of issue:
  
    $ (cd repo1; chg --cwd ../repo2 -R .)
  
  +  chg: abort: too many redirections.
  +  Please make sure $path/hg is not a wrapper which changes sensitive environment variables before executing hg. If you have to use a wrapper, wrap chg instead of hg.
  +  [255]
  
  chgserver is interpreting -R as relative to its cwd, instead of
  relative to --cwd like regular hg does, which I think causes an
  inconsistency leading to the above.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12579

AFFECTED FILES
  mercurial/dispatch.py
  tests/test-chg.t

CHANGE DETAILS




To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-chg.t b/tests/test-chg.t
--- a/tests/test-chg.t
+++ b/tests/test-chg.t
@@ -432,6 +432,15 @@ 
   YYYY/MM/DD HH:MM:SS (PID)> log -R cached
   YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in  ...s)
 
+-R is interpreted relative to --cwd
+
+  $ hg init repo1
+  $ hg init repo2
+  $ printf "[alias]\nx=y\n" >> repo1/.hg/hgrc
+  $ printf "[alias]\nx=z\n" >> repo2/.hg/hgrc
+  $ (cd repo1; chg --cwd ../repo2 -R . show alias.x)
+  z
+
 Test that chg works (sets to the user's actual LC_CTYPE) even when python
 "coerces" the locale (py3.7+)
 
@@ -536,3 +545,4 @@ 
   $ filteredchg log -r . --no-profile
   $ filteredchg log -r .
   Sample count: * (glob)
+  $ cd ../
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -973,6 +973,8 @@ 
             lui.readconfig(os.path.join(path, b".hg", b"hgrc-not-shared"), path)
 
     if rpath:
+        if wd is not None:
+            rpath = os.path.join(wd, rpath)
         path = urlutil.get_clone_path(lui, rpath)[0]
         lui = ui.copy()
         if rcutil.use_repo_hgrc():