Patchwork [stable] bash_completion: do not use aliased hg if the alias sources a script

login
register
mail settings
Submitter Peter Arrenbrecht
Date May 11, 2020, 6:37 a.m.
Message ID <250aa808db30315f0c2c.1589179072@thebuntu>
Download mbox | patch
Permalink /patch/46296/
State Accepted
Headers show

Comments

Peter Arrenbrecht - May 11, 2020, 6:37 a.m.
# HG changeset patch
# User Peter Arrenbrecht <peter@arrenbrecht.ch>
# Date 1589177620 -7200
#      Mon May 11 08:13:40 2020 +0200
# Branch stable
# Node ID 250aa808db30315f0c2cd97602dcd86f1854b1a5
# Parent  a467416c493c3ab32f214b69b5d5831da24e5732
bash_completion: do not use aliased hg if the alias sources a script

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

Resolves (issue6308).
Yuya Nishihara - May 12, 2020, 12:58 p.m.
On Mon, 11 May 2020 08:37:52 +0200, Peter Arrenbrecht wrote:
> # HG changeset patch
> # User Peter Arrenbrecht <peter@arrenbrecht.ch>
> # Date 1589177620 -7200
> #      Mon May 11 08:13:40 2020 +0200
> # Branch stable
> # Node ID 250aa808db30315f0c2cd97602dcd86f1854b1a5
> # Parent  a467416c493c3ab32f214b69b5d5831da24e5732
> bash_completion: do not use aliased hg if the alias sources a script
> 
> 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
> 
> Resolves (issue6308).
> 
> diff --git a/contrib/bash_completion b/contrib/bash_completion
> --- a/contrib/bash_completion
> +++ b/contrib/bash_completion
> @@ -160,7 +160,10 @@
>      if [[ -n "$aliashg" ]]; then
>        aliashg=${aliashg#"alias $hg='"}
>        aliashg=${aliashg%"'"}
> -      hg=$aliashg
> +      # `source`d aliases break completion, so ignore them
> +      if [[ "${aliashg:0:7}" != "source " ]]; then
> +        hg=$aliashg

Seems fine. Queued for stable, thanks.

Patch

diff --git a/contrib/bash_completion b/contrib/bash_completion
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -160,7 +160,10 @@ 
     if [[ -n "$aliashg" ]]; then
       aliashg=${aliashg#"alias $hg='"}
       aliashg=${aliashg%"'"}
-      hg=$aliashg
+      # `source`d aliases break completion, so ignore them
+      if [[ "${aliashg:0:7}" != "source " ]]; then
+        hg=$aliashg
+      fi
     fi
 
     COMPREPLY=()