Bug 6308 - contrib/bash_completion breaks if `alias hg='source /my/file'`
Summary: contrib/bash_completion breaks if `alias hg='source /my/file'`
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: stable branch
Hardware: PC Linux
: wish bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-27 02:41 UTC by Peter Arrenbrecht
Modified: 2020-05-20 00:01 UTC (History)
1 user (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Arrenbrecht 2020-04-27 02:41 UTC
The reason is that the scripts tries to use the alias again when invoking `hg` internally:
https://www.mercurial-scm.org/repo/hg/file/f365dfede78f/contrib/bash_completion#l159

I propose to add an env variable to disable this behaviour. For example:

  if [[ -z "$HGCOMPLETE_NOALIAS" ]]; then
    ...
  fi

Alternative: Also filter the `source` statement for internal invocations. But this seems a bit too specific to my case. Basically:

  aliashg=${aliashg#"alias $hg='"}  # existing
  aliashg=${aliashg#"source "}  # new

Would love to hear what the team prefers.
Comment 1 HG Bot 2020-05-12 16:10 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/f71c8eea7161
Peter Arrenbrecht <peter@arrenbrecht.ch>
bash_completion: do not use aliased hg if it sources a script (issue6308)

I have an alias that sources a script around hg. Mercurial's bash_completion
script tries to use this as its main hg binary. But sourcing a wrapper breaks
Bash's completion. So this patch disables using the alias as the hg binary if
it starts with "source ".

Alias resolution was introduced in rev 191ab08e7099 for users with
"alias hg='hg --some_opts'".

See https://www.mercurial-scm.org/repo/hg/rev/191ab08e7099

(please test the fix)
Comment 2 Bugzilla 2020-05-20 00:01 UTC
Bug was set to TESTING for 7 days, resolving