Opened 12 years ago

Closed 11 years ago

Last modified 8 years ago

#37462 closed defect (fixed)

git-core: Actual bash_completion dir implies in bug on hub and git-flow bash completion

Reported by: robsonpeixoto@… Owned by: ci42
Priority: Normal Milestone:
Component: ports Version: 2.1.2
Keywords: haspatch Cc: raimue (Rainer Müller)
Port: git-core

Description

If change bash completion from ${destroot}${prefix}/share/bash-completion/completions to ${destroot}${prefix}/etc/bash_completion.d the git-flow completion and hub work very well.

Attachments (3)

completion.patch (800 bytes) - added by robsonpeixoto@… 12 years ago.
git-bash-completion.patch (190 bytes) - added by robsonpeixoto@… 11 years ago.
git-bash-completion.2.patch (190 bytes) - added by robsonpeixoto@… 11 years ago.

Download all attachments as: .zip

Change History (15)

Changed 12 years ago by robsonpeixoto@…

Attachment: completion.patch added

comment:1 Changed 12 years ago by ci42

Cc: ciserlohn@… removed
Keywords: bash_completion removed
Owner: changed from macports-tickets@… to ciserlohn@…
Priority: HighNormal
Summary: git: Actual bash_completion dir implies in bug on hub and git-flow bash completiongit-core: Actual bash_completion dir implies in bug on hub and git-flow bash completion

Please note that priority 'high' is reserved for MacPorts team members.

comment:2 Changed 12 years ago by robsonpeixoto@…

ping

comment:3 Changed 12 years ago by raimue (Rainer Müller)

Cc: raimue@… added

The bash completion works for me as is. Can you please be more specific what kind of problems you are seeing? The directory ${prefix}/etc/bash_completion.d/ is deprecated and only available for compatibility.

comment:4 Changed 12 years ago by robsonpeixoto@…

The bash-completion from git flow and hub git-prompt aren't working in ${prefix}/share/bash-completion/completions. The git-prompt aren't working on ${prefix}/share/bash-completion/completions, too.

But if I put all git related on ${prefix}/etc/bash_completion.d/, everything works.

On ${prefix}/share/bash-completion/completions only work the git-extras and git-core bash-completion

comment:5 Changed 12 years ago by raimue (Rainer Müller)

I cannot reproduce the issue. I have the files installed by the current ports. I can use git <Tab> in my bash to see the list of valid git commands. I don't know what "git flow" or "hub git-prompt" is, so please give me a way to reproduce the issue.

$ port -q installed active and \( 'git*' 'bash*' \)
  bash @4.2.42_0 (active)
  bash-completion @2.0_1 (active)
  git-core @1.8.1.1_0+bash_completion+credential_osxkeychain+doc+pcre+python27 (active)
  git-flow @0.4.1_0 (active)

comment:6 Changed 12 years ago by ci42

Resolution: worksforme
Status: newclosed

@robsonpeixoto:
Not sure what you mean, but both git-prompt.sh and git-flow completion work fine for me.

You find the git-prompt.sh here: ${prefix}/local/share/git-core/git-prompt.sh and not in ${prefix}/share/bash-completion/completions/

Make sure you have something like this in your .profile or .bashrc

if [ -f /opt/local/share/git-core/git-prompt.sh ]; then
      . /opt/local/share/git-core/git-prompt.sh
fi

Add something like this to your .profile or .bashrc

if [ -f ~/.git-flow-completion.bash ]; then
    . ~/.git-flow-completion.bash
fi

and you can use git flow <TAB> to see a list of valid git-flow commands.

comment:7 Changed 11 years ago by robsonpeixoto@…

Resolution: worksforme
Status: closedreopened

I had the hub installed and a created the alias git='hub' as the port suggest.

When I try to use the bash-completion of hub using the git command, all commands of hub aren't completed. Like it:

$ git f<tab>
fetch           filter-branch   format-patch    fsck

After move the bash-completion from /opt/local/share/bash-completion/completions to /opt/local/etc/bash_completion.d it's working very well. Now are showing the fork command.

$!sh
$ git f<tab>
fetch           filter-branch   fork            format-patch    fsck

I'm attaching the file git-bash-completion.patch moving the bash-completion to /opt/local/etc/bash_completion.d

Changed 11 years ago by robsonpeixoto@…

Attachment: git-bash-completion.patch added

Changed 11 years ago by robsonpeixoto@…

Attachment: git-bash-completion.2.patch added

comment:8 Changed 11 years ago by raimue (Rainer Müller)

Moving the git completion back to ${prefix}/etc/bash_completion.d should be avoided as it forces loading of the script each time a shell is started. This is the main advantage of bash-completion >= 2.0, as scripts are only loaded when actually required. The hub completion is just not compatible with bash-completion >= 2.0. Anyway, bash-completion does not work with other aliases either, so I don't think moving the git completion around just for the sake of hub's incompatible completion is the best solution.

comment:9 Changed 11 years ago by robsonpeixoto@…

But it will help a lot with hub, git-flow and maybe with other tools.

comment:10 Changed 11 years ago by raimue (Rainer Müller)

Resolution: fixed
Status: reopenedclosed

Completion for git-flow works, only hub causes issues. The problem is that you want the completion for hub to be loaded although you are typing the command git. This is unsupported by bash-completion and the existing <2.0 implementation is a hack. At the moment, the completion file for hub expects the completion file for git to be loaded beforehand as it merely modifies the existing completion. The load order is not guaranteed even if they are both in the old ${prefix}/etc/bash_completion.d directory.

I updated the hub completion to work properly with bash-completion >= 2.0 in r112130 and r112131. This does not solve the problem of the alias. However, this is the case for all bash-completion script and thus, out of scope of this request and would need to be addressed upstream.

As a workaround, if you really want this to work now, add it now in the following way to your ~/.bashrc:

alias git='hub'
source /opt/local/share/bash-completion/completions/hub

comment:11 Changed 11 years ago by robsonpeixoto@…

Thanks! =D

I need to reinstall hub:

sudo port uninstall hub
sudo port -s install hub

And add on ~/.bashrc below because of that bug -bash: __git_complete: command not found

alias git='hub'
source /opt/local/share/bash-completion/completions/git
source /opt/local/share/bash-completion/completions/hub
Last edited 11 years ago by robsonpeixoto@… (previous) (diff)

comment:12 Changed 8 years ago by bernicecarisa@…

Installation for Bash

To achieve git-flow completion nirvana:

  1. Install git-completion.
  1. Install git-flow-completion.bash. Either:

(i). Place it in your bash_completion.d folder, usually something like /etc/bash_completion.d, /usr/local/etc/bash_completion.d or ~/bash_completion.d. (ii). copy it somewhere (e.g. ~/git-flow-completion.bash) and put the following line in the .profile or .bashrc file in your home directory:

source ~/git-flow-completion.bash
  1. If you are using Git < 1.7.1, you will need to edit git completion (usually /etc/bash_completion.d/git or git-completion.sh) and add the following line to the $command case in _git:
git ()
{
        [...]
        case "$command" in
           [...]
           flow)        _git_flow ;;        
           *)           COMPREPLY=() ;;
        esac
}

Installation for Zsh

  1. Update your zsh's git-completion module to the newest version.
  1. Install git-flow-completion.zsh. Either:
  1. Place it in your .zshrc.
  1. Or, copy it somewhere (e.g. ~/.git-flow-completion.zsh) and put the following line in your .zshrc:
    source ~/.git-flow-completion.zsh

  1. Turn the plugin on by updating your zsh configuration file, ~/.zshrc

a.{{{

open ~/.zshrc

}}}

  1. Find the plugins section. It'll look like this:
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
 # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
 # Example format: plugins=(rails git textmate ruby lighthouse)
 plugins=(<some-plugin> <another-plugin> <third-plugin>)

C- Add git-flow-completion to the list of plugins within the parentheses. D- Save

Installation for fish -

To achieve git-flow completion nirvana:

 1- Install git.fish in your ~/.config/fish/completions folder.
Note: See TracTickets for help on using tickets.